From 9ede6580bcc1412e1c67c0acaca374e0efe4f534 Mon Sep 17 00:00:00 2001 From: Songyi Huang Date: Tue, 22 Sep 2020 22:05:35 -0700 Subject: [PATCH] detect leaderboard agent / game change and reset pagination --- src/components/MenuBar.js | 2 ++ src/view/LeaderBoard.js | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/MenuBar.js b/src/components/MenuBar.js index a62c91b..fbd9168 100644 --- a/src/components/MenuBar.js +++ b/src/components/MenuBar.js @@ -130,9 +130,11 @@ function MenuBar (props) { const history = useHistory(); const handleGameJump = (gameName) => { + props.resetPagination(); history.push(`/leaderboard?type=game&name=${gameName}`); } const handleAgentJump = (agentName) => { + props.resetPagination(); history.push(`/leaderboard?type=agent&name=${agentName}`); } diff --git a/src/view/LeaderBoard.js b/src/view/LeaderBoard.js index 01650c0..eb40ab4 100644 --- a/src/view/LeaderBoard.js +++ b/src/view/LeaderBoard.js @@ -71,8 +71,6 @@ function LeaderBoard () { } console.log(requestUrl); - // todo: detect type change then reset page and page size - useEffect(() => { async function fetchData() { const res = await axios.get(requestUrl); @@ -92,7 +90,13 @@ function LeaderBoard () { return (
- + {setPage(0); setRowsPerPage(initRowsPerPage);}} + />