From 0e720f70e833f80de3c86f0549c7dde9ee9304a1 Mon Sep 17 00:00:00 2001 From: silberengel Date: Thu, 14 Aug 2025 08:08:24 +0200 Subject: [PATCH] corrected my-notes going blank on refresh and showing when no one is logged-in --- src/lib/components/Navigation.svelte | 4 ++- src/lib/ndk.ts | 31 ++++++++++++----------- src/routes/my-notes/+page.svelte | 37 ++++++++++++++++++---------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/lib/components/Navigation.svelte b/src/lib/components/Navigation.svelte index e155c03..186a93f 100644 --- a/src/lib/components/Navigation.svelte +++ b/src/lib/components/Navigation.svelte @@ -31,7 +31,9 @@ Visualize Getting Started Events - My Notes + {#if userState.signedIn} + My Notes + {/if} About Contact diff --git a/src/lib/ndk.ts b/src/lib/ndk.ts index 45e9097..92d2430 100644 --- a/src/lib/ndk.ts +++ b/src/lib/ndk.ts @@ -91,20 +91,8 @@ function clearPersistentRelaySet(): void { } } -// Subscribe to userStore changes and update ndkSignedIn accordingly -userStore.subscribe(async (userState) => { - ndkSignedIn.set(userState.signedIn); - - // Refresh relay stores when user state changes - const ndk = get(ndkInstance); - if (ndk) { - try { - await refreshRelayStores(ndk); - } catch (error) { - console.warn('[NDK.ts] Failed to refresh relay stores on user state change:', error); - } - } -}); +// AI-NOTE: userStore subscription moved to initNdk function to prevent initialization errors +// The subscription will be set up after userStore is properly initialized /** * Custom authentication policy that handles NIP-42 authentication manually @@ -655,6 +643,21 @@ export function initNdk(): NDK { attemptConnection(); + // AI-NOTE: Set up userStore subscription after NDK initialization to prevent initialization errors + userStore.subscribe(async (userState) => { + ndkSignedIn.set(userState.signedIn); + + // Refresh relay stores when user state changes + const ndk = get(ndkInstance); + if (ndk) { + try { + await refreshRelayStores(ndk); + } catch (error) { + console.warn('[NDK.ts] Failed to refresh relay stores on user state change:', error); + } + } + }); + return ndk; } diff --git a/src/routes/my-notes/+page.svelte b/src/routes/my-notes/+page.svelte index 4841b4c..852d31e 100644 --- a/src/routes/my-notes/+page.svelte +++ b/src/routes/my-notes/+page.svelte @@ -1,5 +1,6 @@