Made it so it currently is possible to save the progress on the Writing exercise as well
This commit is contained in:
@@ -22,9 +22,31 @@ export default function Writing({
|
|||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [inputText, setInputText] = useState(userSolutions.length === 1 ? userSolutions[0].solution : "");
|
const [inputText, setInputText] = useState(userSolutions.length === 1 ? userSolutions[0].solution : "");
|
||||||
const [isSubmitEnabled, setIsSubmitEnabled] = useState(false);
|
const [isSubmitEnabled, setIsSubmitEnabled] = useState(false);
|
||||||
|
const [saveTimer, setSaveTimer] = useState(0);
|
||||||
|
|
||||||
|
const {userSolutions: storeUserSolutions, setUserSolutions} = useExamStore((state) => state);
|
||||||
const hasExamEnded = useExamStore((state) => state.hasExamEnded);
|
const hasExamEnded = useExamStore((state) => state.hasExamEnded);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const saveTimerInterval = setInterval(() => {
|
||||||
|
setSaveTimer((prev) => prev + 1);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(saveTimerInterval);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputText.length > 0 && saveTimer % 10 === 0) {
|
||||||
|
setUserSolutions([
|
||||||
|
...storeUserSolutions.filter((x) => x.exercise !== id),
|
||||||
|
{exercise: id, solutions: [{id, solution: inputText}], score: {correct: 1, total: 1, missing: 0}, type},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [saveTimer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localStorage.getItem("enable_paste")) return;
|
if (localStorage.getItem("enable_paste")) return;
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ export default function ExamPage({page}: Props) {
|
|||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
const saveSession = async () => {
|
const saveSession = async () => {
|
||||||
|
console.log("Saving your session...");
|
||||||
|
|
||||||
await axios.post("/api/sessions", {
|
await axios.post("/api/sessions", {
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -139,6 +141,7 @@ export default function ExamPage({page}: Props) {
|
|||||||
const nextExam = exams[moduleIndex];
|
const nextExam = exams[moduleIndex];
|
||||||
|
|
||||||
if (partIndex === -1 && nextExam.module !== "listening") setPartIndex(0);
|
if (partIndex === -1 && nextExam.module !== "listening") setPartIndex(0);
|
||||||
|
if (exerciseIndex === -1 && !["reading", "listening"].includes(nextExam.module)) setExerciseIndex(0);
|
||||||
setExam(nextExam ? updateExamWithUserSolutions(nextExam) : undefined);
|
setExam(nextExam ? updateExamWithUserSolutions(nextExam) : undefined);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user