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

notes-app.tsx

63 lines2.0 KB

1import { LoaderCircle } from "lucide-react";
2import type { ReactNode } from "react";
3​
4import { Button } from "@/components/ui/button";
5import { useAppData } from "@/db/queries";
6​
7import { MacSidebar } from "./mac/sidebar";
8import { NotesLayoutProvider, useNotesLayout } from "./notes-layout";
9import { useRollbackToasts } from "./use-rollback-toasts";
10​
11/**
12 * Root of the Notes clone. On macOS the sidebar stays mounted while routes
13 * swap the columns next to it; on iPhone each route is a full screen. The
14 * screens render once the collections have loaded from the API.
15 */
16export function NotesApp({ children }: { children: ReactNode }) {
17 useRollbackToasts();
18 return (
19 <NotesLayoutProvider>
20 <NotesAppFrame>{children}</NotesAppFrame>
21 </NotesLayoutProvider>
22 );
24​
25function NotesAppFrame({ children }: { children: ReactNode }) {
26 const { layout, sidebarVisible } = useNotesLayout();
27 const { status, retry } = useAppData();
28​
29 if (status !== "ready") {
30 return (
31 <div
32 className={
33 layout === "ios"
34 ? "grid h-full place-items-center bg-ios-bg text-ios-secondary"
35 : "grid h-full place-items-center bg-mac-content text-mac-text-secondary"
36 }
37 >
38 {status === "loading" ? (
39 <p className="flex items-center gap-2 text-[13px]" role="status">
40 <LoaderCircle className="size-4 animate-spin" aria-hidden />
41 Loading notes…
42 </p>
43 ) : (
44 <div className="space-y-3 text-center text-[13px]" role="alert">
45 <p>Couldn't load your notes.</p>
46 <Button size="sm" variant="outline" onClick={retry}>
47 Try again
48 </Button>
49 </div>
50 )}
51 </div>
52 );
53 }
54​
55 if (layout === "ios") return <div className="h-full">{children}</div>;
56​
57 return (
58 <div className="flex h-full bg-mac-content font-sans text-mac-text antialiased">
59 {sidebarVisible && <MacSidebar />}
60 {children}
61 </div>
62 );