Skip to content
Source
Sign inSign up
fuko/trytanstackdb-v2
Open History to see the last commit

workspace.tsx

87 lines3.0 KB

1import { useLocation } from "@tanstack/react-router";
2import type { ReactNode } from "react";
3​
4import { BrowserFrame } from "@/components/browser/browser-frame";
5import { GuidePanel } from "@/components/guide/guide-panel";
6import { usePageTitle } from "@/components/notes/use-page-title";
7import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";
8import { useMediaQuery } from "@/hooks/use-media-query";
9import { cn } from "@/lib/utils";
10​
11/**
12 * The page: the guide and the app as two framed panels with a resizable gap
13 * between them. Side by side on desktop; stacked (app on top) on small screens.
14 */
15export function Workspace({ app }: { app: ReactNode }) {
16 const isDesktop = useMediaQuery("(min-width: 1024px)");
17 const title = usePageTitle();
18 const path = useLocation({ select: (location) => location.pathname });
19​
20 const appPanel = (
21 <Frame>
22 <BrowserFrame title={title} path={path} compact={!isDesktop}>
23 {app}
24 </BrowserFrame>
25 </Frame>
26 );
27 const guidePanel = (
28 <Frame>
29 <GuidePanel />
30 </Frame>
31 );
32​
33 return (
34 <main className="h-dvh bg-muted p-2 lg:p-4 dark:bg-[#0c0c0d]">
35 {isDesktop ? (
36 <ResizablePanelGroup key="desktop" orientation="horizontal">
37 <ResizablePanel id="guide" defaultSize="34%" minSize={320}>
38 {guidePanel}
39 </ResizablePanel>
40 <GapHandle orientation="horizontal" />
41 <ResizablePanel id="app" defaultSize="66%" minSize={720}>
42 {appPanel}
43 </ResizablePanel>
44 </ResizablePanelGroup>
45 ) : (
46 <ResizablePanelGroup key="mobile" orientation="vertical">
47 <ResizablePanel id="app" defaultSize="50%" minSize={220}>
48 {appPanel}
49 </ResizablePanel>
50 <GapHandle orientation="vertical" />
51 <ResizablePanel id="guide" defaultSize="50%" minSize={120}>
52 {/* Phase 4 can turn this panel into Guide / Requests tabs. */}
53 {guidePanel}
54 </ResizablePanel>
55 </ResizablePanelGroup>
56 )}
57 </main>
58 );
60​
61function Frame({ children }: { children: ReactNode }) {
62 return (
63 <div className="h-full overflow-hidden rounded-xl border bg-background shadow-sm lg:rounded-2xl">
64 {children}
65 </div>
66 );
68​
69/** The divider lives in the gap between the two panels. */
70function GapHandle({ orientation }: { orientation: "horizontal" | "vertical" }) {
71 const horizontal = orientation === "horizontal";
72 return (
73 <ResizableHandle
74 className={cn(
75 "group/handle bg-transparent after:hidden focus-visible:ring-0",
76 horizontal ? "w-3 lg:w-4" : "aria-[orientation=horizontal]:h-2",
77 )}
78 >
79 <span
80 className={cn(
81 "rounded-full bg-foreground/15 transition-colors group-hover/handle:bg-foreground/40 group-data-[separator=hover]/handle:bg-foreground/40 group-data-[separator=active]/handle:bg-guide-accent group-focus-visible/handle:bg-guide-accent",
82 horizontal ? "h-10 w-1" : "h-1 w-10",
83 )}
84 />
85 </ResizableHandle>
86 );