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/components/shared/sidebar | |
| parent | 179f00b15525b024b6823088ef8fb94b7106b4f0 (diff) | |
| download | karakeep-5902664658a36e4afc81327eea9f8eef05561bcb.tar.zst | |
refactor: Refactor sidebar into a shared component
Diffstat (limited to 'apps/web/components/shared/sidebar')
| -rw-r--r-- | apps/web/components/shared/sidebar/MobileSidebar.tsx | 26 | ||||
| -rw-r--r-- | apps/web/components/shared/sidebar/Sidebar.tsx | 38 | ||||
| -rw-r--r-- | apps/web/components/shared/sidebar/SidebarLayout.tsx | 37 | ||||
| -rw-r--r-- | apps/web/components/shared/sidebar/TSidebarItem.ts | 5 |
4 files changed, 106 insertions, 0 deletions
diff --git a/apps/web/components/shared/sidebar/MobileSidebar.tsx b/apps/web/components/shared/sidebar/MobileSidebar.tsx new file mode 100644 index 00000000..d3edc7df --- /dev/null +++ b/apps/web/components/shared/sidebar/MobileSidebar.tsx @@ -0,0 +1,26 @@ +import { useTranslation } from "@/lib/i18n/server"; +import { TFunction } from "i18next"; + +import MobileSidebarItem from "./ModileSidebarItem"; +import { TSidebarItem } from "./TSidebarItem"; + +export default async function MobileSidebar({ + items, +}: { + items: (t: TFunction) => TSidebarItem[]; +}) { + const { t } = await useTranslation(); + return ( + <aside className="w-full"> + <ul className="flex justify-between space-x-2 border-b-black px-5 py-2 pt-5"> + {items(t).map((item) => ( + <MobileSidebarItem + key={item.name} + logo={item.icon} + path={item.path} + /> + ))} + </ul> + </aside> + ); +} diff --git a/apps/web/components/shared/sidebar/Sidebar.tsx b/apps/web/components/shared/sidebar/Sidebar.tsx new file mode 100644 index 00000000..bd5d23e6 --- /dev/null +++ b/apps/web/components/shared/sidebar/Sidebar.tsx @@ -0,0 +1,38 @@ +import { useTranslation } from "@/lib/i18n/server"; +import { TFunction } from "i18next"; + +import serverConfig from "@hoarder/shared/config"; + +import SidebarItem from "./SidebarItem"; +import { TSidebarItem } from "./TSidebarItem"; + +export default async function Sidebar({ + items, + extraSections, +}: { + items: (t: TFunction) => TSidebarItem[]; + extraSections?: React.ReactNode; +}) { + const { t } = await useTranslation(); + + return ( + <aside className="flex h-[calc(100vh-64px)] w-60 flex-col gap-5 border-r p-4 "> + <div> + <ul className="space-y-2 text-sm font-medium"> + {items(t).map((item) => ( + <SidebarItem + key={item.name} + logo={item.icon} + name={item.name} + path={item.path} + /> + ))} + </ul> + </div> + {extraSections} + <div className="mt-auto flex items-center border-t pt-2 text-sm text-gray-400"> + Hoarder v{serverConfig.serverVersion} + </div> + </aside> + ); +} diff --git a/apps/web/components/shared/sidebar/SidebarLayout.tsx b/apps/web/components/shared/sidebar/SidebarLayout.tsx new file mode 100644 index 00000000..2a2a872e --- /dev/null +++ b/apps/web/components/shared/sidebar/SidebarLayout.tsx @@ -0,0 +1,37 @@ +import Header from "@/components/dashboard/header/Header"; +import DemoModeBanner from "@/components/DemoModeBanner"; +import { Separator } from "@/components/ui/separator"; +import ValidAccountCheck from "@/components/utils/ValidAccountCheck"; + +import serverConfig from "@hoarder/shared/config"; + +export default function SidebarLayout({ + children, + mobileSidebar, + sidebar, + modal, +}: { + children: React.ReactNode; + mobileSidebar: React.ReactNode; + sidebar: React.ReactNode; + modal?: React.ReactNode; +}) { + 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> + ); +} diff --git a/apps/web/components/shared/sidebar/TSidebarItem.ts b/apps/web/components/shared/sidebar/TSidebarItem.ts new file mode 100644 index 00000000..84cd58f5 --- /dev/null +++ b/apps/web/components/shared/sidebar/TSidebarItem.ts @@ -0,0 +1,5 @@ +export interface TSidebarItem { + name: string; + icon: JSX.Element; + path: string; +} |
