From 96fc060f703bb7ffbbd434e9c1a828ff0774241b Mon Sep 17 00:00:00 2001 From: nhestrompia Date: Wed, 31 May 2023 18:06:36 +0300 Subject: [PATCH 1/3] fix: reset pages shown when filter applied --- veascan-web/src/App.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/veascan-web/src/App.tsx b/veascan-web/src/App.tsx index f997f74b..e1dbcdcb 100644 --- a/veascan-web/src/App.tsx +++ b/veascan-web/src/App.tsx @@ -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; @@ -24,15 +25,28 @@ const App = () => { const [currentPage, setCurrentPage] = useState(1); const [ pageTracking, - { push: pushPageTracking, removeAt: removeAtPageTracking }, + { + push: pushPageTracking, + removeAt: removeAtPageTracking, + clear: clearPageTracking, + }, ] = useList(); const { data } = useSnapshots( pageTracking.at(-1)?.shownSnapshots, pageTracking.at(-1)?.timestamp, SNAPSHOTS_PER_PAGE ); + + const { fromChain, toChain, statusFilter } = useFiltersContext(); + + useEffect(() => { + clearPageTracking(); + setCurrentPage(1); + }, [fromChain, toChain, statusFilter]); + const handlePageChange = useCallback( (newPage: number) => { + console.log("data", data); if (newPage > currentPage) pushPageTracking({ timestamp: data?.snapshots.at(-1)?.[0].timestamp, From 56e75634b504a97247b80ecd5edf0b0568cb36a8 Mon Sep 17 00:00:00 2001 From: nhestrompia Date: Wed, 31 May 2023 18:08:31 +0300 Subject: [PATCH 2/3] chore: remove console log --- veascan-web/src/App.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/veascan-web/src/App.tsx b/veascan-web/src/App.tsx index e1dbcdcb..f118c835 100644 --- a/veascan-web/src/App.tsx +++ b/veascan-web/src/App.tsx @@ -46,7 +46,6 @@ const App = () => { const handlePageChange = useCallback( (newPage: number) => { - console.log("data", data); if (newPage > currentPage) pushPageTracking({ timestamp: data?.snapshots.at(-1)?.[0].timestamp, From bcfe12e3194e448e0d70abdc03c1bfb204a06d50 Mon Sep 17 00:00:00 2001 From: nhestrompia Date: Wed, 31 May 2023 18:52:17 +0300 Subject: [PATCH 3/3] fix: prevent re-render --- veascan-web/src/App.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/veascan-web/src/App.tsx b/veascan-web/src/App.tsx index f118c835..a9c504b0 100644 --- a/veascan-web/src/App.tsx +++ b/veascan-web/src/App.tsx @@ -40,8 +40,10 @@ const App = () => { const { fromChain, toChain, statusFilter } = useFiltersContext(); useEffect(() => { - clearPageTracking(); - setCurrentPage(1); + if (currentPage !== 1) { + clearPageTracking(); + setCurrentPage(1); + } }, [fromChain, toChain, statusFilter]); const handlePageChange = useCallback(