|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Paintbrush } from "lucide-react"; |
| 4 | +import { useRouter } from "next/navigation"; |
| 5 | +import * as React from "react"; |
| 6 | +import ThemeSelector from "@/components/ThemeSelector"; |
| 7 | +import { |
| 8 | + Breadcrumb, |
| 9 | + BreadcrumbItem, |
| 10 | + BreadcrumbLink, |
| 11 | + BreadcrumbList, |
| 12 | + BreadcrumbPage, |
| 13 | + BreadcrumbSeparator, |
| 14 | +} from "@/components/ui/breadcrumb"; |
| 15 | +import { |
| 16 | + Dialog, |
| 17 | + DialogContent, |
| 18 | + DialogDescription, |
| 19 | + DialogTitle, |
| 20 | +} from "@/components/ui/dialog"; |
| 21 | +import { |
| 22 | + Sidebar, |
| 23 | + SidebarContent, |
| 24 | + SidebarGroup, |
| 25 | + SidebarGroupContent, |
| 26 | + SidebarHeader, |
| 27 | + SidebarMenu, |
| 28 | + SidebarMenuButton, |
| 29 | + SidebarMenuItem, |
| 30 | + SidebarProvider, |
| 31 | +} from "@/components/ui/sidebar"; |
| 32 | + |
| 33 | +const settingsNav = [{ name: "Appearance", icon: Paintbrush }]; |
| 34 | + |
| 35 | +export function SettingsDialog() { |
| 36 | + const [open, setOpen] = React.useState(false); |
| 37 | + const [activeSection, setActiveSection] = React.useState("Appearance"); |
| 38 | + const router = useRouter(); |
| 39 | + |
| 40 | + React.useEffect(() => { |
| 41 | + const handleHashChange = () => { |
| 42 | + setOpen(window.location.hash === "#settings"); |
| 43 | + }; |
| 44 | + |
| 45 | + handleHashChange(); |
| 46 | + |
| 47 | + window.addEventListener("hashchange", handleHashChange); |
| 48 | + |
| 49 | + return () => { |
| 50 | + window.removeEventListener("hashchange", handleHashChange); |
| 51 | + }; |
| 52 | + }, []); |
| 53 | + |
| 54 | + const handleOpenChange = (newOpen: boolean) => { |
| 55 | + setOpen(newOpen); |
| 56 | + if (!newOpen) { |
| 57 | + if (window.location.hash === "#settings") { |
| 58 | + router.push(window.location.pathname + window.location.search); |
| 59 | + } |
| 60 | + } |
| 61 | + }; |
| 62 | + |
| 63 | + return ( |
| 64 | + <Dialog open={open} onOpenChange={handleOpenChange}> |
| 65 | + <DialogContent className="overflow-hidden p-0 md:max-w-[700px] lg:max-w-[800px] max-h-[600px]"> |
| 66 | + <DialogTitle className="sr-only">Settings</DialogTitle> |
| 67 | + <DialogDescription className="sr-only"> |
| 68 | + Customize your application settings |
| 69 | + </DialogDescription> |
| 70 | + <SidebarProvider className="items-start"> |
| 71 | + <Sidebar collapsible="none" className="hidden md:flex border-r"> |
| 72 | + <SidebarHeader> |
| 73 | + <h2 className="text-lg font-semibold px-2">Settings</h2> |
| 74 | + </SidebarHeader> |
| 75 | + <SidebarContent> |
| 76 | + <SidebarGroup> |
| 77 | + <SidebarGroupContent> |
| 78 | + <SidebarMenu> |
| 79 | + {settingsNav.map((item) => ( |
| 80 | + <SidebarMenuItem key={item.name}> |
| 81 | + <SidebarMenuButton |
| 82 | + onClick={() => setActiveSection(item.name)} |
| 83 | + isActive={item.name === activeSection} |
| 84 | + > |
| 85 | + <item.icon /> |
| 86 | + <span>{item.name}</span> |
| 87 | + </SidebarMenuButton> |
| 88 | + </SidebarMenuItem> |
| 89 | + ))} |
| 90 | + </SidebarMenu> |
| 91 | + </SidebarGroupContent> |
| 92 | + </SidebarGroup> |
| 93 | + </SidebarContent> |
| 94 | + </Sidebar> |
| 95 | + <main className="flex flex-1 flex-col overflow-hidden"> |
| 96 | + <header className="flex h-16 shrink-0 items-center gap-2 border-b px-6"> |
| 97 | + <Breadcrumb> |
| 98 | + <BreadcrumbList> |
| 99 | + <BreadcrumbItem> |
| 100 | + <BreadcrumbLink href="#settings">Settings</BreadcrumbLink> |
| 101 | + </BreadcrumbItem> |
| 102 | + <BreadcrumbSeparator /> |
| 103 | + <BreadcrumbItem> |
| 104 | + <BreadcrumbPage>{activeSection}</BreadcrumbPage> |
| 105 | + </BreadcrumbItem> |
| 106 | + </BreadcrumbList> |
| 107 | + </Breadcrumb> |
| 108 | + </header> |
| 109 | + <div className="flex flex-1 flex-col gap-6 overflow-y-auto p-6"> |
| 110 | + {activeSection === "Appearance" && ( |
| 111 | + <div> |
| 112 | + <h2 className="text-lg font-medium mb-4">Appearance</h2> |
| 113 | + <ThemeSelector /> |
| 114 | + </div> |
| 115 | + )} |
| 116 | + </div> |
| 117 | + </main> |
| 118 | + </SidebarProvider> |
| 119 | + </DialogContent> |
| 120 | + </Dialog> |
| 121 | + ); |
| 122 | +} |
0 commit comments