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
This commit is contained in:
Gigi
2025-10-05 03:48:32 +01:00
parent 09bbe10aa6
commit e9cbe56bc0

View File

@@ -45,17 +45,16 @@ const Bookmarks: React.FC<BookmarksProps> = ({ 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<BookmarksProps> = ({ relayPool, onLogout }) => {
return () => {
subscription.unsubscribe()
}
}, [activeAccount?.pubkey, eventStore])
}, [relayPool, activeAccount?.pubkey, eventStore])
useEffect(() => {
const root = document.documentElement.style