"use client"; import { useSearchParams } from "next/navigation"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import Header from "@/components/Header"; import DestructibleAlert from "@/components/DestructibleAlert"; import BackgroundWrapper from "@/components/BackgroundWrapper"; import { API_URL } from "@/lib/auth"; import { Loader, RefreshCw } from "lucide-react"; import { v4 as uuidv4 } from "uuid"; import { useAuth } from "@/context/AuthContext"; interface Mock { id: string; title: string; rating: number; } export default function PaperScreen() { const router = useRouter(); const searchParams = useSearchParams(); const name = searchParams.get("name") || ""; const {user} = useAuth() const [questions, setQuestions] = useState(null); const [errorMsg, setErrorMsg] = useState(null); const [refreshing, setRefreshing] = useState(false); const [componentKey, setComponentKey] = useState(0); interface Subject { subject_id: string; name: string; unit: string; } const [subjects, setSubjects] = useState([ { subject_id: uuidv4(), name: "Biology", unit: "Science" }, { subject_id: uuidv4(), name: "Chemistry", unit: "Science" }, { subject_id: uuidv4(), name: "Physics", unit: "Science" }, { subject_id: uuidv4(), name: "Accounting", unit: "Business" }, { subject_id: uuidv4(), name: "Finance", unit: "Business" }, { subject_id: uuidv4(), name: "Marketing", unit: "Business" }, { subject_id: uuidv4(), name: "History", unit: "Humanities" }, { subject_id: uuidv4(), name: "Geography", unit: "Humanities" }, { subject_id: uuidv4(), name: "Sociology", unit: "Humanities" }, ]); // async function fetchMocks() { // try { // const questionResponse = await fetch(`${API_URL}/mocks`, { // method: "GET", // }); // const fetchedQuestionData: Mock[] = await questionResponse.json(); // setQuestions(fetchedQuestionData); // } catch (error) { // setErrorMsg(error instanceof Error ? error.message : "An error occurred"); // } // } // useEffect(() => { // if (name) { // fetchMocks(); // } // }, [name]); const onRefresh = async () => { setRefreshing(true); setSubjects([{ subject_id: uuidv4(), name: "Biology", unit: "Science" }, { subject_id: uuidv4(), name: "Chemistry", unit: "Science" }, { subject_id: uuidv4(), name: "Physics", unit: "Science" }, { subject_id: uuidv4(), name: "Accounting", unit: "Business Studies" }, { subject_id: uuidv4(), name: "Finance", unit: "Business Studies" }, { subject_id: uuidv4(), name: "Marketing", unit: "Business Studies" }, { subject_id: uuidv4(), name: "History", unit: "Humanities" }, { subject_id: uuidv4(), name: "Geography", unit: "Humanities" }, { subject_id: uuidv4(), name: "Sociology", unit: "Humanities" }]) setComponentKey((prevKey) => prevKey + 1); setTimeout(() => { setRefreshing(false); }, 1000); }; if (errorMsg) { return (
); } return (

{user?.preparation_unit}

{subjects ? ( subjects .filter(subject => subject.unit === user?.preparation_unit) .map((subject) => (
)) ) : (

Loading...

)}
{/* */}
); }