Skip to content

Commit

Permalink
Merge pull request #215 from kleros/fix(web)/reset-pages-when-filtered
Browse files Browse the repository at this point in the history
fix: reset pages shown when filter applied
  • Loading branch information
alcercu authored May 31, 2023
2 parents b30f287 + bdb26dc commit 74ea819
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions veascan-web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState, useCallback } from "react";
import React, { useCallback, useEffect, useState } from "react";
import styled from "styled-components";
import { useList } from "react-use";
import { StandardPagination } from "@kleros/ui-components-library";
import Layout from "components/Layout";
import SnapshotAccordion from "components/SnapshotAccordion";
import TxFilterHeader from "components/TxFilterHeader";
import { useSnapshots, getSnapshotId } from "hooks/useSnapshots";
import { getSnapshotId, useSnapshots } from "hooks/useSnapshots";
import { mapDataForAccordion } from "utils/mapDataForAccordion";
import { useFiltersContext } from "./contexts/FiltersContext";

const SNAPSHOTS_PER_PAGE = 5;

Expand All @@ -24,13 +25,27 @@ const App = () => {
const [currentPage, setCurrentPage] = useState(1);
const [
pageTracking,
{ push: pushPageTracking, removeAt: removeAtPageTracking },
{
push: pushPageTracking,
removeAt: removeAtPageTracking,
clear: clearPageTracking,
},
] = useList<IPageTracking>();
const { data } = useSnapshots(
pageTracking.at(-1)?.shownSnapshots,
pageTracking.at(-1)?.timestamp,
SNAPSHOTS_PER_PAGE
);

const { fromChain, toChain, statusFilter } = useFiltersContext();

useEffect(() => {
if (currentPage !== 1) {
clearPageTracking();
setCurrentPage(1);
}
}, [fromChain, toChain, statusFilter]);

const handlePageChange = useCallback(
(newPage: number) => {
if (newPage > currentPage)
Expand Down

0 comments on commit 74ea819

Please sign in to comment.