"use client"; import React, { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import Link from "next/link"; import Header from "@/components/Header"; import SlidingGallery from "@/components/SlidingGallery"; import BackgroundWrapper from "@/components/BackgroundWrapper"; import DestructibleAlert from "@/components/DestructibleAlert"; import { ChevronRight } from "lucide-react"; // Using Lucide React for icons import styles from "@/css/Home.module.css"; const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/api"; const page = () => { const profileImg = "/images/static/avatar.jpg"; const router = useRouter(); const [boardData, setBoardData] = useState([]); const [boardError, setBoardError] = useState(null); const performanceData = [ { label: "Mock Test", progress: 20 }, { label: "Topic Test", progress: 70 }, { label: "Subject Test", progress: 50 }, ]; const progressData = [ { label: "Physics", progress: 25 }, { label: "Chemistry", progress: 57 }, ]; // Fetch function for leaderboard data useEffect(() => { let isMounted = true; async function fetchBoardData() { try { const response = await fetch(`${API_URL}/leaderboard`); if (!response.ok) { throw new Error("Failed to fetch leaderboard data"); } const data = await response.json(); if (isMounted) setBoardData(data); } catch (error) { if (isMounted) setBoardError(error.message || "An error occurred"); } } fetchBoardData(); return () => { isMounted = false; }; }, []); const getTopThree = (boardData) => { if (!boardData || boardData.length === 0) return []; return boardData .slice() .sort((a, b) => b.points - a.points) .slice(0, 3) .map((player, index) => ({ ...player, rank: index + 1, height: index === 0 ? 250 : index === 1 ? 200 : 170, })); }; return (
{/* Categories Section */}

Categories

{/* Leaderboard Section */}

Leaderboard

Top 3
{getTopThree(boardData).map((student, idx) => (
{student.rank} Avatar {student.name}
{student.points}pt
))}
{/* Performance Summary Section */}

Performance Summary

Coming soon.

{/* Progress Tracker Section */}

Progress Tracker

Coming soon.

{/* Daily Quiz Section */}

Daily Quiz

Coming soon.

{/* Live Exams Section */}

Live Exams

Coming soon.

); }; export default page;