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/sidebar-mobile #92

Closed
wants to merge 4 commits into from
Closed
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
18 changes: 13 additions & 5 deletions app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppSidebar } from "@/components/dashboardComponents/AppSidebar";
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
import MobileSidear from "@/components/dashboardComponents/MobileSidebar";
import type { Metadata } from "next";

export const metadata: Metadata = {
Expand All @@ -12,10 +12,18 @@ 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 md:p-3 h-full">
<div className="md:block hidden">
<AppSidebar />
</div>
<div className="md:hidden block fixed top-1 left-1 w-full z-50">
<MobileSidear/>
</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
Loading