fix(api): fix api endpoint logic #5

chore(env): obscure api url in env

feat(ui): render subjects according to user preparation unit
This commit is contained in:
Dacca Retro
2025-08-18 15:06:50 +06:00
parent e3673951c6
commit 58d4d14a51
15 changed files with 3853 additions and 577 deletions

View File

@ -8,49 +8,15 @@ import { API_URL, getToken } from "@/lib/auth";
import { BoardData, getLeaderboard } from "@/lib/leaderboard";
import { UserData } from "@/types/auth";
import React, { useEffect, useState } from "react";
import { useAuth } from "@/context/AuthContext";
const LeaderboardPage = () => {
const [boardError, setBoardError] = useState<string | null>(null);
const [boardData, setBoardData] = useState<BoardData[]>([]);
const [userData, setUserData] = useState<UserData>({
name: "",
institution: "",
sscRoll: "",
hscRoll: "",
email: "",
phone: "",
});
const {user, isLoading} = useAuth()
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchUser() {
try {
const token = await getToken();
if (!token) throw new Error("User is not authenticated");
const response = await fetch(`${API_URL}/me`, {
method: "get",
headers: { Authorization: `Bearer ${token}` },
});
if (!response.ok) throw new Error("Failed to fetch user data");
const fetchedUserData = await response.json();
setLoading(false);
setUserData(fetchedUserData);
} catch (error) {
console.error(error);
setUserData({
name: "",
institution: "",
sscRoll: "",
hscRoll: "",
email: "",
phone: "",
});
}
}
async function fetchBoardData() {
try {
@ -75,10 +41,8 @@ const LeaderboardPage = () => {
setBoardData([]);
}
}
fetchUser();
fetchBoardData();
}, []);
}
const getTopThree = (boardData: BoardData[]) => {
if (!boardData || !Array.isArray(boardData)) return [];