CodeHarborHub -
Developer workspace -
- Local time -
-- {now.toLocaleTimeString([], { - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - })} +
+ Workspace / {title}
+
{displayName}
-- Demo member +
+ Workspace member
diff --git a/src/components/auth/DashboardLayout.tsx b/src/components/auth/DashboardLayout.tsx index 615c9c69e..f10453ddc 100644 --- a/src/components/auth/DashboardLayout.tsx +++ b/src/components/auth/DashboardLayout.tsx @@ -1,9 +1,27 @@ import React, { useEffect, useState } from "react"; -// @ts-ignore import Layout from "@theme/Layout"; -// @ts-ignore import Link from "@docusaurus/Link"; -// @ts-ignore +import { useLocation } from "@docusaurus/router"; +import { + ArrowUpRight, + BookOpen, + Bookmark, + ChevronRight, + Code2, + ExternalLink, + FolderKanban, + LayoutDashboard, + LogOut, + Menu, + Moon, + Settings, + ShieldCheck, + Sparkles, + Sun, + UserRound, + X, +} from "lucide-react"; + import { useAuth } from "@site/src/context/AuthContext"; type DashboardLayoutProps = { @@ -12,11 +30,53 @@ type DashboardLayoutProps = { children: React.ReactNode; }; -const navigation = [ - { label: "Overview", href: "/dashboard", icon: "⌂" }, - { label: "My profile", href: "/profile", icon: "◎" }, - { label: "Account", href: "/settings/account", icon: "⚙" }, - { label: "Security", href: "/settings/security", icon: "◇" }, +const workspaceNavigation = [ + { + label: "Overview", + href: "/dashboard", + icon: LayoutDashboard, + }, + { + label: "My profile", + href: "/profile", + icon: UserRound, + }, + { + label: "Bookmarks", + href: "/bookmarks", + icon: Bookmark, + }, +]; + +const accountNavigation = [ + { + label: "Account settings", + href: "/settings/account", + icon: Settings, + }, + { + label: "Security", + href: "/settings/security", + icon: ShieldCheck, + }, +]; + +const exploreNavigation = [ + { + label: "Tutorials", + href: "/tutorials/", + icon: BookOpen, + }, + { + label: "Learning paths", + href: "/roadmap", + icon: Code2, + }, + { + label: "Projects", + href: "/projects", + icon: FolderKanban, + }, ]; function getInitials(name?: string) { @@ -30,36 +90,70 @@ function getInitials(name?: string) { .join(""); } -function getGreeting(hour: number) { +function getGreeting() { + const hour = new Date().getHours(); + if (hour < 12) return "Good morning"; if (hour < 17) return "Good afternoon"; + return "Good evening"; } +function normalizePath(path: string) { + return path.replace(/\/+$/, "") || "/"; +} + +function isRouteActive(currentPath: string, href: string) { + const current = normalizePath(currentPath); + const target = normalizePath(href); + + return current === target || current.startsWith(`${target}/`); +} + export default function DashboardLayout({ title, eyebrow = "CODEHARBORHUB WORKSPACE", children, }: DashboardLayoutProps) { const { user, logout } = useAuth(); + const location = useLocation(); - const [now, setNow] = useState(() => new Date()); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [signingOut, setSigningOut] = useState(false); + const displayName = user?.name?.trim() || "Developer"; + const initials = getInitials(user?.name); + const greeting = getGreeting(); + + const currentDate = new Date().toLocaleDateString([], { + weekday: "long", + day: "numeric", + month: "long", + year: "numeric", + }); + + // Close the mobile drawer when navigating or pressing Escape. useEffect(() => { - const timer = window.setInterval(() => { - setNow(new Date()); - }, 1000); + setMobileMenuOpen(false); + }, [location.pathname]); - return () => window.clearInterval(timer); - }, []); + useEffect(() => { + if (!mobileMenuOpen) return; - const displayName = user?.name?.trim() || "Developer"; - const initials = getInitials(user?.name); - const greeting = getGreeting(now.getHours()); + function handleKeyDown(event: KeyboardEvent) { + if (event.key === "Escape") { + setMobileMenuOpen(false); + } + } + + window.addEventListener("keydown", handleKeyDown); - function signOut() { + return () => { + window.removeEventListener("keydown", handleKeyDown); + }; + }, [mobileMenuOpen]); + + function handleSignOut() { if (signingOut) return; setSigningOut(true); @@ -72,262 +166,320 @@ export default function DashboardLayout({ } } + const renderNavigation = ( + items: typeof workspaceNavigation, + label: string + ) => ( +
+ {label} +
+ + {items.map((item) => { + const active = isRouteActive( + location.pathname, + item.href + ); + + const Icon = item.icon; + + return ( + ++ CodeHarborHub +
+ ++ Developer workspace +
++ Keep learning +
+ ++ Explore tutorials, build projects, and grow your developer skills. +
+ + + Explore tutorials ++ Your session is stored locally in this browser. +
+CodeHarborHub -
Developer workspace -
- Local time -
-- {now.toLocaleTimeString([], { - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - })} +
+ Workspace / {title}
+
{displayName}
-- Demo member +
+ Workspace member