feat: stream highlights progressively as they arrive from relays

This commit is contained in:
Gigi
2025-10-05 22:42:39 +01:00
parent 5e2abfa8c7
commit 41fb51c357
3 changed files with 121 additions and 21 deletions

View File

@@ -65,15 +65,23 @@ export function useArticleLoader({
setReaderLoading(false)
// Fetch highlights asynchronously without blocking article display
// Stream them as they arrive for instant rendering
try {
setHighlightsLoading(true)
const fetchedHighlights = await fetchHighlightsForArticle(
setHighlights([]) // Clear old highlights
const highlightsList: Highlight[] = []
await fetchHighlightsForArticle(
relayPool,
articleCoordinate,
article.event.id
article.event.id,
(highlight) => {
// Render each highlight immediately as it arrives
highlightsList.push(highlight)
setHighlights([...highlightsList].sort((a, b) => b.created_at - a.created_at))
}
)
console.log(`📌 Found ${fetchedHighlights.length} highlights`)
setHighlights(fetchedHighlights)
console.log(`📌 Found ${highlightsList.length} highlights`)
} catch (err) {
console.error('Failed to fetch highlights:', err)
} finally {