diff --git a/app/(tabs)/home/page.tsx b/app/(tabs)/home/page.tsx index 5d3e223..61005a5 100644 --- a/app/(tabs)/home/page.tsx +++ b/app/(tabs)/home/page.tsx @@ -7,7 +7,7 @@ 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 { ChevronRight } from "lucide-react"; import styles from "@/css/Home.module.css"; import { API_URL } from "@/lib/auth"; import { Avatar } from "@/components/ui/avatar"; @@ -52,6 +52,7 @@ const page = () => { } const fetchedLinkedViews = getLinkedViews(); setLinkedViews(fetchedLinkedViews); + fetchBoardData(); return () => { isMounted = false; diff --git a/app/(tabs)/leaderboard/page.tsx b/app/(tabs)/leaderboard/page.tsx index ad06c8b..33d2e2b 100644 --- a/app/(tabs)/leaderboard/page.tsx +++ b/app/(tabs)/leaderboard/page.tsx @@ -4,15 +4,22 @@ import BackgroundWrapper from "@/components/BackgroundWrapper"; import Header from "@/components/Header"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { API_URL, getToken } from "@/lib/auth"; -import { BoardData, getLeaderboard, getUserData } from "@/lib/leaderboard"; +import { BoardData, getLeaderboard } from "@/lib/leaderboard"; import { UserData } from "@/types/auth"; -import Image from "next/image"; import React, { useEffect, useState } from "react"; const LeaderboardPage = () => { const [boardError, setBoardError] = useState(null); const [boardData, setBoardData] = useState([]); - const [userData, setUserData] = useState(); + const [userData, setUserData] = useState({ + name: "", + institution: "", + sscRoll: "", + hscRoll: "", + email: "", + phone: "", + }); + const [loading, setLoading] = useState(true); useEffect(() => { @@ -80,6 +87,16 @@ const LeaderboardPage = () => { return [topThree[1], topThree[0], topThree[2]].filter(Boolean); // Handle missing players }; + const getUserData = (boardData: BoardData[], name: string) => { + if (!boardData || !Array.isArray(boardData)) return []; + const sortedData = boardData + .filter((player) => player?.name && player?.points !== undefined) + .sort((a, b) => b.points - a.points); + + const result = sortedData.find((player) => player.name === name); + return result ? [{ ...result, rank: sortedData.indexOf(result) + 1 }] : []; + }; + return (
@@ -112,7 +129,7 @@ const LeaderboardPage = () => {
- {getUserData(boardData, userData!.name).map((user, idx) => ( + {getUserData(boardData, userData.name).map((user, idx) => (
-
+
@@ -88,13 +81,7 @@ export default function PaperScreen() { return (
-
+
{questions ? ( diff --git a/app/exam/pretest/page.tsx b/app/exam/pretest/page.tsx index 0754219..760245c 100644 --- a/app/exam/pretest/page.tsx +++ b/app/exam/pretest/page.tsx @@ -91,7 +91,7 @@ export default function PretestPage() {
{metadata ? (
- diff --git a/app/exam/results/page.tsx b/app/exam/results/page.tsx index 5ddbc0b..0ade0f8 100644 --- a/app/exam/results/page.tsx +++ b/app/exam/results/page.tsx @@ -7,7 +7,7 @@ import React from "react"; import { ArrowLeft } from "lucide-react"; import SlidingGallery from "@/components/SlidingGallery"; import QuestionItem from "@/components/QuestionItem"; -import { getResultViews } from "@/lib/resultViews"; +import { getResultViews } from "@/lib/gallery-views"; export default function ResultsPage() { const router = useRouter(); diff --git a/components/Header.tsx b/components/Header.tsx index d6a4ab9..a9c7f19 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -12,7 +12,7 @@ import { UserData } from "@/types/auth"; interface HeaderProps { displayUser?: boolean; displaySubject?: string; - displayTabTitle: string; + displayTabTitle?: string; examDuration?: string; } @@ -109,18 +109,18 @@ const Header = ({
)} - {displaySubject && ( + {displayTabTitle && (
- {displaySubject} + {displayTabTitle}
)} - {displayTabTitle && ( + {displaySubject && (
- {displayTabTitle} + {displaySubject}
)} diff --git a/components/SlidingGallery.tsx b/components/SlidingGallery.tsx index bf6bd31..baa20a7 100644 --- a/components/SlidingGallery.tsx +++ b/components/SlidingGallery.tsx @@ -3,6 +3,19 @@ import Link from "next/link"; import Image from "next/image"; import styles from "../css/SlidingGallery.module.css"; +interface SlidingGalleryProps { + views?: { + id: string; + content: React.ReactNode; + }[]; + className?: string; + showPagination?: boolean; + autoScroll?: boolean; + autoScrollInterval?: number; + onSlideChange?: (currentIndex: number) => void; + height?: string | number; +} + const SlidingGallery = ({ views = [], className = "", @@ -11,7 +24,7 @@ const SlidingGallery = ({ autoScrollInterval = 5000, onSlideChange = () => {}, height = "100vh", -}) => { +}: SlidingGalleryProps) => { const [activeIdx, setActiveIdx] = useState(0); const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); const scrollRef = useRef(null); @@ -74,7 +87,7 @@ const SlidingGallery = ({ } }, [dimensions]); - const handleScroll = (event) => { + const handleScroll = (event: { target: { scrollLeft: any } }) => { handleUserInteraction(); const scrollLeft = event.target.scrollLeft; const slideWidth = dimensions.width; diff --git a/lib/gallery-views.tsx b/lib/gallery-views.tsx index 2b3d79d..e5f0195 100644 --- a/lib/gallery-views.tsx +++ b/lib/gallery-views.tsx @@ -1,5 +1,5 @@ // lib/gallery-views.tsx -import { Link } from "lucide-react"; +import Link from "next/link"; import Image from "next/image"; interface ExamResults { @@ -8,6 +8,11 @@ interface ExamResults { answers: string[]; } +interface LinkedViews { + id: string; + content: React.ReactNode; +} + export const getResultViews = (examResults: ExamResults | null) => [ { id: 1, @@ -99,7 +104,7 @@ export const getResultViews = (examResults: ExamResults | null) => [ }, ]; -export const getLinkedViews = () => [ +export const getLinkedViews = (): LinkedViews[] => [ { id: "1", content: (