Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Scroll to Top" button beneath generated schedules. #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
18 changes: 16 additions & 2 deletions app/src/components/MultipleScheduleDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useState, useRef } from "react";
import { Schedule } from "@scripts/scheduleGenerator";
import ScheduleDisplay from "@components/ScheduleDisplay";

Expand All @@ -12,10 +12,15 @@ interface Props {
export default function MultipleScheduleDisplay(props: Props) {
const [numPages, setNumPages] = useState(1);

const scrollAnchorRef = useRef<HTMLDivElement>(null);
const scrollToTop = () => {
scrollAnchorRef.current?.scrollIntoView({ behavior: "smooth" });
};

const maxSchedulesToShow = (props.numPerPage ?? NUM_PER_PAGE) * numPages;
const schedulesToShow = props.schedules.slice(0, maxSchedulesToShow);
return (
<div>
<div ref={scrollAnchorRef}>
<p className={"text-center"}>
<b>
<u>{props.schedules.length.toLocaleString()}</u> Schedules
Expand All @@ -42,6 +47,15 @@ export default function MultipleScheduleDisplay(props: Props) {
</button>
</div>
)}

{props.schedules.length > 1 ? (
<button
onClick={scrollToTop}
className="bg-sky-500 hover:bg-sky-400 border border-blue-300 text-white text-sm rounded-lg p-1.5 mr-1 text-center mt-1.5 mb-1.5"
>
Scroll to top
</button>
) : null}
</div>
);
}