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

@@ -24,7 +24,10 @@ export default function Writing({exam, showSolutions = false, onFinish}: Props)
const [hasExamEnded, setHasExamEnded] = useExamStore((state) => [state.hasExamEnded, state.setHasExamEnded]);
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
const nextExercise = (solution?: UserSolution) => {
scrollToTop();
if (solution) {
setUserSolutions((prev) => [...prev.filter((x) => x.exercise !== solution.exercise), solution]);
}
@@ -48,6 +51,7 @@ export default function Writing({exam, showSolutions = false, onFinish}: Props)
};
const previousExercise = (solution?: UserSolution) => {
scrollToTop();
if (solution) {
setUserSolutions((prev) => [...prev.filter((x) => x.exercise !== solution.exercise), solution]);
}