diff --git a/src/PageManager.tsx b/src/PageManager.tsx index 8e4b634..6d6bf5e 100644 --- a/src/PageManager.tsx +++ b/src/PageManager.tsx @@ -91,6 +91,7 @@ const SecondaryPageContext = createContext(un const PrimaryNoteViewContext = createContext<{ setPrimaryNoteView: (view: ReactNode | null, type?: 'note' | 'settings' | 'settings-sub' | 'profile') => void + primaryViewType: 'note' | 'settings' | 'settings-sub' | 'profile' | null } | undefined>(undefined) export function usePrimaryPage() { @@ -128,7 +129,8 @@ export function useSmartNoteNavigation() { // When right panel is hidden, show note in primary area // Extract note ID from URL (e.g., "/notes/note1..." -> "note1...") const noteId = url.replace('/notes/', '') - setPrimaryNoteView(, 'note') + window.history.replaceState(null, '', url) + setPrimaryNoteView(, 'note') } else { // Normal behavior - use secondary navigation pushSecondary(url) @@ -170,6 +172,7 @@ export function useSmartProfileNavigation() { // When right panel is hidden, show profile in primary area // Extract profile ID from URL (e.g., "/users/npub1..." -> "npub1...") const profileId = url.replace('/users/', '') + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'profile') } else { // Normal behavior - use secondary navigation @@ -190,16 +193,22 @@ export function useSmartSettingsNavigation() { if (!showRecommendedRelaysPanel) { // When right panel is hidden, show settings page in primary area if (url === '/settings') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings') } else if (url === '/settings/relays') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings-sub') } else if (url === '/settings/wallet') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings-sub') } else if (url === '/settings/posts') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings-sub') } else if (url === '/settings/general') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings-sub') } else if (url === '/settings/translation') { + window.history.replaceState(null, '', url) setPrimaryNoteView(, 'settings-sub') } } else { @@ -311,6 +320,7 @@ function MainContentArea({ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { const { isSmallScreen } = useScreenSize() + const { showRecommendedRelaysPanel } = useUserPreferences() const [currentPrimaryPage, setCurrentPrimaryPage] = useState('home') const [primaryPages, setPrimaryPages] = useState< { name: TPrimaryPageName; element: ReactNode; props?: any }[] @@ -323,10 +333,22 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { const [secondaryStack, setSecondaryStack] = useState([]) const [primaryNoteView, setPrimaryNoteViewState] = useState(null) const [primaryViewType, setPrimaryViewType] = useState<'note' | 'settings' | 'settings-sub' | 'profile' | null>(null) + const [savedPrimaryPage, setSavedPrimaryPage] = useState(null) const setPrimaryNoteView = (view: ReactNode | null, type?: 'note' | 'settings' | 'settings-sub' | 'profile') => { + if (view && !primaryNoteView) { + // Saving current primary page before showing overlay + setSavedPrimaryPage(currentPrimaryPage) + } + setPrimaryNoteViewState(view) setPrimaryViewType(type || null) + + // If clearing the view, restore to the saved primary page + if (!view && savedPrimaryPage) { + const newUrl = savedPrimaryPage === 'home' ? '/' : `/?page=${savedPrimaryPage}` + window.history.replaceState(null, '', newUrl) + } } const ignorePopStateRef = useRef(false) @@ -351,20 +373,27 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { window.history.pushState(null, '', window.location.href) if (window.location.pathname !== '/') { const url = window.location.pathname + window.location.search + window.location.hash - setSecondaryStack((prevStack) => { - if (isCurrentPage(prevStack, url)) return prevStack - - const { newStack, newItem } = pushNewPageToStack( - prevStack, - url, - maxStackSize, - window.history.state?.index - ) - if (newItem) { - window.history.replaceState({ index: newItem.index, url }, '', url) - } - return newStack - }) + + // If the side panel is off and we're on a settings page, don't add to secondary stack + // The settings navigation will handle it via primary view + if (!showRecommendedRelaysPanel && window.location.pathname.startsWith('/settings')) { + // Skip secondary stack handling for settings when side panel is off + } else { + setSecondaryStack((prevStack) => { + if (isCurrentPage(prevStack, url)) return prevStack + + const { newStack, newItem } = pushNewPageToStack( + prevStack, + url, + maxStackSize, + window.history.state?.index + ) + if (newItem) { + window.history.replaceState({ index: newItem.index, url }, '', url) + } + return newStack + }) + } } else { const searchParams = new URLSearchParams(window.location.search) const r = searchParams.get('r') @@ -467,6 +496,9 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { }) setCurrentPrimaryPage(page) + // Clear any primary note view when navigating to a new primary page + setPrimaryNoteView(null) + // Update URL for primary pages (except home) const newUrl = page === 'home' ? '/' : `/?page=${page}` window.history.pushState(null, '', newUrl) @@ -532,7 +564,7 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { > - + {!!secondaryStack.length && secondaryStack.map((item, index) => (
- +
navigate('discussions')} - active={current === 'discussions'} + active={display && current === 'discussions' && primaryViewType === null} > diff --git a/src/components/Sidebar/ExploreButton.tsx b/src/components/Sidebar/ExploreButton.tsx index 8495d11..67bb8e6 100644 --- a/src/components/Sidebar/ExploreButton.tsx +++ b/src/components/Sidebar/ExploreButton.tsx @@ -1,17 +1,18 @@ -import { usePrimaryPage } from '@/PageManager' +import { usePrimaryPage, usePrimaryNoteView } from '@/PageManager' import { Compass } from 'lucide-react' import { useTranslation } from 'react-i18next' import SidebarItem from './SidebarItem' export default function RelaysButton() { const { t } = useTranslation() - const { navigate, current } = usePrimaryPage() + const { navigate, current, display } = usePrimaryPage() + const { primaryViewType } = usePrimaryNoteView() return ( navigate('explore')} - active={current === 'explore'} + active={display && current === 'explore' && primaryViewType === null} > diff --git a/src/components/Sidebar/HomeButton.tsx b/src/components/Sidebar/HomeButton.tsx index 0b3db67..bde11df 100644 --- a/src/components/Sidebar/HomeButton.tsx +++ b/src/components/Sidebar/HomeButton.tsx @@ -1,12 +1,17 @@ -import { usePrimaryPage } from '@/PageManager' +import { usePrimaryPage, usePrimaryNoteView } from '@/PageManager' import { Home } from 'lucide-react' import SidebarItem from './SidebarItem' export default function HomeButton() { - const { navigate, current } = usePrimaryPage() + const { navigate, current, display } = usePrimaryPage() + const { primaryViewType } = usePrimaryNoteView() return ( - navigate('home')} active={current === 'home'}> + navigate('home')} + active={display && current === 'home' && primaryViewType === null} + > ) diff --git a/src/components/Sidebar/NotificationButton.tsx b/src/components/Sidebar/NotificationButton.tsx index d0bae5b..178dc23 100644 --- a/src/components/Sidebar/NotificationButton.tsx +++ b/src/components/Sidebar/NotificationButton.tsx @@ -1,4 +1,4 @@ -import { usePrimaryPage } from '@/PageManager' +import { usePrimaryPage, usePrimaryNoteView } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { useNotification } from '@/providers/NotificationProvider' import { Bell } from 'lucide-react' @@ -6,14 +6,15 @@ import SidebarItem from './SidebarItem' export default function NotificationsButton() { const { checkLogin } = useNostr() - const { navigate, current } = usePrimaryPage() + const { navigate, current, display } = usePrimaryPage() + const { primaryViewType } = usePrimaryNoteView() const { hasNewNotification } = useNotification() return ( checkLogin(() => navigate('notifications'))} - active={current === 'notifications'} + active={display && current === 'notifications' && primaryViewType === null} >
diff --git a/src/components/Sidebar/ProfileButton.tsx b/src/components/Sidebar/ProfileButton.tsx index d707015..0ca32d3 100644 --- a/src/components/Sidebar/ProfileButton.tsx +++ b/src/components/Sidebar/ProfileButton.tsx @@ -1,17 +1,18 @@ -import { usePrimaryPage } from '@/PageManager' +import { usePrimaryPage, usePrimaryNoteView } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { UserRound } from 'lucide-react' import SidebarItem from './SidebarItem' export default function ProfileButton() { - const { navigate, current } = usePrimaryPage() + const { navigate, current, display } = usePrimaryPage() + const { primaryViewType } = usePrimaryNoteView() const { checkLogin } = useNostr() return ( checkLogin(() => navigate('profile'))} - active={current === 'profile'} + active={display && current === 'profile' && primaryViewType === 'profile'} > diff --git a/src/components/Sidebar/SearchButton.tsx b/src/components/Sidebar/SearchButton.tsx index 126a891..f1bdcdc 100644 --- a/src/components/Sidebar/SearchButton.tsx +++ b/src/components/Sidebar/SearchButton.tsx @@ -1,15 +1,16 @@ -import { usePrimaryPage } from '@/PageManager' +import { usePrimaryPage, usePrimaryNoteView } from '@/PageManager' import { Search } from 'lucide-react' import SidebarItem from './SidebarItem' export default function SearchButton() { const { navigate, current, display } = usePrimaryPage() + const { primaryViewType } = usePrimaryNoteView() return ( navigate('search')} - active={current === 'search' && display} + active={current === 'search' && display && primaryViewType === null} > diff --git a/src/components/Sidebar/SettingsButton.tsx b/src/components/Sidebar/SettingsButton.tsx index 6df5af0..7b134a8 100644 --- a/src/components/Sidebar/SettingsButton.tsx +++ b/src/components/Sidebar/SettingsButton.tsx @@ -1,13 +1,25 @@ import { toSettings } from '@/lib/link' -import { useSmartSettingsNavigation } from '@/PageManager' +import { useSmartSettingsNavigation, usePrimaryNoteView } from '@/PageManager' +import { useUserPreferences } from '@/providers/UserPreferencesProvider' import { Settings } from 'lucide-react' import SidebarItem from './SidebarItem' export default function SettingsButton() { const { navigateToSettings } = useSmartSettingsNavigation() + const { primaryViewType } = usePrimaryNoteView() + const { showRecommendedRelaysPanel } = useUserPreferences() + + // Settings is active when: + // 1. primaryViewType is 'settings' or 'settings-sub' (when side panel is off) + // 2. OR we're on a /settings URL (when side panel is on) + const url = window.location.pathname + const isActive = + primaryViewType === 'settings' || + primaryViewType === 'settings-sub' || + (showRecommendedRelaysPanel && url.startsWith('/settings')) return ( - navigateToSettings(toSettings())}> + navigateToSettings(toSettings())} active={isActive}> )