From 1f768be0485bbfa6b542dd24183fe8389acb9355 Mon Sep 17 00:00:00 2001 From: Md Saban <45597394+mdsaban@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:37:20 +0530 Subject: feature(web): Introduce a new sticky navbar. Fixes 520 (#515) * ui: add global header * fix: design fixes * fix: tests * fix navbar background, hide y scrollbar and change sidebar footer to show version --------- Co-authored-by: MohamedBassem --- apps/web/app/dashboard/archive/page.tsx | 16 ++--- apps/web/app/dashboard/bookmarks/page.tsx | 10 +-- apps/web/app/dashboard/favourites/page.tsx | 2 - apps/web/app/dashboard/layout.tsx | 30 +++++---- apps/web/app/dashboard/search/page.tsx | 11 +--- apps/web/components/dashboard/GlobalActions.tsx | 2 +- apps/web/components/dashboard/header/Header.tsx | 71 ++++++++++++++++++++ .../components/dashboard/header/ProfileOptions.tsx | 75 ++++++++++++++++++++++ apps/web/components/dashboard/lists/ListHeader.tsx | 2 - apps/web/components/dashboard/sidebar/AllLists.tsx | 6 -- .../components/dashboard/sidebar/ModileSidebar.tsx | 4 +- apps/web/components/dashboard/sidebar/Sidebar.tsx | 34 ++-------- .../dashboard/sidebar/SidebarProfileOptions.tsx | 68 -------------------- 13 files changed, 180 insertions(+), 151 deletions(-) create mode 100644 apps/web/components/dashboard/header/Header.tsx create mode 100644 apps/web/components/dashboard/header/ProfileOptions.tsx delete mode 100644 apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx (limited to 'apps/web') diff --git a/apps/web/app/dashboard/archive/page.tsx b/apps/web/app/dashboard/archive/page.tsx index 5c25d8cc..becb6a58 100644 --- a/apps/web/app/dashboard/archive/page.tsx +++ b/apps/web/app/dashboard/archive/page.tsx @@ -1,19 +1,13 @@ import Bookmarks from "@/components/dashboard/bookmarks/Bookmarks"; -import GlobalActions from "@/components/dashboard/GlobalActions"; import InfoTooltip from "@/components/ui/info-tooltip"; function header() { return ( -
-
-

🗄️ Archive

- -

Archived bookmarks won't appear in the homepage

-
-
-
- -
+
+

🗄️ Archive

+ +

Archived bookmarks won't appear in the homepage

+
); } diff --git a/apps/web/app/dashboard/bookmarks/page.tsx b/apps/web/app/dashboard/bookmarks/page.tsx index c02e6b85..a7b22fef 100644 --- a/apps/web/app/dashboard/bookmarks/page.tsx +++ b/apps/web/app/dashboard/bookmarks/page.tsx @@ -1,18 +1,10 @@ import React from "react"; import Bookmarks from "@/components/dashboard/bookmarks/Bookmarks"; -import GlobalActions from "@/components/dashboard/GlobalActions"; -import { SearchInput } from "@/components/dashboard/search/SearchInput"; export default async function BookmarksPage() { return (
-
- - -
-
- -
+
); } diff --git a/apps/web/app/dashboard/favourites/page.tsx b/apps/web/app/dashboard/favourites/page.tsx index e5959af3..be20bd2f 100644 --- a/apps/web/app/dashboard/favourites/page.tsx +++ b/apps/web/app/dashboard/favourites/page.tsx @@ -1,5 +1,4 @@ import Bookmarks from "@/components/dashboard/bookmarks/Bookmarks"; -import GlobalActions from "@/components/dashboard/GlobalActions"; export default async function FavouritesBookmarkPage() { return ( @@ -7,7 +6,6 @@ export default async function FavouritesBookmarkPage() { header={

⭐️ Favourites

-
} query={{ favourited: true }} diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx index b0ac1f7d..cbd51245 100644 --- a/apps/web/app/dashboard/layout.tsx +++ b/apps/web/app/dashboard/layout.tsx @@ -1,3 +1,4 @@ +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"; @@ -14,20 +15,23 @@ export default async function Dashboard({ modal: React.ReactNode; }>) { return ( -
- -
- -
-
- {serverConfig.demoMode && } -
- - +
+
+
+ +
+
- {modal} -
{children}
-
+
+ {serverConfig.demoMode && } +
+ + +
+ {modal} +
{children}
+
+
); } diff --git a/apps/web/app/dashboard/search/page.tsx b/apps/web/app/dashboard/search/page.tsx index e7405c85..a239550c 100644 --- a/apps/web/app/dashboard/search/page.tsx +++ b/apps/web/app/dashboard/search/page.tsx @@ -1,24 +1,15 @@ "use client"; -import { Suspense, useRef } from "react"; +import { Suspense } from "react"; import BookmarksGrid from "@/components/dashboard/bookmarks/BookmarksGrid"; -import GlobalActions from "@/components/dashboard/GlobalActions"; -import { SearchInput } from "@/components/dashboard/search/SearchInput"; import { FullPageSpinner } from "@/components/ui/full-page-spinner"; import { useBookmarkSearch } from "@/lib/hooks/bookmark-search"; function SearchComp() { const { data } = useBookmarkSearch(); - const inputRef: React.MutableRefObject = - useRef(null); - return (
-
- - -
{data ? ( ) : ( diff --git a/apps/web/components/dashboard/GlobalActions.tsx b/apps/web/components/dashboard/GlobalActions.tsx index e09f92a2..9c05dddf 100644 --- a/apps/web/components/dashboard/GlobalActions.tsx +++ b/apps/web/components/dashboard/GlobalActions.tsx @@ -5,7 +5,7 @@ import ChangeLayout from "@/components/dashboard/ChangeLayout"; export default function GlobalActions() { return ( -
+
diff --git a/apps/web/components/dashboard/header/Header.tsx b/apps/web/components/dashboard/header/Header.tsx new file mode 100644 index 00000000..11e3b3c3 --- /dev/null +++ b/apps/web/components/dashboard/header/Header.tsx @@ -0,0 +1,71 @@ +import React from "react"; +import Link from "next/link"; +import { redirect } from "next/navigation"; +import GlobalActions from "@/components/dashboard/GlobalActions"; +import ProfileOptions from "@/components/dashboard/header/ProfileOptions"; +import { SearchInput } from "@/components/dashboard/search/SearchInput"; +import HoarderLogo from "@/components/HoarderIcon"; +import { Button } from "@/components/ui/button"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { getServerAuthSession } from "@/server/auth"; +import { Settings, Shield } from "lucide-react"; + +export default async function Header() { + const session = await getServerAuthSession(); + if (!session) { + redirect("/"); + } + + const adminItem = + session.user.role == "admin" + ? [ + { + name: "Admin", + icon: , + path: "/dashboard/admin", + }, + ] + : []; + + const headerItems = [ + ...adminItem, + { + name: "Settings", + icon: , + path: "/dashboard/settings", + }, + ]; + + return ( +
+
+ + + +
+
+ + +
+
+ {headerItems.map((item) => ( + + + + + {item.name} + + ))} + +
+
+ ); +} diff --git a/apps/web/components/dashboard/header/ProfileOptions.tsx b/apps/web/components/dashboard/header/ProfileOptions.tsx new file mode 100644 index 00000000..df31171c --- /dev/null +++ b/apps/web/components/dashboard/header/ProfileOptions.tsx @@ -0,0 +1,75 @@ +"use client"; + +import Link from "next/link"; +import { redirect } from "next/navigation"; +import { useToggleTheme } from "@/components/theme-provider"; +import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { LogOut, Moon, Paintbrush, Sun } from "lucide-react"; +import { signOut, useSession } from "next-auth/react"; +import { useTheme } from "next-themes"; + +function DarkModeToggle() { + const { theme } = useTheme(); + + if (theme == "dark") { + return ( + <> + + Light Mode + + ); + } else { + return ( + <> + + Dark Mode + + ); + } +} + +export default function SidebarProfileOptions() { + const toggleTheme = useToggleTheme(); + const { data: session } = useSession(); + if (!session) return redirect("/"); + + return ( + + + + + + + + + Cleanups + + + + + + + signOut({ + callbackUrl: "/", + }) + } + > + + Sign Out + + + + ); +} diff --git a/apps/web/components/dashboard/lists/ListHeader.tsx b/apps/web/components/dashboard/lists/ListHeader.tsx index 1655a80b..a6780e1e 100644 --- a/apps/web/components/dashboard/lists/ListHeader.tsx +++ b/apps/web/components/dashboard/lists/ListHeader.tsx @@ -1,7 +1,6 @@ "use client"; import { useRouter } from "next/navigation"; -import GlobalActions from "@/components/dashboard/GlobalActions"; import { Button } from "@/components/ui/button"; import { MoreHorizontal } from "lucide-react"; @@ -43,7 +42,6 @@ export default function ListHeader({ -
); diff --git a/apps/web/components/dashboard/sidebar/AllLists.tsx b/apps/web/components/dashboard/sidebar/AllLists.tsx index 15bed88a..b6cadea9 100644 --- a/apps/web/components/dashboard/sidebar/AllLists.tsx +++ b/apps/web/components/dashboard/sidebar/AllLists.tsx @@ -47,12 +47,6 @@ export default function AllLists({ path={`/dashboard/favourites`} linkClassName="py-0.5" /> - 🗄️} - name="Archive" - path={`/dashboard/archive`} - linkClassName="py-0.5" - /> { } path="/dashboard/lists" /> } path="/dashboard/tags" /> } path="/dashboard/settings" /> - + ); diff --git a/apps/web/components/dashboard/sidebar/Sidebar.tsx b/apps/web/components/dashboard/sidebar/Sidebar.tsx index 84a10d2d..13260e07 100644 --- a/apps/web/components/dashboard/sidebar/Sidebar.tsx +++ b/apps/web/components/dashboard/sidebar/Sidebar.tsx @@ -1,16 +1,13 @@ -import Link from "next/link"; import { redirect } from "next/navigation"; -import HoarderLogo from "@/components/HoarderIcon"; import { Separator } from "@/components/ui/separator"; import { api } from "@/server/api/client"; import { getServerAuthSession } from "@/server/auth"; -import { Home, Search, Settings, Shield, Tag } from "lucide-react"; +import { Archive, Home, Search, Tag } from "lucide-react"; import serverConfig from "@hoarder/shared/config"; import AllLists from "./AllLists"; import SidebarItem from "./SidebarItem"; -import SidebarProfileOptions from "./SidebarProfileOptions"; export default async function Sidebar() { const session = await getServerAuthSession(); @@ -30,17 +27,6 @@ export default async function Sidebar() { ] : []; - const adminItem = - session.user.role == "admin" - ? [ - { - name: "Admin", - icon: , - path: "/dashboard/admin", - }, - ] - : []; - const menu: { name: string; icon: JSX.Element; @@ -58,19 +44,14 @@ export default async function Sidebar() { path: "/dashboard/tags", }, { - name: "Settings", - icon: , - path: "/dashboard/settings", + name: "Archive", + icon: , + path: "/dashboard/archive", }, - ...adminItem, ]; return ( -