Skip to content
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

Feature/added-Sidebar #84

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AppSidebar } from "@/components/dashboardComponents/AppSidebar";
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "LeetCode Journal",
description: "Track your LeetCode progress and boost your coding skills",
};

export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<SidebarProvider>
<AppSidebar />
<main className="w-full">{children}</main>
</SidebarProvider>
);
}
124 changes: 43 additions & 81 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,59 @@
"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuthStore } from "@/store/AuthStore/useAuthStore";
import Navbar from "@/components/header";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import { useAuthStore } from "@/store/AuthStore/useAuthStore";
import DashboardNavbar from "@/components/dashboardComponents/DashboardNavbar";
import { DashboardContentSkeleton } from "@/components/dashboardComponents/DashboardContentSkeleton";

function DashboardContent({ authUser }: any) {
return (
<main className="container mx-auto p-4 space-y-6">
<h1 className="text-3xl font-bold">Welcome, {authUser?.fullName}</h1>
<Card>
<CardHeader>
<CardTitle>Your Profile</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<p>
<span className="font-medium">LeetCode Username:</span>{" "}
{authUser?.leetcodeUsername}
</p>
<p>
<span className="font-medium">Gender:</span> {authUser?.gender}
</p>
</CardContent>
</Card>

<Card>
<CardHeader>
<CardTitle>LeetCode Stats</CardTitle>
</CardHeader>
<CardContent>
<p className="text-muted-foreground">
LeetCode stats are coming soon!
</p>
</CardContent>
</Card>
</main>
);
}

export default function Dashboard() {
const router = useRouter();
const { authUser, fetchAuthUser, authUserLoading } = useAuthStore();

useEffect(() => {
fetchAuthUser();
}, [fetchAuthUser]);

useEffect(() => {
if (!authUserLoading && !authUser) {
router.push("/auth/signin");
}
}, [authUserLoading, authUser, router]);

if (authUserLoading) {
return <DashboardSkeleton />;
}

if (!authUser) {
return null;
}

return (
<div className="min-h-screen">
<Navbar userId={authUser.id} />
<main className="container mx-auto p-4 space-y-6">
<h1 className="text-3xl font-bold">Welcome, {authUser.fullName}</h1>

<Card>
<CardHeader>
<CardTitle>Your Profile</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
<p>
<span className="font-medium">LeetCode Username:</span>{" "}
{authUser.leetcodeUsername}
</p>
<p>
<span className="font-medium">Gender:</span> {authUser.gender}
</p>
</CardContent>
</Card>

<Card>
<CardHeader>
<CardTitle>LeetCode Stats</CardTitle>
</CardHeader>
<CardContent>
{/* LeetCode stats component will go here */}
<p className="text-muted-foreground">
LeetCode stats are coming soon!
</p>
</CardContent>
</Card>
</main>
</div>
);
}

function DashboardSkeleton() {
return (
<div className="min-h-screen">
{/* <Navbar userId={} /> */}
<main className="container mx-auto p-4 space-y-6">
<Skeleton className="h-10 w-[250px]" />

<Card>
<CardHeader>
<Skeleton className="h-7 w-[100px]" />
</CardHeader>
<CardContent className="space-y-2">
<Skeleton className="h-5 w-full" />
<Skeleton className="h-5 w-full" />
</CardContent>
</Card>

<Card>
<CardHeader>
<Skeleton className="h-7 w-[120px]" />
</CardHeader>
<CardContent>
<Skeleton className="h-20 w-full" />
</CardContent>
</Card>
</main>
<div className="min-h-screen w-full">
<DashboardNavbar isLoading={authUserLoading} userId={authUser?.id} />
{authUserLoading ? (
<DashboardContentSkeleton />
) : (
<DashboardContent authUser={authUser} />
)}
</div>
);
}
3 changes: 1 addition & 2 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@
body {
@apply bg-background text-foreground;
}
}

}
150 changes: 150 additions & 0 deletions components/dashboardComponents/AppSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
"use client";

import {
Calendar,
ChevronUp,
Search,
Settings,
User,
User2,
} from "lucide-react";
import { useState } from "react";

import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarTrigger,
} from "@/components/ui/sidebar";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { cn } from "@/lib/utils";
import { signout } from "@/app/actions/action";
import Dashboard from "@/app/dashboard/page";

// Menu items.
const items = [
{
title: "profile",
url: "#",
icon: User,
},
{
title: "Problems",
url: "#",
icon: Dashboard,
},
{
title: "Calendar",
url: "#",
icon: Calendar,
},
{
title: "Search",
url: "#",
icon: Search,
},
{
title: "Settings",
url: "#",
icon: Settings,
},
];

export function AppSidebar() {
const [isCollapsed, setIsCollapsed] = useState(false);
return (
<Sidebar collapsible="icon" className="border-r">
<SidebarTrigger
onClick={() => setIsCollapsed(!isCollapsed)}
className="absolute right-[-12px] top-4 z-20 flex h-6 w-6 items-center justify-center rounded-full border bg-background text-foreground shadow-sm"
>
{isCollapsed ? "→" : "←"}
</SidebarTrigger>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel className="text-lg font-semibold">
Leetcode Journal
</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{items.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild className="group relative">
<a
href={item.url}
className="flex items-center gap-3 rounded-md p-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground"
>
<item.icon className="h-5 w-5" />
<span
className={cn(
"transition-opacity",
isCollapsed ? "opacity-0" : "opacity-100"
)}
>
{item.title}
</span>
{isCollapsed && (
<span className="absolute left-full ml-2 hidden rounded-md bg-accent px-2 py-1 text-xs group-hover:block">
{item.title}
</span>
)}
</a>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter className="border-t">
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<SidebarMenuButton className="w-full">
<User2 className="h-5 w-5" />
<span
className={cn(
"ml-2 transition-opacity",
isCollapsed ? "opacity-0" : "opacity-100"
)}
>
Username
</span>
<ChevronUp
className={cn(
"ml-auto h-4 w-4 transition-transform",
isCollapsed ? "opacity-0" : "opacity-100"
)}
/>
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent side="top" align="start" className="w-56">
<DropdownMenuItem>
<span>Account</span>
</DropdownMenuItem>
<DropdownMenuItem>
<span>Billing</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={signout}>
<span className="text-red-500">Sign out</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
</Sidebar>
);
}
29 changes: 29 additions & 0 deletions components/dashboardComponents/DashboardContentSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Card, CardContent, CardHeader } from "../ui/card";
import { Skeleton } from "../ui/skeleton";

export function DashboardContentSkeleton() {
return (
<main className="container mx-auto p-4 space-y-6">
<Skeleton className="h-10 w-[250px]" />

<Card>
<CardHeader>
<Skeleton className="h-7 w-[100px]" />
</CardHeader>
<CardContent className="space-y-2">
<Skeleton className="h-5 w-full" />
<Skeleton className="h-5 w-full" />
</CardContent>
</Card>

<Card>
<CardHeader>
<Skeleton className="h-7 w-[120px]" />
</CardHeader>
<CardContent>
<Skeleton className="h-20 w-full" />
</CardContent>
</Card>
</main>
);
}
Loading
Loading