Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions frontend/src/ts/components/layout/footer/ScrollToTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@ import { Fa } from "../../common/Fa";

export function ScrollToTop(): JSXElement {
const [visible, setVisible] = createSignal(false);
const [scrolling, setScrolling] = createSignal(false);

const handleScroll = (): void => {
if (getActivePage() === "test") return;

if (getActivePage() === "test" || scrolling()) return;
const scroll = window.scrollY;
setVisible(scroll > 100);
};

const scrollUp = async (): Promise<void> => {
const scrollEnded = new Promise<void>((resolve) => {
setTimeout(resolve, 1000);
if (window.scrollY === 0) {
resolve();
return;
}
window.addEventListener("scrollend", () => resolve(), { once: true });
});
window.scrollTo({ top: 0, behavior: "smooth" });
await scrollEnded;
};
Comment on lines +16 to +27

onMount(() => {
window.addEventListener("scroll", handleScroll, { passive: true });
handleScroll();
Expand All @@ -35,12 +48,11 @@ export function ScrollToTop(): JSXElement {
"opacity-0": getActivePage() === "test" || !visible(),
"pointer-events-none": getActivePage() === "test" || !visible(),
}}
onClick={() => {
onClick={async () => {
setVisible(false);
window.scrollTo({
top: 0,
behavior: "smooth",
});
setScrolling(true);
await scrollUp();
setScrolling(false);
Comment on lines +51 to +55
}}
>
<Fa icon="fa-angle-double-up" />
Expand Down
Loading