fix: resolve TypeScript errors in nostrUriResolver.tsx

- Add explicit type annotations for decoded variable and npub parameter
- Use switch statement for better type narrowing when checking npub type
This commit is contained in:
Gigi
2025-11-02 23:13:37 +01:00
parent ea3c130cc3
commit 8cb77864bc

View File

@@ -378,32 +378,36 @@ export function addLoadingClassToProfileLinks(
} }
// Find all <a> tags with href starting with /p/ (profile links) // Find all <a> tags with href starting with /p/ (profile links)
const result = html.replace(/<a\s+[^>]*?href="\/p\/([^"]+)"[^>]*?>/g, (match, npub) => { const result = html.replace(/<a\s+[^>]*?href="\/p\/([^"]+)"[^>]*?>/g, (match, npub: string) => {
try { try {
// Decode npub to get pubkey // Decode npub to get pubkey
const decoded = decode(npub) const decoded: ReturnType<typeof decode> = decode(npub)
if (decoded.type !== 'npub') { switch (decoded.type) {
return match case 'npub': {
} const pubkey = decoded.data
const pubkey = decoded.data // Check if this profile is loading
const isLoading = profileLoading.get(pubkey)
// Check if this profile is loading
const isLoading = profileLoading.get(pubkey) if (isLoading === true) {
// Add profile-loading class if not already present
if (isLoading === true) { if (!match.includes('profile-loading')) {
// Add profile-loading class if not already present // Insert class before the closing >
if (!match.includes('profile-loading')) { const classMatch = /class="([^"]*)"/.exec(match)
// Insert class before the closing > if (classMatch) {
const classMatch = /class="([^"]*)"/.exec(match) const updated = match.replace(/class="([^"]*)"/, `class="$1 profile-loading"`)
if (classMatch) { return updated
const updated = match.replace(/class="([^"]*)"/, `class="$1 profile-loading"`) } else {
return updated const updated = match.replace(/(<a\s+[^>]*?)>/, '$1 class="profile-loading">')
} else { return updated
const updated = match.replace(/(<a\s+[^>]*?)>/, '$1 class="profile-loading">') }
return updated }
} }
break
} }
default:
// Not an npub, ignore
break
} }
} catch (error) { } catch (error) {
// Ignore processing errors // Ignore processing errors