feat: add breadcrumb navigation to GlassTopBar
Site pages show: Your Sites > site-name > Page Title Each segment is clickable for navigation back. Home/non-site pages show plain title as before.
This commit is contained in:
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
import { useState, useCallback, useEffect, useRef } from 'react'
|
import { useState, useCallback, useEffect, useRef } from 'react'
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
|
import Link from 'next/link'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import { formatUpdatedAgo } from '@ciphera-net/ui'
|
import { formatUpdatedAgo } from '@ciphera-net/ui'
|
||||||
import { SidebarSimple } from '@phosphor-icons/react'
|
import { CaretRight, SidebarSimple } from '@phosphor-icons/react'
|
||||||
import { SidebarProvider, useSidebar } from '@/lib/sidebar-context'
|
import { SidebarProvider, useSidebar } from '@/lib/sidebar-context'
|
||||||
import { useRealtime } from '@/lib/swr/dashboard'
|
import { useRealtime } from '@/lib/swr/dashboard'
|
||||||
|
import { getSite } from '@/lib/api/sites'
|
||||||
import ContentHeader from './ContentHeader'
|
import ContentHeader from './ContentHeader'
|
||||||
|
|
||||||
const PAGE_TITLES: Record<string, string> = {
|
const PAGE_TITLES: Record<string, string> = {
|
||||||
@@ -58,6 +60,7 @@ function GlassTopBar({ siteId }: { siteId: string | null }) {
|
|||||||
const { data: realtime } = useRealtime(siteId ?? '')
|
const { data: realtime } = useRealtime(siteId ?? '')
|
||||||
const lastUpdatedRef = useRef<number | null>(null)
|
const lastUpdatedRef = useRef<number | null>(null)
|
||||||
const [, setTick] = useState(0)
|
const [, setTick] = useState(0)
|
||||||
|
const [siteName, setSiteName] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (siteId && realtime) lastUpdatedRef.current = Date.now()
|
if (siteId && realtime) lastUpdatedRef.current = Date.now()
|
||||||
@@ -69,13 +72,18 @@ function GlassTopBar({ siteId }: { siteId: string | null }) {
|
|||||||
return () => clearInterval(timer)
|
return () => clearInterval(timer)
|
||||||
}, [realtime])
|
}, [realtime])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!siteId) { setSiteName(null); return }
|
||||||
|
getSite(siteId).then((s) => setSiteName(s.name)).catch(() => {})
|
||||||
|
}, [siteId])
|
||||||
|
|
||||||
const dashboardTitle = usePageTitle()
|
const dashboardTitle = usePageTitle()
|
||||||
const homeTitle = useHomePageTitle()
|
const homeTitle = useHomePageTitle()
|
||||||
const pageTitle = siteId ? dashboardTitle : homeTitle
|
const pageTitle = siteId ? dashboardTitle : homeTitle
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="hidden md:flex items-center justify-between shrink-0 px-3 pt-1.5 pb-1">
|
<div className="hidden md:flex items-center justify-between shrink-0 px-3 pt-1.5 pb-1">
|
||||||
{/* Left: collapse toggle + page title */}
|
{/* Left: collapse toggle + breadcrumbs */}
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<button
|
<button
|
||||||
onClick={toggle}
|
onClick={toggle}
|
||||||
@@ -84,7 +92,17 @@ function GlassTopBar({ siteId }: { siteId: string | null }) {
|
|||||||
>
|
>
|
||||||
<SidebarSimple className="w-[18px] h-[18px]" weight={collapsed ? 'regular' : 'fill'} />
|
<SidebarSimple className="w-[18px] h-[18px]" weight={collapsed ? 'regular' : 'fill'} />
|
||||||
</button>
|
</button>
|
||||||
|
{siteId && siteName ? (
|
||||||
|
<nav className="flex items-center gap-1 text-sm font-medium">
|
||||||
|
<Link href="/" className="text-neutral-500 hover:text-neutral-300 transition-colors">Your Sites</Link>
|
||||||
|
<CaretRight className="w-3 h-3 text-neutral-600" />
|
||||||
|
<Link href={`/sites/${siteId}`} className="text-neutral-500 hover:text-neutral-300 transition-colors truncate max-w-[160px]">{siteName}</Link>
|
||||||
|
<CaretRight className="w-3 h-3 text-neutral-600" />
|
||||||
|
<span className="text-neutral-400">{pageTitle}</span>
|
||||||
|
</nav>
|
||||||
|
) : (
|
||||||
<span className="text-sm text-neutral-400 font-medium">{pageTitle}</span>
|
<span className="text-sm text-neutral-400 font-medium">{pageTitle}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Realtime indicator */}
|
{/* Realtime indicator */}
|
||||||
|
|||||||
Reference in New Issue
Block a user