diff --git a/src/lib/components/cards/BlogHeader.svelte b/src/lib/components/cards/BlogHeader.svelte index 0696d89..0c3a2bc 100644 --- a/src/lib/components/cards/BlogHeader.svelte +++ b/src/lib/components/cards/BlogHeader.svelte @@ -1,12 +1,14 @@ + +
+ +
+
+ + + { + setTimeout(() => { + imageLoaded = true; + }, 100); + }} + onerror={() => { + imageError = true; + }} + /> + + + {#if imageError} +
+
+ Failed to load +
+
+ {/if} +
\ No newline at end of file diff --git a/src/lib/consts.ts b/src/lib/consts.ts index 4241d1d..b6df380 100644 --- a/src/lib/consts.ts +++ b/src/lib/consts.ts @@ -36,9 +36,9 @@ export const lowbandwidthRelays = [ "wss://aggr.nostr.land" ]; -export const localRelays = [ - "wss://localhost:8080", - "wss://localhost:4869" +export const localRelays: string[] = [ + // "wss://localhost:8080", + // "wss://localhost:4869" ]; export enum FeedType { diff --git a/src/lib/stores/userStore.ts b/src/lib/stores/userStore.ts index 3275e23..6e8ef07 100644 --- a/src/lib/stores/userStore.ts +++ b/src/lib/stores/userStore.ts @@ -162,7 +162,20 @@ export async function loginWithExtension() { const signer = new NDKNip07Signer(); const user = await signer.user(); const npub = user.npub; - const profile = await getUserMetadata(npub); + + // Try to fetch user metadata, but don't fail if it times out + let profile: NostrProfile | null = null; + try { + profile = await getUserMetadata(npub); + } catch (error) { + console.warn("Failed to fetch user metadata during login:", error); + // Continue with login even if metadata fetch fails + profile = { + name: npub.slice(0, 8) + "..." + npub.slice(-4), + displayName: npub.slice(0, 8) + "..." + npub.slice(-4), + }; + } + // Fetch user's preferred relays const [persistedInboxes, persistedOutboxes] = getPersistedRelays(user); for (const relay of persistedInboxes) { diff --git a/src/lib/utils/image_utils.ts b/src/lib/utils/image_utils.ts new file mode 100644 index 0000000..4922995 --- /dev/null +++ b/src/lib/utils/image_utils.ts @@ -0,0 +1,31 @@ +/** + * Generate a dark-pastel color based on a string (like an event ID) + * @param seed - The string to generate a color from + * @returns A dark-pastel hex color + */ +export function generateDarkPastelColor(seed: string): string { + // Create a simple hash from the seed string + let hash = 0; + for (let i = 0; i < seed.length; i++) { + const char = seed.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; // Convert to 32-bit integer + } + + // Use the hash to generate lighter pastel colors + // Keep values in the 120-200 range for better pastel effect + const r = Math.abs(hash) % 80 + 120; // 120-200 range + const g = Math.abs(hash >> 8) % 80 + 120; // 120-200 range + const b = Math.abs(hash >> 16) % 80 + 120; // 120-200 range + + return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`; +} + +/** + * Test function to verify color generation + * @param eventId - The event ID to test + * @returns The generated color + */ +export function testColorGeneration(eventId: string): string { + return generateDarkPastelColor(eventId); +} \ No newline at end of file diff --git a/src/lib/utils/nostrUtils.ts b/src/lib/utils/nostrUtils.ts index a7aef5e..85e9e8d 100644 --- a/src/lib/utils/nostrUtils.ts +++ b/src/lib/utils/nostrUtils.ts @@ -426,12 +426,18 @@ export async function fetchEventWithFallback( // Use the active inbox relays from the relay management system const inboxRelays = get(activeInboxRelays); + // Check if we have any relays available + if (inboxRelays.length === 0) { + console.warn("No inbox relays available for event fetch"); + return null; + } + // Create relay set from active inbox relays const relaySet = NDKRelaySetFromNDK.fromRelayUrls(inboxRelays, ndk); try { if (relaySet.relays.size === 0) { - console.warn("No inbox relays available for event fetch"); + console.warn("No relays in relay set for event fetch"); return null; } @@ -467,7 +473,15 @@ export async function fetchEventWithFallback( // Always wrap as NDKEvent return found instanceof NDKEvent ? found : new NDKEvent(ndk, found); } catch (err) { - console.error("Error in fetchEventWithFallback:", err); + if (err instanceof Error && err.message === 'Timeout') { + const timeoutSeconds = timeoutMs / 1000; + const relayUrls = Array.from(relaySet.relays).map((r: any) => r.url).join(", "); + console.warn( + `Event fetch timed out after ${timeoutSeconds}s. Tried inbox relays: ${relayUrls}. Some relays may be offline or slow.`, + ); + } else { + console.error("Error in fetchEventWithFallback:", err); + } return null; } } diff --git a/src/lib/utils/relay_management.ts b/src/lib/utils/relay_management.ts index dbaa08a..e02c7f8 100644 --- a/src/lib/utils/relay_management.ts +++ b/src/lib/utils/relay_management.ts @@ -147,19 +147,30 @@ function ensureSecureWebSocket(url: string): string { async function testLocalRelays(localRelayUrls: string[], ndk: NDK): Promise { const workingRelays: string[] = []; + if (localRelayUrls.length === 0) { + return workingRelays; + } + + console.debug(`[relay_management.ts] Testing ${localRelayUrls.length} local relays...`); + await Promise.all( localRelayUrls.map(async (url) => { try { const result = await testRelayConnection(url, ndk); if (result.connected) { workingRelays.push(url); + console.debug(`[relay_management.ts] Local relay connected: ${url}`); + } else { + console.debug(`[relay_management.ts] Local relay failed: ${url} - ${result.error}`); } } catch (error) { - // Silently ignore local relay failures + // Silently ignore local relay failures - they're optional + console.debug(`[relay_management.ts] Local relay error (ignored): ${url}`); } }) ); + console.debug(`[relay_management.ts] Found ${workingRelays.length} working local relays`); return workingRelays; } @@ -170,6 +181,12 @@ async function testLocalRelays(localRelayUrls: string[], ndk: NDK): Promise { try { + // If no local relays are configured, return empty array + if (localRelays.length === 0) { + console.debug('[relay_management.ts] No local relays configured'); + return []; + } + // Convert wss:// URLs from consts to ws:// for local testing const localRelayUrls = localRelays.map(url => url.replace(/^wss:\/\//, 'ws://')