From 5902664658a36e4afc81327eea9f8eef05561bcb Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Mon, 30 Dec 2024 12:15:35 +0000 Subject: refactor: Refactor sidebar into a shared component --- apps/web/app/admin/layout.tsx | 63 ++++++++++++++++++--------- apps/web/app/dashboard/layout.tsx | 89 +++++++++++++++++++++++++++++---------- apps/web/app/settings/layout.tsx | 86 ++++++++++++++++++++++++++----------- 3 files changed, 170 insertions(+), 68 deletions(-) (limited to 'apps/web/app') diff --git a/apps/web/app/admin/layout.tsx b/apps/web/app/admin/layout.tsx index 0d876736..7b20b7ad 100644 --- a/apps/web/app/admin/layout.tsx +++ b/apps/web/app/admin/layout.tsx @@ -1,11 +1,41 @@ import { redirect } from "next/navigation"; import { AdminCard } from "@/components/admin/AdminCard"; import { AdminNotices } from "@/components/admin/AdminNotices"; -import MobileAdminSidebar from "@/components/admin/sidebar/MobileSidebar"; -import AdminSidebar from "@/components/admin/sidebar/Sidebar"; -import Header from "@/components/dashboard/header/Header"; -import { Separator } from "@/components/ui/separator"; +import MobileSidebar from "@/components/shared/sidebar/MobileSidebar"; +import Sidebar from "@/components/shared/sidebar/Sidebar"; +import SidebarLayout from "@/components/shared/sidebar/SidebarLayout"; import { getServerAuthSession } from "@/server/auth"; +import { TFunction } from "i18next"; +import { Activity, ArrowLeft, Settings, Users } from "lucide-react"; + +const adminSidebarItems = ( + t: TFunction, +): { + name: string; + icon: JSX.Element; + path: string; +}[] => [ + { + name: t("settings.back_to_app"), + icon: , + path: "/dashboard/bookmarks", + }, + { + name: t("admin.server_stats.server_stats"), + icon: , + path: "/admin/overview", + }, + { + name: t("admin.users_list.users_list"), + icon: , + path: "/admin/users", + }, + { + name: t("common.actions"), + icon: , + path: "/admin/actions", + }, +]; export default async function AdminLayout({ children, @@ -18,23 +48,14 @@ export default async function AdminLayout({ } return ( -
-
-
-
- -
-
-
- - -
-
- - {children} -
-
+ } + mobileSidebar={} + > +
+ + {children}
-
+ ); } 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: , + path: "/dashboard/bookmarks", + }, + serverConfig.meilisearch + ? [ + { + name: t("common.search"), + icon: , + path: "/dashboard/search", + }, + ] + : [], + { + name: t("common.tags"), + icon: , + path: "/dashboard/tags", + }, + { + name: t("common.highlights"), + icon: , + path: "/dashboard/highlights", + }, + { + name: t("common.archive"), + icon: , + path: "/dashboard/archive", + }, + ].flat(); + return ( -
-
-
- -
- -
-
- {serverConfig.demoMode && } -
- - -
- {modal} -
{children}
-
-
-
+ + + + + } + /> + } + mobileSidebar={} + modal={modal} + > + {children} + ); } diff --git a/apps/web/app/settings/layout.tsx b/apps/web/app/settings/layout.tsx index 0ab6c624..bbff68a9 100644 --- a/apps/web/app/settings/layout.tsx +++ b/apps/web/app/settings/layout.tsx @@ -1,11 +1,60 @@ -import Header from "@/components/dashboard/header/Header"; -import DemoModeBanner from "@/components/DemoModeBanner"; -import MobileSidebar from "@/components/settings/sidebar/ModileSidebar"; -import Sidebar from "@/components/settings/sidebar/Sidebar"; -import { Separator } from "@/components/ui/separator"; -import ValidAccountCheck from "@/components/utils/ValidAccountCheck"; +import MobileSidebar from "@/components/shared/sidebar/MobileSidebar"; +import Sidebar from "@/components/shared/sidebar/Sidebar"; +import SidebarLayout from "@/components/shared/sidebar/SidebarLayout"; +import { TFunction } from "i18next"; +import { + ArrowLeft, + Download, + KeyRound, + Link, + Rss, + Sparkles, + User, +} from "lucide-react"; -import serverConfig from "@hoarder/shared/config"; +const settingsSidebarItems = ( + t: TFunction, +): { + name: string; + icon: JSX.Element; + path: string; +}[] => [ + { + name: t("settings.back_to_app"), + icon: , + path: "/dashboard/bookmarks", + }, + { + name: t("settings.info.user_info"), + icon: , + path: "/settings/info", + }, + { + name: t("settings.ai.ai_settings"), + icon: , + path: "/settings/ai", + }, + { + name: t("settings.feeds.rss_subscriptions"), + icon: , + path: "/settings/feeds", + }, + { + name: t("settings.import.import_export"), + icon: , + path: "/settings/import", + }, + { + name: t("settings.api_keys.api_keys"), + icon: , + path: "/settings/api-keys", + }, + { + name: t("settings.broken_links.broken_links"), + icon: , + path: "/settings/broken-links", + }, +]; export default async function SettingsLayout({ children, @@ -13,22 +62,11 @@ export default async function SettingsLayout({ children: React.ReactNode; }>) { return ( -
-
-
- -
- -
-
- {serverConfig.demoMode && } -
- - -
-
{children}
-
-
-
+ } + mobileSidebar={} + > + {children} + ); } -- cgit v1.2.3-70-g09d2