Skip to content

Commit

Permalink
Feature/Sidebar (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanuchaudhary authored Jan 15, 2025
1 parent a0fba6e commit 2462b0c
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 238 deletions.
14 changes: 9 additions & 5 deletions app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AppSidebar } from "@/components/dashboardComponents/AppSidebar";
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import type { Metadata } from "next";

export const metadata: Metadata = {
Expand All @@ -12,10 +11,15 @@ export default function RootLayout({
}: {
children: React.ReactNode;
}) {

return (
<SidebarProvider>
<AppSidebar />
<main className="w-full">{children}</main>
</SidebarProvider>
<body>
<main className="flex min-h-screen overflow-hidden md:gap-3 gap-1 md:p-3 p-1 h-full">
<div>
<AppSidebar />
</div>
<div className="w-full dark:bg-neutral-900 md:p-6 p-3 bg-neutral-200 md:rounded-xl rounded-sm">{children}</div>
</main>
</body>
);
}
100 changes: 3 additions & 97 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,103 +1,9 @@
"use client";

import { useEffect, useState } from "react";
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";
import { Bar } from "react-chartjs-2";
import { Chart as ChartJS, CategoryScale, LinearScale, BarElement } from "chart.js";

ChartJS.register(CategoryScale, LinearScale, BarElement);

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>
);
}
import React from "react";

export default function Dashboard() {
const { authUser, fetchAuthUser, authUserLoading } = useAuthStore();
const [leetcodeStats, setLeetcodeStats] = useState<any>(null);

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

// Fetch and store stats once we have the user
useEffect(() => {
if (authUser?.leetcodeUsername && authUser?.id) {
const fetchStats = async () => {
const res = await fetch(
`/api/leetcode?username=${authUser.leetcodeUsername}&id=${authUser.id}`,
{ method: "POST" }
);
if (res.ok) {
const data = await res.json();
setLeetcodeStats(data.stats);
}
};
fetchStats();
}
}, [authUser]);

// Simple bar chart config
const chartData = {
labels: ["Easy", "Medium", "Hard"],
datasets: [
{
label: "Solved",
data: leetcodeStats?.submitStats.acSubmissionNum?.map((i: any) => i.count) || [0, 0, 0],
backgroundColor: ["#4ade80", "#fbbf24", "#ef4444"],
},
],
};

return (
<div className="min-h-screen w-full">
{authUserLoading ? (
<DashboardContentSkeleton />
) : (
<>
<DashboardContent authUser={authUser} />
{leetcodeStats && (
<div className="container mx-auto mt-6">
<h2 className="text-xl font-semibold mb-4">Your LeetCode Progress</h2>
<div className="max-w-xl">
<Bar data={chartData} />
</div>
</div>
)}
</>
)}
<div className="flex flex-col items-center justify-center h-full">
<h1 className="text-6xl font-bold">This is the dashboard</h1>
</div>
);
}
101 changes: 89 additions & 12 deletions app/dashboard/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,89 @@
import React from 'react';

const ProfilePage: React.FC = () => {
return (
<div>
<h1>Profile Page</h1>
<p>Welcome to your profile!</p>
</div>
);
};

export default ProfilePage;
"use client";

import { useEffect, useState } from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useAuthStore } from "@/store/AuthStore/useAuthStore";
import { DashboardContentSkeleton } from "@/components/dashboardComponents/DashboardContentSkeleton";
import { Bar } from "react-chartjs-2";
import { Chart as ChartJS, CategoryScale, LinearScale, BarElement } from "chart.js";

ChartJS.register(CategoryScale, LinearScale, BarElement);

function DashboardContent({ authUser }: any) {
return (
<main className="container mx-auto 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>
</main>
);
}

export default function Dashboard() {
const { authUser, fetchAuthUser, authUserLoading } = useAuthStore();
const [leetcodeStats, setLeetcodeStats] = useState<any>(null);

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

useEffect(() => {
if (authUser?.leetcodeUsername && authUser?.id) {
const fetchStats = async () => {
const res = await fetch(
`/api/leetcode?username=${authUser.leetcodeUsername}&id=${authUser.id}`,
{ method: "POST" }
);
if (res.ok) {
const data = await res.json();
setLeetcodeStats(data.stats);
}
};
fetchStats();
}
}, [authUser]);

// Simple bar chart config
const chartData = {
labels: ["Easy", "Medium", "Hard"],
datasets: [
{
label: "Solved",
data: leetcodeStats?.submitStats.acSubmissionNum?.map((i: any) => i.count) || [0, 0, 0],
backgroundColor: ["#4ade80", "#fbbf24", "#ef4444"],
},
],
};

return (
<div className="w-full">
{authUserLoading ? (
<DashboardContentSkeleton />
) : (
<>
<DashboardContent authUser={authUser} />
{leetcodeStats && (
<div className="container mx-auto bg-neutral-800 rounded-lg p-3 mt-6">
<h2 className="text-xl font-semibold mb-4">Your LeetCode Progress</h2>
<div className="max-w-xl">
<Bar data={chartData} />
</div>
</div>
)}
</>
)}
</div>
);
}
Loading

0 comments on commit 2462b0c

Please sign in to comment.