From 1f5e3f82b0286457b2ec8cd9b0b349132f554acf Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 5 Oct 2025 09:06:54 +0100 Subject: [PATCH] feat: load default article on startup with collapsed sidebars - Redirect root path to default article (naddr) - Start with both sidebars (bookmarks and highlights) collapsed - Auto-fetch and show highlights for the article author - No authentication required to view articles - Highlights panel auto-expands when article loads - Login page moved to /login route --- dist/index.html | 2 +- src/App.tsx | 19 ++++++------------- src/components/Bookmarks.tsx | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dist/index.html b/dist/index.html index acf972a7..d944c05f 100644 --- a/dist/index.html +++ b/dist/index.html @@ -5,7 +5,7 @@ Boris - Nostr Bookmarks - + diff --git a/src/App.tsx b/src/App.tsx index 252df5a0..552c8c89 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react' -import { BrowserRouter, Routes, Route } from 'react-router-dom' +import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' import { EventStoreProvider, AccountsProvider } from 'applesauce-react' import { EventStore } from 'applesauce-core' import { AccountManager } from 'applesauce-accounts' @@ -8,11 +8,12 @@ import { createAddressLoader } from 'applesauce-loaders/loaders' import Login from './components/Login' import Bookmarks from './components/Bookmarks' +const DEFAULT_ARTICLE = 'naddr1qvzqqqr4gupzqmjxss3dld622uu8q25gywum9qtg4w4cv4064jmg20xsac2aam5nqqxnzd3cxqmrzv3exgmr2wfesgsmew' + function App() { const [eventStore, setEventStore] = useState(null) const [accountManager, setAccountManager] = useState(null) const [relayPool, setRelayPool] = useState(null) - const [isAuthenticated, setIsAuthenticated] = useState(false) useEffect(() => { // Initialize event store, account manager, and relay pool @@ -71,20 +72,12 @@ function App() { element={ setIsAuthenticated(false)} + onLogout={() => {}} /> } /> - setIsAuthenticated(true)} /> - ) : ( - setIsAuthenticated(false)} - /> - ) - } /> + } /> + {}} />} /> diff --git a/src/components/Bookmarks.tsx b/src/components/Bookmarks.tsx index 18a00c4c..6f1cbb13 100644 --- a/src/components/Bookmarks.tsx +++ b/src/components/Bookmarks.tsx @@ -31,8 +31,8 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { const [selectedUrl, setSelectedUrl] = useState(undefined) const [readerLoading, setReaderLoading] = useState(false) const [readerContent, setReaderContent] = useState(undefined) - const [isCollapsed, setIsCollapsed] = useState(false) - const [isHighlightsCollapsed, setIsHighlightsCollapsed] = useState(false) + const [isCollapsed, setIsCollapsed] = useState(true) // Start collapsed + const [isHighlightsCollapsed, setIsHighlightsCollapsed] = useState(true) // Start collapsed const [viewMode, setViewMode] = useState('compact') const [showUnderlines, setShowUnderlines] = useState(true) const [selectedHighlightId, setSelectedHighlightId] = useState(undefined) @@ -57,14 +57,27 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { setReaderContent(undefined) setSelectedUrl(`nostr:${naddr}`) // Use naddr as the URL identifier setIsCollapsed(true) + setIsHighlightsCollapsed(false) // Show highlights for the article try { const article = await fetchArticleByNaddr(relayPool, naddr) setReaderContent({ title: article.title, markdown: article.markdown, + image: article.image, url: `nostr:${naddr}` }) + + // Fetch highlights for this article (using the article author's pubkey) + try { + setHighlightsLoading(true) + const fetchedHighlights = await fetchHighlights(relayPool, article.author) + setHighlights(fetchedHighlights) + } catch (err) { + console.error('Failed to fetch highlights:', err) + } finally { + setHighlightsLoading(false) + } } catch (err) { console.error('Failed to load article:', err) setReaderContent({ @@ -72,6 +85,7 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { html: `

Failed to load article: ${err instanceof Error ? err.message : 'Unknown error'}

`, url: `nostr:${naddr}` }) + setReaderLoading(false) } finally { setReaderLoading(false) }