refactor: remove loading state and show bookmarks as they arrive

- Remove loading state variable from Bookmarks component
- Remove 'Loading bookmarks...' screen
- Start with empty list and populate bookmarks in background
- Remove timeout and loading callbacks from fetchBookmarks
- Better UX: show UI immediately, bookmarks appear when ready
- Bookmarks.tsx now at 197 lines
This commit is contained in:
Gigi
2025-10-05 03:15:57 +01:00
parent 183af3a80c
commit dd3203f34f
2 changed files with 2 additions and 20 deletions

View File

@@ -28,7 +28,6 @@ const RELAY_URLS = [
const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
const [bookmarks, setBookmarks] = useState<Bookmark[]>([])
const [loading, setLoading] = useState(true)
const [highlights, setHighlights] = useState<Highlight[]>([])
const [highlightsLoading, setHighlightsLoading] = useState(true)
const [selectedUrl, setSelectedUrl] = useState<string | undefined>(undefined)
@@ -69,9 +68,8 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
const handleFetchBookmarks = async () => {
if (!relayPool || !activeAccount) return
const timeoutId = setTimeout(() => setLoading(false), 15000)
const fullAccount = accountManager.getActive()
await fetchBookmarks(relayPool, fullAccount || activeAccount, setBookmarks, setLoading, timeoutId)
await fetchBookmarks(relayPool, fullAccount || activeAccount, setBookmarks)
}
const handleFetchHighlights = async () => {
@@ -132,14 +130,6 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
}
}
if (loading) {
return (
<div className="bookmarks-container">
<div className="loading">Loading bookmarks...</div>
</div>
)
}
return (
<>
<div className={`three-pane ${isCollapsed ? 'sidebar-collapsed' : ''} ${isHighlightsCollapsed ? 'highlights-collapsed' : ''}`}>

View File

@@ -20,12 +20,9 @@ import { collectBookmarksFromEvents } from './bookmarkProcessing.ts'
export const fetchBookmarks = async (
relayPool: RelayPool,
activeAccount: unknown, // Full account object with extension capabilities
setBookmarks: (bookmarks: Bookmark[]) => void,
setLoading: (loading: boolean) => void,
timeoutId: number
setBookmarks: (bookmarks: Bookmark[]) => void
) => {
try {
setLoading(true)
if (!isAccountWithExtension(activeAccount)) {
throw new Error('Invalid account object provided')
@@ -62,7 +59,6 @@ export const fetchBookmarks = async (
console.log('📋 After deduplication:', bookmarkListEvents.length, 'bookmark events')
if (bookmarkListEvents.length === 0) {
setBookmarks([])
setLoading(false)
return
}
// Aggregate across events
@@ -139,12 +135,8 @@ export const fetchBookmarks = async (
}
setBookmarks([bookmark])
clearTimeout(timeoutId)
setLoading(false)
} catch (error) {
console.error('Failed to fetch bookmarks:', error)
clearTimeout(timeoutId)
setLoading(false)
}
}