Added a Scroll To Top function

This commit is contained in:
Tiago Ribeiro
2024-02-05 17:59:46 +00:00
parent f6166ca9e1
commit 8baa25c445
8 changed files with 354 additions and 393 deletions

View File

@@ -63,6 +63,8 @@ export default function MultipleChoice({
const hasExamEnded = useExamStore((state) => state.hasExamEnded);
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
useEffect(() => {
if (hasExamEnded) onNext({exercise: id, solutions: answers, score: calculateScore(), type});
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -93,6 +95,8 @@ export default function MultipleChoice({
} else {
setQuestionIndex((prev) => prev + 1);
}
scrollToTop();
};
const back = () => {
@@ -101,6 +105,8 @@ export default function MultipleChoice({
} else {
setQuestionIndex((prev) => prev - 1);
}
scrollToTop();
};
return (