Shuffles fixed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import {Module} from "@/interfaces";
|
||||
import {useEffect, useState} from "react";
|
||||
import { Module } from "@/interfaces";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import AbandonPopup from "@/components/AbandonPopup";
|
||||
import Layout from "@/components/High/Layout";
|
||||
@@ -12,15 +12,15 @@ import Selection from "@/exams/Selection";
|
||||
import Speaking from "@/exams/Speaking";
|
||||
import Writing from "@/exams/Writing";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import {Exam, LevelExam, UserSolution, Variant} from "@/interfaces/exam";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
import { Exam, LevelExam, UserSolution, Variant } from "@/interfaces/exam";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {evaluateSpeakingAnswer, evaluateWritingAnswer} from "@/utils/evaluation";
|
||||
import {defaultExamUserSolutions, getExam} from "@/utils/exams";
|
||||
import { evaluateSpeakingAnswer, evaluateWritingAnswer } from "@/utils/evaluation";
|
||||
import { defaultExamUserSolutions, getExam } from "@/utils/exams";
|
||||
import axios from "axios";
|
||||
import {useRouter} from "next/router";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import { useRouter } from "next/router";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import useSessions from "@/hooks/useSessions";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
import clsx from "clsx";
|
||||
@@ -29,7 +29,7 @@ interface Props {
|
||||
page: "exams" | "exercises";
|
||||
}
|
||||
|
||||
export default function ExamPage({page}: Props) {
|
||||
export default function ExamPage({ page }: Props) {
|
||||
const [variant, setVariant] = useState<Variant>("full");
|
||||
const [avoidRepeated, setAvoidRepeated] = useState(false);
|
||||
const [hasBeenUploaded, setHasBeenUploaded] = useState(false);
|
||||
@@ -44,20 +44,21 @@ export default function ExamPage({page}: Props) {
|
||||
const assignment = useExamStore((state) => state.assignment);
|
||||
const initialTimeSpent = useExamStore((state) => state.timeSpent);
|
||||
|
||||
const {exam, setExam} = useExamStore((state) => state);
|
||||
const {exams, setExams} = useExamStore((state) => state);
|
||||
const {sessionId, setSessionId} = useExamStore((state) => state);
|
||||
const {partIndex, setPartIndex} = useExamStore((state) => state);
|
||||
const {moduleIndex, setModuleIndex} = useExamStore((state) => state);
|
||||
const {questionIndex, setQuestionIndex} = useExamStore((state) => state);
|
||||
const {exerciseIndex, setExerciseIndex} = useExamStore((state) => state);
|
||||
const {userSolutions, setUserSolutions} = useExamStore((state) => state);
|
||||
const {showSolutions, setShowSolutions} = useExamStore((state) => state);
|
||||
const {selectedModules, setSelectedModules} = useExamStore((state) => state);
|
||||
const {inactivity, setInactivity} = useExamStore((state) => state);
|
||||
const {bgColor, setBgColor} = useExamStore((state) => state);
|
||||
const { exam, setExam } = useExamStore((state) => state);
|
||||
const { exams, setExams } = useExamStore((state) => state);
|
||||
const { sessionId, setSessionId } = useExamStore((state) => state);
|
||||
const { partIndex, setPartIndex } = useExamStore((state) => state);
|
||||
const { moduleIndex, setModuleIndex } = useExamStore((state) => state);
|
||||
const { questionIndex, setQuestionIndex } = useExamStore((state) => state);
|
||||
const { exerciseIndex, setExerciseIndex } = useExamStore((state) => state);
|
||||
const { userSolutions, setUserSolutions } = useExamStore((state) => state);
|
||||
const { showSolutions, setShowSolutions } = useExamStore((state) => state);
|
||||
const { selectedModules, setSelectedModules } = useExamStore((state) => state);
|
||||
const { inactivity, setInactivity } = useExamStore((state) => state);
|
||||
const { bgColor, setBgColor } = useExamStore((state) => state);
|
||||
const setShuffleMaps = useExamStore((state) => state.setShuffles)
|
||||
|
||||
const {user} = useUser({redirectTo: "/login"});
|
||||
const { user } = useUser({ redirectTo: "/login" });
|
||||
const router = useRouter();
|
||||
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -260,11 +261,11 @@ export default function ExamPage({page}: Props) {
|
||||
date: new Date().getTime(),
|
||||
isDisabled: solution.isDisabled,
|
||||
shuffleMaps: solution.shuffleMaps,
|
||||
...(assignment ? {assignment: assignment.id} : {}),
|
||||
...(assignment ? { assignment: assignment.id } : {}),
|
||||
}));
|
||||
|
||||
axios
|
||||
.post<{ok: boolean}>("/api/stats", newStats)
|
||||
.post<{ ok: boolean }>("/api/stats", newStats)
|
||||
.then((response) => setHasBeenUploaded(response.data.ok))
|
||||
.catch(() => setHasBeenUploaded(false));
|
||||
}
|
||||
@@ -282,9 +283,9 @@ export default function ExamPage({page}: Props) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [statsAwaitingEvaluation]);
|
||||
|
||||
useEffect(()=> {
|
||||
useEffect(() => {
|
||||
|
||||
if(exam && exam.module === "level" && exam.parts[0].intro && !showSolutions) {
|
||||
if (exam && exam.module === "level" && exam.parts[0].intro && !showSolutions) {
|
||||
setBgColor("bg-ielts-level-light");
|
||||
}
|
||||
}, [exam, showSolutions, setBgColor])
|
||||
@@ -332,7 +333,7 @@ export default function ExamPage({page}: Props) {
|
||||
),
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, {parts});
|
||||
return Object.assign(exam, { parts });
|
||||
}
|
||||
|
||||
const exercises = exam.exercises.map((x) =>
|
||||
@@ -340,7 +341,7 @@ export default function ExamPage({page}: Props) {
|
||||
userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions,
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, {exercises});
|
||||
return Object.assign(exam, { exercises });
|
||||
};
|
||||
|
||||
const onFinish = async (solutions: UserSolution[]) => {
|
||||
@@ -348,6 +349,8 @@ export default function ExamPage({page}: Props) {
|
||||
const solutionExams = solutions.map((x) => x.exam);
|
||||
|
||||
let newSolutions = [...solutions];
|
||||
console.log("ON finish CALLEDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
|
||||
console.log(newSolutions);
|
||||
|
||||
if (exam && !solutionExams.includes(exam.id)) return;
|
||||
|
||||
@@ -395,7 +398,7 @@ export default function ExamPage({page}: Props) {
|
||||
correct: number;
|
||||
}[] => {
|
||||
const scores: {
|
||||
[key in Module]: {total: number; missing: number; correct: number};
|
||||
[key in Module]: { total: number; missing: number; correct: number };
|
||||
} = {
|
||||
reading: {
|
||||
total: 0,
|
||||
@@ -437,7 +440,7 @@ export default function ExamPage({page}: Props) {
|
||||
|
||||
return Object.keys(scores)
|
||||
.filter((x) => scores[x as Module].total > 0)
|
||||
.map((x) => ({module: x as Module, ...scores[x as Module]}));
|
||||
.map((x) => ({ module: x as Module, ...scores[x as Module] }));
|
||||
};
|
||||
|
||||
const renderScreen = () => {
|
||||
@@ -478,10 +481,13 @@ export default function ExamPage({page}: Props) {
|
||||
const indexB = exerciseOrderMap.get(b.exercise) ?? Infinity;
|
||||
return indexA - indexB;
|
||||
});
|
||||
console.log(orderedSolutions);
|
||||
setUserSolutions(orderedSolutions);
|
||||
|
||||
} else {
|
||||
setUserSolutions(userSolutions);
|
||||
}
|
||||
setShuffleMaps([]);
|
||||
setShowSolutions(true);
|
||||
setModuleIndex(index || 0);
|
||||
setExerciseIndex(["reading", "listening"].includes(exams[0].module) ? -1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user