feat: implement smart highlight clearing for articles

- Preserve highlights that belong to the current article when switching articles
- Only clear highlights that don't match the current article coordinate or event ID
- Improve user experience by maintaining relevant highlights during navigation
This commit is contained in:
Gigi
2025-10-25 00:54:02 +02:00
parent 465c24ed3a
commit a8ad346c5d

View File

@@ -76,8 +76,8 @@ export function useArticleLoader({
setSelectedUrl(`nostr:${naddr}`) setSelectedUrl(`nostr:${naddr}`)
setIsCollapsed(true) setIsCollapsed(true)
// Clear highlights immediately when starting to load a new article // Don't clear highlights yet - let the smart filtering logic handle it
setHighlights([]) // when we know the article coordinate
setHighlightsLoading(false) // Don't show loading yet setHighlightsLoading(false) // Don't show loading yet
// If we have preview data from navigation, show it immediately (no skeleton!) // If we have preview data from navigation, show it immediately (no skeleton!)
@@ -241,7 +241,13 @@ export function useArticleLoader({
if (coord && eventId) { if (coord && eventId) {
setHighlightsLoading(true) setHighlightsLoading(true)
setHighlights([]) // Clear highlights that don't belong to this article coordinate
setHighlights((prev) => {
return prev.filter(h => {
// Keep highlights that match this article coordinate or event ID
return h.eventReference === coord || h.eventReference === eventId
})
})
await fetchHighlightsForArticle( await fetchHighlightsForArticle(
relayPool, relayPool,
coord, coord,