-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_AppShell.tsx
More file actions
70 lines (61 loc) · 1.74 KB
/
Copy path_AppShell.tsx
File metadata and controls
70 lines (61 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use client";
import { usePathname, useRouter } from "next/navigation";
import { useState, useTransition } from "react";
import { signOutFromKeycloak } from "@/app/actions";
import { LeftRail } from "@/components/shared/LeftRail";
import { TopBar } from "@/components/shared/TopBar";
const ROUTE_MAP: Record<string, string> = {
"/projects": "my-projects",
};
interface AppShellProps {
userInitials: string;
userHue?: 0 | 1 | 2 | 3;
children: React.ReactNode;
}
/**
* Authenticated page shell providing TopBar and LeftRail with mobile drawer state.
* @param userInitials - Initials shown in the TopBar avatar
* @param userHue - Avatar gradient variant (0–3)
*/
export function AppShell({
userInitials,
userHue = 1,
children,
}: AppShellProps) {
const pathname = usePathname();
const router = useRouter();
const [drawerOpen, setDrawerOpen] = useState(false);
const [, startTransition] = useTransition();
const activeRoute = ROUTE_MAP[pathname] ?? undefined;
function handleNavigate(routeId: string) {
const destinations: Record<string, string> = {
"my-projects": "/projects",
};
const path = destinations[routeId];
if (path) router.push(path);
}
function handleSignOut() {
startTransition(() => {
signOutFromKeycloak();
});
}
return (
<>
<TopBar
userInitials={userInitials}
userHue={userHue}
onMenuToggle={() => setDrawerOpen(true)}
onSignOut={handleSignOut}
/>
<div className="flex">
<LeftRail
route={activeRoute}
onNavigate={handleNavigate}
open={drawerOpen}
onClose={() => setDrawerOpen(false)}
/>
<div className="flex-1 min-w-0">{children}</div>
</div>
</>
);
}