mirror of
https://github.com/dergigi/boris.git
synced 2025-12-27 11:34:50 +01:00
feat(routing): add /settings route and URL-based settings navigation
- Add /settings route to router - Derive showSettings from location.pathname instead of state - Update onOpenSettings to navigate to /settings - Update onCloseSettings to navigate back to previous location - Track previous location to restore context when closing settings - Remove showSettings state from useBookmarksUI hook
This commit is contained in:
@@ -52,6 +52,15 @@ function AppRoutes({
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/settings"
|
||||
element={
|
||||
<Bookmarks
|
||||
relayPool={relayPool}
|
||||
onLogout={handleLogout}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Route path="/" element={<Navigate to={`/a/${DEFAULT_ARTICLE}`} replace />} />
|
||||
</Routes>
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useMemo } from 'react'
|
||||
import { useParams, useLocation } from 'react-router-dom'
|
||||
import React, { useMemo, useEffect, useRef } from 'react'
|
||||
import { useParams, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { Hooks } from 'applesauce-react'
|
||||
import { useEventStore } from 'applesauce-react/hooks'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
@@ -23,10 +23,21 @@ interface BookmarksProps {
|
||||
const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
const { naddr } = useParams<{ naddr?: string }>()
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const previousLocationRef = useRef<string>()
|
||||
|
||||
const externalUrl = location.pathname.startsWith('/r/')
|
||||
? decodeURIComponent(location.pathname.slice(3))
|
||||
: undefined
|
||||
|
||||
const showSettings = location.pathname === '/settings'
|
||||
|
||||
// Track previous location for going back from settings
|
||||
useEffect(() => {
|
||||
if (!showSettings) {
|
||||
previousLocationRef.current = location.pathname
|
||||
}
|
||||
}, [location.pathname, showSettings])
|
||||
|
||||
const activeAccount = Hooks.useActiveAccount()
|
||||
const accountManager = Hooks.useAccountManager()
|
||||
@@ -50,8 +61,6 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
setShowHighlights,
|
||||
selectedHighlightId,
|
||||
setSelectedHighlightId,
|
||||
showSettings,
|
||||
setShowSettings,
|
||||
currentArticleCoordinate,
|
||||
setCurrentArticleCoordinate,
|
||||
currentArticleEventId,
|
||||
@@ -94,7 +103,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
relayPool,
|
||||
settings,
|
||||
setIsCollapsed,
|
||||
setShowSettings,
|
||||
setShowSettings: () => {}, // No-op since we use route-based settings now
|
||||
setCurrentArticle
|
||||
})
|
||||
|
||||
@@ -160,7 +169,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
onLogout={onLogout}
|
||||
onViewModeChange={setViewMode}
|
||||
onOpenSettings={() => {
|
||||
setShowSettings(true)
|
||||
navigate('/settings')
|
||||
setIsCollapsed(true)
|
||||
setIsHighlightsCollapsed(true)
|
||||
}}
|
||||
@@ -171,7 +180,11 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
selectedUrl={selectedUrl}
|
||||
settings={settings}
|
||||
onSaveSettings={saveSettings}
|
||||
onCloseSettings={() => setShowSettings(false)}
|
||||
onCloseSettings={() => {
|
||||
// Navigate back to previous location or default
|
||||
const backTo = previousLocationRef.current || '/'
|
||||
navigate(backTo)
|
||||
}}
|
||||
classifiedHighlights={classifiedHighlights}
|
||||
showHighlights={showHighlights}
|
||||
selectedHighlightId={selectedHighlightId}
|
||||
|
||||
@@ -14,7 +14,6 @@ export const useBookmarksUI = ({ settings }: UseBookmarksUIParams) => {
|
||||
const [viewMode, setViewMode] = useState<ViewMode>('compact')
|
||||
const [showHighlights, setShowHighlights] = useState(true)
|
||||
const [selectedHighlightId, setSelectedHighlightId] = useState<string | undefined>(undefined)
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const [currentArticleCoordinate, setCurrentArticleCoordinate] = useState<string | undefined>(undefined)
|
||||
const [currentArticleEventId, setCurrentArticleEventId] = useState<string | undefined>(undefined)
|
||||
const [currentArticle, setCurrentArticle] = useState<NostrEvent | undefined>(undefined)
|
||||
@@ -46,8 +45,6 @@ export const useBookmarksUI = ({ settings }: UseBookmarksUIParams) => {
|
||||
setShowHighlights,
|
||||
selectedHighlightId,
|
||||
setSelectedHighlightId,
|
||||
showSettings,
|
||||
setShowSettings,
|
||||
currentArticleCoordinate,
|
||||
setCurrentArticleCoordinate,
|
||||
currentArticleEventId,
|
||||
|
||||
Reference in New Issue
Block a user