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

notes-app.tsx

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