diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-12-30 12:15:35 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-12-30 12:15:35 +0000 |
| commit | 5902664658a36e4afc81327eea9f8eef05561bcb (patch) | |
| tree | b72415e988efb5cd95e4a28634b0b53bf125b168 /apps/web/app/dashboard/layout.tsx | |
| parent | 179f00b15525b024b6823088ef8fb94b7106b4f0 (diff) | |
| download | karakeep-5902664658a36e4afc81327eea9f8eef05561bcb.tar.zst | |
refactor: Refactor sidebar into a shared component
Diffstat (limited to 'apps/web/app/dashboard/layout.tsx')
| -rw-r--r-- | apps/web/app/dashboard/layout.tsx | 89 |
1 files changed, 66 insertions, 23 deletions
diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx index cbd51245..17a7c144 100644 --- a/apps/web/app/dashboard/layout.tsx +++ b/apps/web/app/dashboard/layout.tsx @@ -1,9 +1,13 @@ -import Header from "@/components/dashboard/header/Header"; -import MobileSidebar from "@/components/dashboard/sidebar/ModileSidebar"; -import Sidebar from "@/components/dashboard/sidebar/Sidebar"; -import DemoModeBanner from "@/components/DemoModeBanner"; +import { redirect } from "next/navigation"; +import AllLists from "@/components/dashboard/sidebar/AllLists"; +import MobileSidebar from "@/components/shared/sidebar/MobileSidebar"; +import Sidebar from "@/components/shared/sidebar/Sidebar"; +import SidebarLayout from "@/components/shared/sidebar/SidebarLayout"; import { Separator } from "@/components/ui/separator"; -import ValidAccountCheck from "@/components/utils/ValidAccountCheck"; +import { api } from "@/server/api/client"; +import { getServerAuthSession } from "@/server/auth"; +import { TFunction } from "i18next"; +import { Archive, Highlighter, Home, Search, Tag } from "lucide-react"; import serverConfig from "@hoarder/shared/config"; @@ -14,24 +18,63 @@ export default async function Dashboard({ children: React.ReactNode; modal: React.ReactNode; }>) { + const session = await getServerAuthSession(); + if (!session) { + redirect("/"); + } + + const lists = await api.lists.list(); + + const items = (t: TFunction) => + [ + { + name: t("common.home"), + icon: <Home size={18} />, + path: "/dashboard/bookmarks", + }, + serverConfig.meilisearch + ? [ + { + name: t("common.search"), + icon: <Search size={18} />, + path: "/dashboard/search", + }, + ] + : [], + { + name: t("common.tags"), + icon: <Tag size={18} />, + path: "/dashboard/tags", + }, + { + name: t("common.highlights"), + icon: <Highlighter size={18} />, + path: "/dashboard/highlights", + }, + { + name: t("common.archive"), + icon: <Archive size={18} />, + path: "/dashboard/archive", + }, + ].flat(); + return ( - <div> - <Header /> - <div className="flex min-h-[calc(100vh-64px)] w-screen flex-col sm:h-[calc(100vh-64px)] sm:flex-row"> - <ValidAccountCheck /> - <div className="hidden flex-none sm:flex"> - <Sidebar /> - </div> - <main className="flex-1 bg-muted sm:overflow-y-auto"> - {serverConfig.demoMode && <DemoModeBanner />} - <div className="block w-full sm:hidden"> - <MobileSidebar /> - <Separator /> - </div> - {modal} - <div className="min-h-30 container p-4">{children}</div> - </main> - </div> - </div> + <SidebarLayout + sidebar={ + <Sidebar + items={items} + extraSections={ + <> + <Separator /> + <AllLists initialData={lists} /> + </> + } + /> + } + mobileSidebar={<MobileSidebar items={items} />} + modal={modal} + > + {children} + </SidebarLayout> ); } |
