import React, { useState, useEffect } from 'react' import { Hooks } from 'applesauce-react' import { RelayPool } from 'applesauce-relay' import { Bookmark } from '../types/bookmarks' import { BookmarkList } from './BookmarkList' import { fetchBookmarks } from '../services/bookmarkService' import ContentPanel from './ContentPanel' import { fetchReadableContent, ReadableContent } from '../services/readerService' interface BookmarksProps { relayPool: RelayPool | null } const Bookmarks: React.FC = ({ relayPool }) => { const [bookmarks, setBookmarks] = useState([]) const [loading, setLoading] = useState(true) const [selectedUrl, setSelectedUrl] = useState(undefined) const [readerLoading, setReaderLoading] = useState(false) const [readerContent, setReaderContent] = useState(undefined) const [isCollapsed, setIsCollapsed] = useState(false) const activeAccount = Hooks.useActiveAccount() const accountManager = Hooks.useAccountManager() useEffect(() => { console.log('Bookmarks useEffect triggered') console.log('relayPool:', !!relayPool) console.log('activeAccount:', !!activeAccount) if (relayPool && activeAccount) { console.log('Starting to fetch bookmarks...') handleFetchBookmarks() } else { console.log('Not fetching bookmarks - missing dependencies') } }, [relayPool, activeAccount?.pubkey]) // Only depend on pubkey, not the entire activeAccount object const handleFetchBookmarks = async () => { console.log('🔍 fetchBookmarks called, loading:', loading) if (!relayPool || !activeAccount) { console.log('🔍 fetchBookmarks early return - relayPool:', !!relayPool, 'activeAccount:', !!activeAccount) return } // 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 the full account object with extension capabilities const fullAccount = accountManager.getActive() await fetchBookmarks(relayPool, fullAccount || activeAccount, setBookmarks, setLoading, timeoutId) } const handleSelectUrl = async (url: string) => { setSelectedUrl(url) setReaderLoading(true) setReaderContent(undefined) try { const content = await fetchReadableContent(url) setReaderContent(content) } catch (err) { console.warn('Failed to fetch readable content:', err) } finally { setReaderLoading(false) } } if (loading) { return (
Loading bookmarks...
) } return (
setIsCollapsed(!isCollapsed)} />
) } export default Bookmarks