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

@@ -93,6 +93,8 @@ export default function Reading({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));
useEffect(() => {
const listener = (e: KeyboardEvent) => {
if (e.key === "F3" || ((e.ctrlKey || e.metaKey) && e.key === "f")) {
@@ -127,6 +129,7 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
};
const nextExercise = (solution?: UserSolution) => {
scrollToTop();
if (solution) {
setUserSolutions((prev) => [...prev.filter((x) => x.exercise !== solution.exercise), solution]);
}
@@ -167,6 +170,7 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
};
const previousExercise = (solution?: UserSolution) => {
scrollToTop();
if (solution) {
setUserSolutions((prev) => [...prev.filter((x) => x.exercise !== solution.exercise), solution]);
}