From 8caf3ac7293388ecbf3b39aefe3c9f1bb9f84ee7 Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 6 Jun 2023 16:45:32 -0400 Subject: [PATCH] fix: pagination is not correct when changing tabs on blocks page --- ui/pages/Blocks.tsx | 60 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/ui/pages/Blocks.tsx b/ui/pages/Blocks.tsx index 1a277a34ed..adc62201d2 100644 --- a/ui/pages/Blocks.tsx +++ b/ui/pages/Blocks.tsx @@ -1,11 +1,11 @@ import { useRouter } from 'next/router'; import React from 'react'; -import type { BlockType } from 'types/api/block'; import type { RoutedTab } from 'ui/shared/Tabs/types'; import useIsMobile from 'lib/hooks/useIsMobile'; import useQueryWithPages from 'lib/hooks/useQueryWithPages'; +import getQueryParamString from 'lib/router/getQueryParamString'; import { BLOCK } from 'stubs/block'; import { generateListStub } from 'stubs/utils'; import BlocksContent from 'ui/blocks/BlocksContent'; @@ -13,12 +13,6 @@ import BlocksTabSlot from 'ui/blocks/BlocksTabSlot'; import PageTitle from 'ui/shared/Page/PageTitle'; import RoutedTabs from 'ui/shared/Tabs/RoutedTabs'; -const TAB_TO_TYPE: Record = { - blocks: 'block', - reorgs: 'reorg', - uncles: 'uncle', -}; - const TAB_LIST_PROPS = { marginBottom: 0, py: 5, @@ -28,23 +22,65 @@ const TAB_LIST_PROPS = { const BlocksPageContent = () => { const router = useRouter(); const isMobile = useIsMobile(); - const type = router.query.tab && !Array.isArray(router.query.tab) ? TAB_TO_TYPE[router.query.tab] : 'block'; + const tab = getQueryParamString(router.query.tab); const blocksQuery = useQueryWithPages({ resourceName: 'blocks', - filters: { type }, + filters: { type: 'block' }, + options: { + enabled: tab === 'blocks' || !tab, + placeholderData: generateListStub<'blocks'>(BLOCK, 50, { next_page_params: { + block_number: 8988686, + items_count: 50, + } }), + }, + }); + const reorgsQuery = useQueryWithPages({ + resourceName: 'blocks', + filters: { type: 'reorg' }, options: { + enabled: tab === 'reorgs', placeholderData: generateListStub<'blocks'>(BLOCK, 50, { next_page_params: { block_number: 8988686, items_count: 50, } }), }, }); + const unclesQuery = useQueryWithPages({ + resourceName: 'blocks', + filters: { type: 'uncle' }, + options: { + enabled: tab === 'uncles', + placeholderData: generateListStub<'blocks'>(BLOCK, 50, { next_page_params: { + block_number: 8988686, + items_count: 50, + } }), + }, + }); + + const { pagination, isPaginationVisible } = (() => { + if (tab === 'reorgs') { + return { + pagination: reorgsQuery.pagination, + isPaginationVisible: reorgsQuery.isPaginationVisible, + }; + } + if (tab === 'uncles') { + return { + pagination: unclesQuery.pagination, + isPaginationVisible: unclesQuery.isPaginationVisible, + }; + } + return { + pagination: blocksQuery.pagination, + isPaginationVisible: blocksQuery.isPaginationVisible, + }; + })(); const tabs: Array = [ { id: 'blocks', title: 'All', component: }, - { id: 'reorgs', title: 'Forked', component: }, - { id: 'uncles', title: 'Uncles', component: }, + { id: 'reorgs', title: 'Forked', component: }, + { id: 'uncles', title: 'Uncles', component: }, ]; return ( @@ -53,7 +89,7 @@ const BlocksPageContent = () => { } + rightSlot={ } stickyEnabled={ !isMobile } />