"use client"; import React, { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import Header from "@/components/Header"; import SlidingGallery from "@/components/SlidingGallery"; import BackgroundWrapper from "@/components/BackgroundWrapper"; import { ChevronRight } from "lucide-react"; import styles from "@/css/Home.module.css"; import { API_URL } from "@/lib/auth"; import { Avatar } from "@/components/ui/avatar"; import { getLinkedViews } from "@/lib/gallery-views"; import { getTopThree } from "@/lib/leaderboard"; import DestructibleAlert from "@/components/DestructibleAlert"; import { GalleryViews } from "@/types/gallery"; interface LeaderboardEntry { id: string; name: string; points: number; } const HomePage = () => { const router = useRouter(); const [boardData, setBoardData] = useState([]); const [boardError, setBoardError] = useState(null); const [linkedViews, setLinkedViews] = useState(); useEffect(() => { let isMounted = true; const fetchBoardData = async () => { try { const response = await fetch(`${API_URL}/leaderboard`); if (!response.ok) { throw new Error("Failed to fetch leaderboard data"); } const data: LeaderboardEntry[] = await response.json(); if (isMounted) setBoardData(data); } catch (err) { if (isMounted) { const message = err instanceof Error ? err.message : "An unexpected error occurred"; setBoardError(message); } } }; const fetchedLinkedViews: GalleryViews[] = getLinkedViews(); setLinkedViews(fetchedLinkedViews); fetchBoardData(); return () => { isMounted = false; }; }, []); return (
{/* Categories Section */}

Categories

{/* Leaderboard Section */}

Leaderboard

Top 3
{boardError ? ( ) : ( getTopThree(boardData).map((student, idx) => (
{student.rank} {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 HomePage;