From 5902664658a36e4afc81327eea9f8eef05561bcb Mon Sep 17 00:00:00 2001
From: Mohamed Bassem <me@mbassem.com>
Date: Mon, 30 Dec 2024 12:15:35 +0000
Subject: refactor: Refactor sidebar into a shared component

---
 apps/web/app/dashboard/layout.tsx | 89 +++++++++++++++++++++++++++++----------
 1 file changed, 66 insertions(+), 23 deletions(-)

(limited to 'apps/web/app/dashboard/layout.tsx')

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>
   );
 }
-- 
cgit v1.2.3-70-g09d2

