Prevented the exam to reload

This commit is contained in:
Tiago Ribeiro
2023-05-27 20:20:16 +01:00
parent fe72b770e9
commit 7f72349f76

View File

@@ -14,11 +14,11 @@ import Finish from "@/exams/Finish";
import axios from "axios"; import axios from "axios";
import {withIronSessionSsr} from "iron-session/next"; import {withIronSessionSsr} from "iron-session/next";
import {sessionOptions} from "@/lib/session"; import {sessionOptions} from "@/lib/session";
import {Stat, User} from "@/interfaces/user"; import {Stat} from "@/interfaces/user";
import Speaking from "@/exams/Speaking"; import Speaking from "@/exams/Speaking";
import {v4 as uuidv4} from "uuid"; import {v4 as uuidv4} from "uuid";
import useUser from "@/hooks/useUser"; import useUser from "@/hooks/useUser";
import useExamStore, {ExamState} from "@/stores/examStore"; import useExamStore from "@/stores/examStore";
export const getServerSideProps = withIronSessionSsr(({req, res}) => { export const getServerSideProps = withIronSessionSsr(({req, res}) => {
const user = req.session.user; const user = req.session.user;
@@ -41,7 +41,7 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
export default function Page() { export default function Page() {
const [hasBeenUploaded, setHasBeenUploaded] = useState(false); const [hasBeenUploaded, setHasBeenUploaded] = useState(false);
const [moduleIndex, setModuleIndex] = useState(0); const [moduleIndex, setModuleIndex] = useState(1);
const [sessionId, setSessionId] = useState(""); const [sessionId, setSessionId] = useState("");
const [exam, setExam] = useState<Exam>(); const [exam, setExam] = useState<Exam>();
const [timer, setTimer] = useState(-1); const [timer, setTimer] = useState(-1);
@@ -67,7 +67,7 @@ export default function Page() {
useEffect(() => { useEffect(() => {
(async () => { (async () => {
if (selectedModules.length > 0) { if (selectedModules.length > 0 && exams.length === 0) {
const examPromises = selectedModules.map(getExam); const examPromises = selectedModules.map(getExam);
Promise.all(examPromises).then((values) => { Promise.all(examPromises).then((values) => {
if (values.every((x) => !!x)) { if (values.every((x) => !!x)) {
@@ -76,11 +76,11 @@ export default function Page() {
}); });
} }
})(); })();
}, [selectedModules, setExams]); }, [selectedModules, setExams, exams]);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
if (selectedModules.length > 0 && moduleIndex >= selectedModules.length && !hasBeenUploaded) { if (selectedModules.length > 0 && exams.length === 0 && moduleIndex >= selectedModules.length && !hasBeenUploaded) {
const newStats: Stat[] = userSolutions.map((solution) => ({ const newStats: Stat[] = userSolutions.map((solution) => ({
...solution, ...solution,
session: sessionId, session: sessionId,