fix: resolve loading state stuck issue

- Remove loading check from early return condition
- Add timeout to ensure loading state gets reset
- Clear timeout when function completes
- This should allow fetchBookmarks to run properly
This commit is contained in:
Gigi
2025-10-02 09:15:04 +02:00
parent 774ce0f1bf
commit 934043f858

View File

@@ -75,8 +75,8 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
const fetchBookmarks = async () => { const fetchBookmarks = async () => {
console.log('🔍 fetchBookmarks called, loading:', loading) console.log('🔍 fetchBookmarks called, loading:', loading)
if (!relayPool || !activeAccount || loading) { if (!relayPool || !activeAccount) {
console.log('🔍 fetchBookmarks early return - relayPool:', !!relayPool, 'activeAccount:', !!activeAccount, 'loading:', loading) console.log('🔍 fetchBookmarks early return - relayPool:', !!relayPool, 'activeAccount:', !!activeAccount)
return return
} }
@@ -84,6 +84,12 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
setLoading(true) setLoading(true)
console.log('🚀 NEW VERSION: Fetching bookmark list for pubkey:', activeAccount.pubkey) console.log('🚀 NEW VERSION: Fetching bookmark list for pubkey:', activeAccount.pubkey)
// Set a timeout to ensure loading state gets reset
const timeoutId = setTimeout(() => {
console.log('⏰ Timeout reached, resetting loading state')
setLoading(false)
}, 15000) // 15 second timeout
// Get relay URLs from the pool // Get relay URLs from the pool
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url) const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
@@ -184,10 +190,12 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
} }
setBookmarks([bookmark]) setBookmarks([bookmark])
clearTimeout(timeoutId)
setLoading(false) setLoading(false)
} catch (error) { } catch (error) {
console.error('Failed to fetch bookmarks:', error) console.error('Failed to fetch bookmarks:', error)
clearTimeout(timeoutId)
setLoading(false) setLoading(false)
} }
} }