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 --- .../web/components/admin/sidebar/MobileSidebar.tsx | 21 ------ apps/web/components/admin/sidebar/Sidebar.tsx | 36 ---------- apps/web/components/admin/sidebar/items.tsx | 31 --------- .../components/dashboard/sidebar/ModileSidebar.tsx | 23 ------ apps/web/components/dashboard/sidebar/Sidebar.tsx | 81 ---------------------- .../components/settings/sidebar/ModileSidebar.tsx | 21 ------ apps/web/components/settings/sidebar/Sidebar.tsx | 36 ---------- apps/web/components/settings/sidebar/items.tsx | 55 --------------- .../components/shared/sidebar/MobileSidebar.tsx | 26 +++++++ apps/web/components/shared/sidebar/Sidebar.tsx | 38 ++++++++++ .../components/shared/sidebar/SidebarLayout.tsx | 37 ++++++++++ apps/web/components/shared/sidebar/TSidebarItem.ts | 5 ++ 12 files changed, 106 insertions(+), 304 deletions(-) delete mode 100644 apps/web/components/admin/sidebar/MobileSidebar.tsx delete mode 100644 apps/web/components/admin/sidebar/Sidebar.tsx delete mode 100644 apps/web/components/admin/sidebar/items.tsx delete mode 100644 apps/web/components/dashboard/sidebar/ModileSidebar.tsx delete mode 100644 apps/web/components/dashboard/sidebar/Sidebar.tsx delete mode 100644 apps/web/components/settings/sidebar/ModileSidebar.tsx delete mode 100644 apps/web/components/settings/sidebar/Sidebar.tsx delete mode 100644 apps/web/components/settings/sidebar/items.tsx create mode 100644 apps/web/components/shared/sidebar/MobileSidebar.tsx create mode 100644 apps/web/components/shared/sidebar/Sidebar.tsx create mode 100644 apps/web/components/shared/sidebar/SidebarLayout.tsx create mode 100644 apps/web/components/shared/sidebar/TSidebarItem.ts (limited to 'apps/web/components') diff --git a/apps/web/components/admin/sidebar/MobileSidebar.tsx b/apps/web/components/admin/sidebar/MobileSidebar.tsx deleted file mode 100644 index 416b944c..00000000 --- a/apps/web/components/admin/sidebar/MobileSidebar.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import MobileSidebarItem from "@/components/shared/sidebar/ModileSidebarItem"; -import { useTranslation } from "@/lib/i18n/server"; - -import { adminSidebarItems } from "./items"; - -export default async function MobileSidebar() { - const { t } = await useTranslation(); - return ( - - ); -} diff --git a/apps/web/components/admin/sidebar/Sidebar.tsx b/apps/web/components/admin/sidebar/Sidebar.tsx deleted file mode 100644 index 8a5d615a..00000000 --- a/apps/web/components/admin/sidebar/Sidebar.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { redirect } from "next/navigation"; -import SidebarItem from "@/components/shared/sidebar/SidebarItem"; -import { useTranslation } from "@/lib/i18n/server"; -import { getServerAuthSession } from "@/server/auth"; - -import serverConfig from "@hoarder/shared/config"; - -import { adminSidebarItems } from "./items"; - -export default async function Sidebar() { - const { t } = await useTranslation(); - const session = await getServerAuthSession(); - if (!session) { - redirect("/"); - } - - return ( - - ); -} diff --git a/apps/web/components/admin/sidebar/items.tsx b/apps/web/components/admin/sidebar/items.tsx deleted file mode 100644 index 78dfee34..00000000 --- a/apps/web/components/admin/sidebar/items.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import { TFunction } from "i18next"; -import { Activity, ArrowLeft, Settings, Users } from "lucide-react"; - -export 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", - }, -]; diff --git a/apps/web/components/dashboard/sidebar/ModileSidebar.tsx b/apps/web/components/dashboard/sidebar/ModileSidebar.tsx deleted file mode 100644 index 777877bf..00000000 --- a/apps/web/components/dashboard/sidebar/ModileSidebar.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import MobileSidebarItem from "@/components/shared/sidebar/ModileSidebarItem"; -import HoarderLogoIcon from "@/public/icons/logo-icon.svg"; -import { ClipboardList, Highlighter, Search, Tag } from "lucide-react"; - -export default async function MobileSidebar() { - return ( - - ); -} diff --git a/apps/web/components/dashboard/sidebar/Sidebar.tsx b/apps/web/components/dashboard/sidebar/Sidebar.tsx deleted file mode 100644 index 0f805a09..00000000 --- a/apps/web/components/dashboard/sidebar/Sidebar.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { redirect } from "next/navigation"; -import SidebarItem from "@/components/shared/sidebar/SidebarItem"; -import { Separator } from "@/components/ui/separator"; -import { useTranslation } from "@/lib/i18n/server"; -import { api } from "@/server/api/client"; -import { getServerAuthSession } from "@/server/auth"; -import { Archive, Highlighter, Home, Search, Tag } from "lucide-react"; - -import serverConfig from "@hoarder/shared/config"; - -import AllLists from "./AllLists"; - -export default async function Sidebar() { - const { t } = await useTranslation(); - const session = await getServerAuthSession(); - if (!session) { - redirect("/"); - } - - const lists = await api.lists.list(); - - const searchItem = serverConfig.meilisearch - ? [ - { - name: t("common.search"), - icon: , - path: "/dashboard/search", - }, - ] - : []; - - const menu: { - name: string; - icon: JSX.Element; - path: string; - }[] = [ - { - name: t("common.home"), - icon: , - path: "/dashboard/bookmarks", - }, - ...searchItem, - { - name: t("common.tags"), - icon: , - path: "/dashboard/tags", - }, - { - name: t("common.highlights"), - icon: , - path: "/dashboard/highlights", - }, - { - name: t("common.archive"), - icon: , - path: "/dashboard/archive", - }, - ]; - - return ( - - ); -} diff --git a/apps/web/components/settings/sidebar/ModileSidebar.tsx b/apps/web/components/settings/sidebar/ModileSidebar.tsx deleted file mode 100644 index cbed9ef9..00000000 --- a/apps/web/components/settings/sidebar/ModileSidebar.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import MobileSidebarItem from "@/components/shared/sidebar/ModileSidebarItem"; -import { useTranslation } from "@/lib/i18n/server"; - -import { settingsSidebarItems } from "./items"; - -export default async function MobileSidebar() { - const { t } = await useTranslation(); - return ( - - ); -} diff --git a/apps/web/components/settings/sidebar/Sidebar.tsx b/apps/web/components/settings/sidebar/Sidebar.tsx deleted file mode 100644 index a1b61e98..00000000 --- a/apps/web/components/settings/sidebar/Sidebar.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { redirect } from "next/navigation"; -import SidebarItem from "@/components/shared/sidebar/SidebarItem"; -import { useTranslation } from "@/lib/i18n/server"; -import { getServerAuthSession } from "@/server/auth"; - -import serverConfig from "@hoarder/shared/config"; - -import { settingsSidebarItems } from "./items"; - -export default async function Sidebar() { - const { t } = await useTranslation(); - const session = await getServerAuthSession(); - if (!session) { - redirect("/"); - } - - return ( - - ); -} diff --git a/apps/web/components/settings/sidebar/items.tsx b/apps/web/components/settings/sidebar/items.tsx deleted file mode 100644 index f76d494a..00000000 --- a/apps/web/components/settings/sidebar/items.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React from "react"; -import { TFunction } from "i18next"; -import { - ArrowLeft, - Download, - KeyRound, - Link, - Rss, - Sparkles, - User, -} from "lucide-react"; - -export 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", - }, -]; 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 ( + + ); +} 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 ( + + ); +} 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 ( +
+
+
+ +
{sidebar}
+
+ {serverConfig.demoMode && } +
+ {mobileSidebar} + +
+ {modal} +
{children}
+
+
+
+ ); +} 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; +} -- cgit v1.2.3-70-g09d2