()
| 31 | } |
| 32 | |
| 33 | export function App() { |
| 34 | const t = useUiMessages(); |
| 35 | const [route, setRoute] = useState<RouteState>(readRoute); |
| 36 | const { tab: activeTab, project: selectedProject } = route; |
| 37 | |
| 38 | /* Normalize the URL on first load so it always carries the current route. */ |
| 39 | useEffect(() => { |
| 40 | const initial = readRoute(); |
| 41 | window.history.replaceState(null, "", routeUrl(initial.tab, initial.project)); |
| 42 | }, []); |
| 43 | |
| 44 | /* Sync state when the user navigates with the browser back/forward buttons. */ |
| 45 | useEffect(() => { |
| 46 | const onPopState = () => setRoute(readRoute()); |
| 47 | window.addEventListener("popstate", onPopState); |
| 48 | return () => window.removeEventListener("popstate", onPopState); |
| 49 | }, []); |
| 50 | |
| 51 | /* Change the route and push a history entry (skips no-op navigations). */ |
| 52 | const navigate = useCallback((tab: TabId, project: string | null) => { |
| 53 | const url = routeUrl(tab, project); |
| 54 | const current = `${window.location.pathname}${window.location.search}${window.location.hash}`; |
| 55 | if (url === current) return; |
| 56 | window.history.pushState(null, "", url); |
| 57 | setRoute({ tab, project }); |
| 58 | }, []); |
| 59 | |
| 60 | const tabs: { id: TabId; label: string }[] = [ |
| 61 | { id: "graph", label: t.tabs.graph }, |
| 62 | { id: "stats", label: t.tabs.projects }, |
| 63 | { id: "control", label: t.tabs.control }, |
| 64 | ]; |
| 65 | |
| 66 | return ( |
| 67 | <div className="h-screen flex flex-col bg-background text-foreground"> |
| 68 | {/* Header */} |
| 69 | <header className="flex items-center justify-between px-5 h-12 border-b border-border bg-[#0b1920]/80 backdrop-blur-md shrink-0"> |
| 70 | <div className="flex items-center gap-6"> |
| 71 | <div className="flex items-center gap-2.5"> |
| 72 | <div className="w-[7px] h-[7px] rounded-full bg-primary" /> |
| 73 | <span className="text-[13px] font-semibold text-foreground/90 tracking-tight"> |
| 74 | Codebase Memory |
| 75 | </span> |
| 76 | </div> |
| 77 | |
| 78 | {/* Tabs inline in header */} |
| 79 | <nav className="flex items-center gap-0.5"> |
| 80 | {tabs.map((tab) => { |
| 81 | const disabled = tab.id === "graph" && !selectedProject; |
| 82 | return ( |
| 83 | <button |
| 84 | key={tab.id} |
| 85 | onClick={() => navigate(tab.id, tab.id === "stats" ? null : selectedProject)} |
| 86 | disabled={disabled} |
| 87 | title={disabled ? "Select a project first" : undefined} |
| 88 | className={`px-3 py-1 rounded-md text-[12px] font-medium transition-all ${ |
| 89 | disabled |
| 90 | ? "text-muted-foreground/30 cursor-not-allowed" |
nothing calls this directly
no test coverage detected