From e9cbe56bc032b7f2a71f107d36707a6bf66a0e6c Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 5 Oct 2025 03:48:32 +0100 Subject: [PATCH] refactor: consolidate settings initialization on login - Merge settings load and subscription setup into single useEffect - Ensure settings are loaded immediately upon successful login - Set up watchSettings subscription at the same time as initial load - Add eventStore as dependency to ensure proper initialization - Improves timing and prevents race conditions --- src/components/Bookmarks.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/Bookmarks.tsx b/src/components/Bookmarks.tsx index 66a852ed..a209266d 100644 --- a/src/components/Bookmarks.tsx +++ b/src/components/Bookmarks.tsx @@ -45,17 +45,16 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { const accountManager = Hooks.useAccountManager() const eventStore = useEventStore() + // Load initial data and set up settings subscription on login useEffect(() => { - if (relayPool && activeAccount) { - handleFetchBookmarks() - handleFetchHighlights() - handleLoadSettings() - } - }, [relayPool, activeAccount?.pubkey]) + if (!relayPool || !activeAccount || !eventStore) return - // Watch for settings changes from Nostr - useEffect(() => { - if (!activeAccount || !eventStore) return + // Fetch bookmarks and highlights + handleFetchBookmarks() + handleFetchHighlights() + + // Load settings from Nostr and set up live subscription + handleLoadSettings() const subscription = watchSettings(eventStore, activeAccount.pubkey, (loadedSettings) => { if (loadedSettings) { @@ -66,7 +65,7 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { return () => { subscription.unsubscribe() } - }, [activeAccount?.pubkey, eventStore]) + }, [relayPool, activeAccount?.pubkey, eventStore]) useEffect(() => { const root = document.documentElement.style