Files
textbee/web/components/shared/route-tabs.tsx
isra el 6c3636104e feat: messaging subroutes (send/bulk/history/api) with full-width history
- new shared RouteTabs primitive (components/shared/route-tabs.tsx): a
  link-based segmented control; tabs are real routes so the active tab
  survives refresh and deep links are shareable; aria-current on the active
  link and the active pill scrolls into view on mobile
- messaging/layout.tsx renders the section header + tabs; views become
  subroutes: / (Send, focused composer), /bulk, /history (now full width,
  previously cramped in a half column), /api-guide (the 419-line guide gets
  its own URL instead of half the page)
- delete the obsolete client-side tab wrapper (components)/messaging.tsx and
  dead main-dashboard.tsx
- messaging e2e rewritten for route tabs, including a direct-load test of
  /dashboard/messaging/history as the refresh-survival guarantee

Build, 25 unit tests, and 12 e2e green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-11 07:32:50 +03:00

73 lines
2.0 KiB
TypeScript

'use client'
import { useEffect, useRef } from 'react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { cn } from '@/lib/utils'
export type RouteTab = {
href: string
label: string
// Exact-match only (used for index routes like /dashboard/messaging so they
// don't stay active on sibling subroutes).
exact?: boolean
}
function isTabActive(tab: RouteTab, pathname: string): boolean {
if (tab.exact) return pathname === tab.href
return pathname === tab.href || pathname.startsWith(`${tab.href}/`)
}
// Link-based segmented control: tabs are real routes, so the active tab
// survives refresh and deep links are shareable. Mobile: horizontally
// scrollable pills; the active pill scrolls into view on load.
export default function RouteTabs({
tabs,
className,
}: {
tabs: RouteTab[]
className?: string
}) {
const pathname = usePathname()
const activeRef = useRef<HTMLAnchorElement | null>(null)
useEffect(() => {
// Deep links must land with the selected pill visible on small screens.
activeRef.current?.scrollIntoView({
block: 'nearest',
inline: 'center',
})
}, [pathname])
return (
<nav
className={cn(
'flex gap-1 overflow-x-auto rounded-lg bg-muted p-1',
'scrollbar-none w-full sm:w-fit',
className
)}
aria-label='Section navigation'
>
{tabs.map((tab) => {
const active = isTabActive(tab, pathname)
return (
<Link
key={tab.href}
href={tab.href}
ref={active ? activeRef : undefined}
aria-current={active ? 'page' : undefined}
className={cn(
'shrink-0 rounded-md px-3 py-1.5 text-sm font-medium transition-colors',
active
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
)}
>
{tab.label}
</Link>
)
})}
</nav>
)
}