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

refactor(web): jurors-page-scroll #1885

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions web/src/hooks/useScrollTop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { OverlayScrollContext } from "context/OverlayScrollContext";
export const useScrollTop = () => {
const osInstanceRef = useContext(OverlayScrollContext);

const scrollTop = () => {
osInstanceRef?.current?.osInstance().elements().viewport.scroll({ top: 0 });
const scrollTop = (smooth = false) => {
osInstanceRef?.current
?.osInstance()
.elements()
.viewport.scroll({ top: 0, behavior: smooth ? "smooth" : "auto" });
};

return scrollTop;
Expand Down
7 changes: 4 additions & 3 deletions web/src/pages/Jurors/DisplayJurors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isUndefined } from "utils/index";
import { StandardPagination } from "@kleros/ui-components-library";

import { useJurorsByCoherenceScore } from "queries/useJurorsByCoherenceScore";
import useIsDesktop from "hooks/useIsDesktop";

import { OrderDirection } from "src/graphql/graphql";

Expand All @@ -15,6 +14,7 @@ import JurorCard from "../Home/TopJurors/JurorCard";
import { ListContainer, StyledLabel } from "../Home/TopJurors";
import Header from "../Home/TopJurors/Header";
import { decodeURIFilter } from "utils/uri";
import { useScrollTop } from "hooks/useScrollTop";

interface IDisplayJurors {
totalLeaderboardJurors: number;
Expand All @@ -28,10 +28,10 @@ const StyledPagination = styled(StandardPagination)`

const DisplayJurors: React.FC<IDisplayJurors> = ({ totalLeaderboardJurors }) => {
const { page, order, filter } = useParams();
const scrollTop = useScrollTop();
const { id: searchValue } = decodeURIFilter(filter ?? "all");
const navigate = useNavigate();
const isDesktop = useIsDesktop();
const jurorsPerPage = isDesktop ? 20 : 10;
const jurorsPerPage = 10;
const currentPage = parseInt(page ?? "1");
const jurorSkip = jurorsPerPage * (currentPage - 1);
const { data: queryJurors } = useJurorsByCoherenceScore(
Expand Down Expand Up @@ -62,6 +62,7 @@ const DisplayJurors: React.FC<IDisplayJurors> = ({ totalLeaderboardJurors }) =>
);

const handlePageChange = (newPage: number) => {
scrollTop(true);
navigate(`/jurors/${newPage}/${order}/${filter}`);
};

Expand Down