-
Notifications
You must be signed in to change notification settings - Fork 0
feat: sidebar #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: sidebar #39
Changes from all commits
3ac11aa
aaed723
da6760c
1d485af
ef68226
c8ad53a
24828cd
1a5d70d
fba8bd3
73acf8f
6099b46
ec3c62e
454e9db
fc32ad7
51e171e
6362566
075f156
21c64c5
e9fd9e7
60d3617
2510a36
f6e4fa3
fd76b34
d7388b5
ba20b0b
57d3a23
5003e80
0b1596c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Skeleton } from "@/components/ui/skeleton" | ||
| import { NewPasskeyButton } from "./passkey-button" | ||
|
|
||
| export default function Loading() { | ||
| return ( | ||
| <main className="container"> | ||
| <h2 className="text-accent-foreground mb-4 text-3xl font-bold">Account</h2> | ||
| <div className="flex gap-4 mb-12"> | ||
| <Skeleton className="h-32 w-32 rounded-full" /> | ||
|
|
||
| <div className="flex flex-col gap-2"> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-accent-foreground/70">Name:</span> | ||
| <Skeleton className="w-40 h-5" /> | ||
| </div> | ||
|
|
||
| <div className="flex items-center gap-2"> | ||
| <span className="text-accent-foreground/70">Email:</span> | ||
| <Skeleton className="w-70 h-5" /> | ||
| </div> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-accent-foreground/70">Telegram:</span> | ||
| <Skeleton className="w-60 h-5" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div className="flex flex-col gap-4 justify-start items-start"> | ||
| <h3>Passkeys</h3> | ||
| <Skeleton className="w-full h-10" /> | ||
| <NewPasskeyButton /> | ||
| </div> | ||
| </main> | ||
| ) | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| "use client" | ||
| import { usePathname } from "next/navigation" | ||
| import { Fragment, useMemo } from "react" | ||
| import { NAV_MAP } from "@/components/dashboard-sidebar/data" | ||
| import { | ||
| BreadcrumbItem as BreadcrumbItemComponent, | ||
| BreadcrumbLink, | ||
| BreadcrumbList, | ||
| BreadcrumbPage, | ||
| Breadcrumb as BreadcrumbRoot, | ||
| BreadcrumbSeparator, | ||
| } from "@/components/ui/breadcrumb" | ||
|
|
||
| export type BreadcrumbItem = { | ||
| title: string | ||
| url?: string | ||
| } | ||
|
|
||
| export function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) { | ||
| const pathname = usePathname() | ||
| const items = useMemo(() => getBreadcrumbs(NAV_MAP, pathname), [pathname]) | ||
|
|
||
| return ( | ||
| <BreadcrumbRoot className={className} {...props}> | ||
| <BreadcrumbList> | ||
| {items.map((item, i) => ( | ||
| <Fragment key={`breadcrumb-item-${i}`}> | ||
| <BreadcrumbItemComponent className="hidden md:block"> | ||
| {i === items.length - 1 ? ( | ||
| <BreadcrumbPage>{item.title}</BreadcrumbPage> | ||
| ) : item.url ? ( | ||
| <BreadcrumbLink href={item.url}>{item.title}</BreadcrumbLink> | ||
| ) : ( | ||
| item.title | ||
| )} | ||
| </BreadcrumbItemComponent> | ||
| {i < items.length - 1 && <BreadcrumbSeparator className="hidden md:block" />} | ||
| </Fragment> | ||
| ))} | ||
| </BreadcrumbList> | ||
| </BreadcrumbRoot> | ||
| ) | ||
| } | ||
|
|
||
| function getBreadcrumbs(navMap: Map<string, string>, pathname: string): BreadcrumbItem[] { | ||
| const segments = pathname.split("/").filter(Boolean) | ||
| const breadcrumbs: BreadcrumbItem[] = [] | ||
|
|
||
| let currentPath = "" | ||
| let i = 0 | ||
|
|
||
| for (const segment of segments) { | ||
| currentPath += `/${segment}` | ||
| let title = navMap.get(currentPath) | ||
| if (!title) { | ||
| if (isUUIDorId(segment)) { | ||
| title = "Details" | ||
| } else { | ||
| title = segment.charAt(0).toUpperCase() + segment.slice(1) | ||
| } | ||
| } | ||
|
|
||
| // note: at the moment we do not plan to make category pages. | ||
| // If such pages are made in the future, this logic can be removed | ||
| breadcrumbs.push({ title, url: i !== 1 ? currentPath : undefined }) | ||
| i++ | ||
| } | ||
|
|
||
| return breadcrumbs | ||
| } | ||
|
|
||
| function isUUIDorId(segment: string) { | ||
| return !Number.isNaN(Number(segment)) || segment.length > 20 // Regex custom a seconda dei tuoi ID | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { cookies } from "next/headers" | ||
| import { DashboardSidebar } from "@/components/dashboard-sidebar" | ||
| import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar" | ||
| import { COOKIES } from "@/constants" | ||
| import { Breadcrumb } from "./breadcrumb" | ||
|
|
||
| function parseCookie(cookie: string) { | ||
| try { | ||
| const parsed = JSON.parse(cookie) | ||
| return parsed | ||
| } catch (_e) { | ||
| return {} | ||
| } | ||
| } | ||
|
|
||
| export default async function AdminLayout({ children }: { children: React.ReactNode }) { | ||
| const cookieStore = await cookies() | ||
| const cookie = cookieStore.get(COOKIES.SIDEBAR_CATEGORY_STATE)?.value | ||
| const DSCategoryState = cookie ? parseCookie(cookie) : {} | ||
|
|
||
| return ( | ||
| <SidebarProvider | ||
| style={ | ||
| { | ||
| "--sidebar-width": "19rem", | ||
| } as React.CSSProperties | ||
| } | ||
| > | ||
|
Comment on lines
+17
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qui viene riletto e settato sidebar_category_state, quindi lo stato delle sezioni, ma la sidebar salva anche lo stato expanded o collapsed in sidebar_state, che peró non viene letto qui, quindi la sidebar userà sempre il default open dopo un refresh. Si potrebbe leggere anche quel cookie e passarlo alla sidebar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ho visto che sidebar_category_state è centralizzato, mentre sidebar_state è hardcoded dentro SidebarProvider. Forse conviene uniformarli e aggiungere anche sidebar_state a cookies in constants |
||
| <DashboardSidebar categoryState={DSCategoryState} /> | ||
| <SidebarInset className="px-4"> | ||
| <header className="flex h-16 shrink-0 relative items-center justify-between gap-2 border-b mb-8"> | ||
| <SidebarTrigger className="-ml-1" size="icon" /> | ||
| <Breadcrumb className="absolute left-1/2 -translate-x-1/2" /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qesto Forse si potrebbe semplificare così: <header className="relative mb-8 flex h-16 shrink-0 items-center border-b">
<SidebarTrigger className="-ml-1" size="icon" />
<Breadcrumb className="absolute left-1/2 -translate-x-1/2" />
</header> |
||
| <div></div> | ||
| </header> | ||
| {children} | ||
| </SidebarInset> | ||
| </SidebarProvider> | ||
| ) | ||
| } | ||
| // <Separator orientation="vertical" className="mr-2 data-vertical:h-4 data-vertical:self-auto" /> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,16 @@ | ||
| import Image from "next/image" | ||
| import Link from "next/link" | ||
| import azureSvg from "@/assets/svg/azure.svg" | ||
| import telegramSvg from "@/assets/svg/telegram.svg" | ||
| import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" | ||
| import { getServerSession } from "@/server/auth" | ||
| import { InfoIcon } from "lucide-react" | ||
| import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" | ||
| import { CompleteProfile } from "./complete-profile" | ||
|
|
||
| export default async function AdminHome() { | ||
| const { data: session } = await getServerSession() | ||
| export default function AdminHome() { | ||
| return ( | ||
| session && ( | ||
| <div className="container py-8 px-2"> | ||
| <CompleteProfile user={session.user} /> | ||
| <h2 className="text-accent-foreground mb-4 text-3xl font-bold">Home</h2> | ||
|
|
||
| <div className="gap-4 flex justify-start flex-wrap items-center"> | ||
| <Link href="/dashboard/azure"> | ||
| <Card className="w-90 hover:bg-accent transition-colors"> | ||
| <CardHeader> | ||
| <CardTitle className="flex gap-2"> | ||
| <Image alt="azure logo" src={azureSvg} className="size-5" /> | ||
| Azure | ||
| </CardTitle> | ||
| <CardDescription>Manage Azure related things</CardDescription> | ||
| </CardHeader> | ||
| </Card> | ||
| </Link> | ||
|
|
||
| <Link href="/dashboard/telegram"> | ||
| <Card className="w-90 hover:bg-accent transition-colors"> | ||
| <CardHeader> | ||
| <CardTitle className="flex gap-2"> | ||
| <Image alt="telegram logo" src={telegramSvg} className="size-5" /> | ||
| Telegram | ||
| </CardTitle> | ||
| <CardDescription>Manage Telegram related things</CardDescription> | ||
| </CardHeader> | ||
| </Card> | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| ) | ||
| <div className="container"> | ||
| <CompleteProfile /> | ||
| <Alert variant="info"> | ||
| <InfoIcon /> | ||
| <AlertTitle>Page under construction</AlertTitle> | ||
| <AlertDescription>Use the sidebar to access the sections</AlertDescription> | ||
| </Alert> | ||
| </div> | ||
| ) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.