From 70b85b0cf01cc06f78884ebb7e65c5db2ce846e9 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 5 Oct 2025 12:23:08 +0100 Subject: [PATCH] fix: refresh button now works without login for article highlights - Track current article coordinate and event ID in state - Update handleFetchHighlights to refresh article highlights if viewing article - Fall back to fetching user's highlights only if logged in and not viewing article - Refresh button now works for anonymous article viewing - No longer requires activeAccount to refresh highlights Previously the refresh button only worked when logged in because it tried to fetch highlights BY the user. Now it intelligently fetches highlights FOR the current article, or falls back to user highlights if logged in. --- dist/index.html | 2 +- src/components/Bookmarks.tsx | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dist/index.html b/dist/index.html index 5fe6ad1c..3168cbf1 100644 --- a/dist/index.html +++ b/dist/index.html @@ -5,7 +5,7 @@ Boris - Nostr Bookmarks - + diff --git a/src/components/Bookmarks.tsx b/src/components/Bookmarks.tsx index fce8ba99..0c408a48 100644 --- a/src/components/Bookmarks.tsx +++ b/src/components/Bookmarks.tsx @@ -37,6 +37,8 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { const [showUnderlines, setShowUnderlines] = useState(true) const [selectedHighlightId, setSelectedHighlightId] = useState(undefined) const [showSettings, setShowSettings] = useState(false) + const [currentArticleCoordinate, setCurrentArticleCoordinate] = useState(undefined) + const [currentArticleEventId, setCurrentArticleEventId] = useState(undefined) const activeAccount = Hooks.useActiveAccount() const accountManager = Hooks.useAccountManager() const eventStore = useEventStore() @@ -73,6 +75,10 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { const dTag = article.event.tags.find(t => t[0] === 'd')?.[1] || '' const articleCoordinate = `${article.event.kind}:${article.author}:${dTag}` + // Store article info for refresh functionality + setCurrentArticleCoordinate(articleCoordinate) + setCurrentArticleEventId(article.event.id) + console.log('📰 Article details:') console.log(' - Event ID:', article.event.id) console.log(' - Author:', article.author) @@ -130,11 +136,25 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { } const handleFetchHighlights = async () => { - if (!relayPool || !activeAccount) return + if (!relayPool) return + setHighlightsLoading(true) try { - const fetchedHighlights = await fetchHighlights(relayPool, activeAccount.pubkey) - setHighlights(fetchedHighlights) + // If we're viewing an article, fetch highlights for that article + if (currentArticleCoordinate) { + const fetchedHighlights = await fetchHighlightsForArticle( + relayPool, + currentArticleCoordinate, + currentArticleEventId + ) + console.log(`🔄 Refreshed ${fetchedHighlights.length} highlights for article`) + setHighlights(fetchedHighlights) + } + // Otherwise, if logged in, fetch user's own highlights + else if (activeAccount) { + const fetchedHighlights = await fetchHighlights(relayPool, activeAccount.pubkey) + setHighlights(fetchedHighlights) + } } catch (err) { console.error('Failed to fetch highlights:', err) } finally {