generated from muhtadeetaron/nextjs-template
fix(api): fix api endpoint logic #6
This commit is contained in:
@ -7,27 +7,17 @@ import DestructibleAlert from "@/components/DestructibleAlert";
|
||||
import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { API_URL } from "@/lib/auth";
|
||||
import { useExam } from "@/context/ExamContext";
|
||||
import { Exam } from "@/types/exam";
|
||||
|
||||
interface Metadata {
|
||||
metadata: {
|
||||
quantity: number;
|
||||
type: string;
|
||||
duration: number;
|
||||
marking: string;
|
||||
};
|
||||
}
|
||||
import { Test } from "@/types/exam";
|
||||
import { Metadata } from "@/types/exam";
|
||||
|
||||
function PretestPageContent() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const [examData, setExamData] = useState<Exam>();
|
||||
const [examData, setExamData] = useState<Test>();
|
||||
const { startExam, setCurrentExam } = useExam();
|
||||
|
||||
// Get params from URL search params
|
||||
const id = searchParams.get("id") || "";
|
||||
const title = searchParams.get("title") || "";
|
||||
const rating = searchParams.get("rating") || "";
|
||||
|
||||
const [metadata, setMetadata] = useState<Metadata | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@ -67,7 +57,7 @@ function PretestPageContent() {
|
||||
<BackgroundWrapper>
|
||||
<div className="min-h-screen">
|
||||
<div className="mx-10 mt-10">
|
||||
<button onClick={() => router.push("/unit")} className="mb-4">
|
||||
<button onClick={() => router.push("/subjects")} className="mb-4">
|
||||
<ArrowLeft size={30} color="black" />
|
||||
</button>
|
||||
<DestructibleAlert text={error} extraStyles="" />
|
||||
@ -77,6 +67,24 @@ function PretestPageContent() {
|
||||
);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<BackgroundWrapper>
|
||||
<div className="min-h-screen">
|
||||
<div className="mx-10 pt-10">
|
||||
<button onClick={() => router.push("/subjects")} className="mb-4">
|
||||
<ArrowLeft size={30} color="black" />
|
||||
</button>
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mb-4"></div>
|
||||
<p className="text-lg font-medium text-gray-900">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BackgroundWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
function handleStartExam() {
|
||||
if (!examData) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user