feat: page title in top bar next to collapse toggle
This commit is contained in:
@@ -2,12 +2,32 @@
|
|||||||
|
|
||||||
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 { usePathname } from 'next/navigation'
|
||||||
import { formatUpdatedAgo } from '@ciphera-net/ui'
|
import { formatUpdatedAgo } from '@ciphera-net/ui'
|
||||||
import { SidebarSimple } from '@phosphor-icons/react'
|
import { 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 ContentHeader from './ContentHeader'
|
import ContentHeader from './ContentHeader'
|
||||||
|
|
||||||
|
const PAGE_TITLES: Record<string, string> = {
|
||||||
|
'': 'Dashboard',
|
||||||
|
journeys: 'Journeys',
|
||||||
|
funnels: 'Funnels',
|
||||||
|
behavior: 'Behavior',
|
||||||
|
search: 'Search',
|
||||||
|
cdn: 'CDN',
|
||||||
|
uptime: 'Uptime',
|
||||||
|
pagespeed: 'PageSpeed',
|
||||||
|
settings: 'Site Settings',
|
||||||
|
}
|
||||||
|
|
||||||
|
function usePageTitle() {
|
||||||
|
const pathname = usePathname()
|
||||||
|
// pathname is /sites/:id or /sites/:id/section/...
|
||||||
|
const segment = pathname.replace(/^\/sites\/[^/]+\/?/, '').split('/')[0]
|
||||||
|
return PAGE_TITLES[segment] ?? segment.charAt(0).toUpperCase() + segment.slice(1) || 'Dashboard'
|
||||||
|
}
|
||||||
|
|
||||||
// Load sidebar only on the client — prevents SSR flash
|
// Load sidebar only on the client — prevents SSR flash
|
||||||
const Sidebar = dynamic(() => import('./Sidebar'), {
|
const Sidebar = dynamic(() => import('./Sidebar'), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -37,9 +57,12 @@ function GlassTopBar({ siteId }: { siteId: string }) {
|
|||||||
return () => clearInterval(timer)
|
return () => clearInterval(timer)
|
||||||
}, [realtime])
|
}, [realtime])
|
||||||
|
|
||||||
|
const pageTitle = usePageTitle()
|
||||||
|
|
||||||
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">
|
||||||
{/* Collapse toggle — mirrors sidebar AppLauncher row sizing for pixel alignment */}
|
{/* Left: collapse toggle + page title */}
|
||||||
|
<div className="flex items-center gap-1.5">
|
||||||
<button
|
<button
|
||||||
onClick={toggle}
|
onClick={toggle}
|
||||||
className="w-9 h-9 flex items-center justify-center text-neutral-400 hover:text-white rounded-lg hover:bg-white/[0.06] transition-colors"
|
className="w-9 h-9 flex items-center justify-center text-neutral-400 hover:text-white rounded-lg hover:bg-white/[0.06] transition-colors"
|
||||||
@@ -47,6 +70,8 @@ function GlassTopBar({ siteId }: { siteId: string }) {
|
|||||||
>
|
>
|
||||||
<SidebarSimple className="w-[18px] h-[18px]" weight={collapsed ? 'regular' : 'fill'} />
|
<SidebarSimple className="w-[18px] h-[18px]" weight={collapsed ? 'regular' : 'fill'} />
|
||||||
</button>
|
</button>
|
||||||
|
<span className="text-sm text-neutral-400 font-medium">{pageTitle}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Realtime indicator */}
|
{/* Realtime indicator */}
|
||||||
{lastUpdatedRef.current != null && (
|
{lastUpdatedRef.current != null && (
|
||||||
|
|||||||
Reference in New Issue
Block a user