Commit cc5fbdbb authored by tom's avatar tom

hide pagination if there is only one page

parent 7faddf76
...@@ -30,6 +30,7 @@ const BlocksContent = ({ type }: Props) => { ...@@ -30,6 +30,7 @@ const BlocksContent = ({ type }: Props) => {
queryName: QueryKeys.blocks, queryName: QueryKeys.blocks,
filters: { type }, filters: { type },
}); });
const isPaginatorHidden = !isLoading && !isError && pagination.page === 1 && !pagination.hasNextPage;
const handleNewBlockMessage: SocketMessage.NewBlock['handler'] = React.useCallback((payload) => { const handleNewBlockMessage: SocketMessage.NewBlock['handler'] = React.useCallback((payload) => {
queryClient.setQueryData([ QueryKeys.blocks, { page: pagination.page, filters: { type } } ], (prevData: BlocksResponse | undefined) => { queryClient.setQueryData([ QueryKeys.blocks, { page: pagination.page, filters: { type } } ], (prevData: BlocksResponse | undefined) => {
...@@ -91,21 +92,27 @@ const BlocksContent = ({ type }: Props) => { ...@@ -91,21 +92,27 @@ const BlocksContent = ({ type }: Props) => {
<> <>
{ socketAlert && <Alert status="warning" mb={ 6 } as="a" href={ window.document.location.href }>{ socketAlert }</Alert> } { socketAlert && <Alert status="warning" mb={ 6 } as="a" href={ window.document.location.href }>{ socketAlert }</Alert> }
<Show below="lg" key="content-mobile"><BlocksList data={ data.items }/></Show> <Show below="lg" key="content-mobile"><BlocksList data={ data.items }/></Show>
<Hide below="lg" key="content-desktop"><BlocksTable data={ data.items }/></Hide> <Hide below="lg" key="content-desktop"><BlocksTable data={ data.items } top={ isPaginatorHidden ? 0 : 80 }/></Hide>
</> </>
); );
})(); })();
const totalText = data?.items.length ?
<Text mb={{ base: 0, lg: 6 }}>Total of { data.items[0].height.toLocaleString() } blocks</Text> :
null;
return ( return (
<> <>
{ data ? { data ?
<Text mb={{ base: 0, lg: 6 }}>Total of { data.items[0].height.toLocaleString() } blocks</Text> : totalText :
<Skeleton h="24px" w="200px" mb={{ base: 0, lg: 6 }}/> <Skeleton h="24px" w="200px" mb={{ base: 0, lg: 6 }}/>
} }
{ !isPaginatorHidden && (
<ActionBar> <ActionBar>
<Pagination ml="auto" { ...pagination }/> <Pagination ml="auto" { ...pagination }/>
</ActionBar> </ActionBar>
) }
{ content } { content }
</> </>
); );
......
...@@ -12,13 +12,14 @@ import { default as Thead } from 'ui/shared/TheadSticky'; ...@@ -12,13 +12,14 @@ import { default as Thead } from 'ui/shared/TheadSticky';
interface Props { interface Props {
data: Array<Block>; data: Array<Block>;
top: number;
} }
const BlocksTable = ({ data }: Props) => { const BlocksTable = ({ data, top }: Props) => {
return ( return (
<Table variant="simple" minWidth="1040px" size="md" fontWeight={ 500 }> <Table variant="simple" minWidth="1040px" size="md" fontWeight={ 500 }>
<Thead top={ 80 }> <Thead top={ top }>
<Tr> <Tr>
<Th width="125px">Block</Th> <Th width="125px">Block</Th>
<Th width="120px">Size</Th> <Th width="120px">Size</Th>
......
...@@ -37,6 +37,7 @@ const TxsContent = ({ ...@@ -37,6 +37,7 @@ const TxsContent = ({
}); });
// } = useQueryWithPages({ ...filters, filter: stateFilter, apiPath }); // } = useQueryWithPages({ ...filters, filter: stateFilter, apiPath });
const { data, isLoading, isError, setSortByField, setSortByValue, sorting } = useTxsSort(queryResult); const { data, isLoading, isError, setSortByField, setSortByValue, sorting } = useTxsSort(queryResult);
const isPaginatorHidden = !isLoading && !isError && pagination.page === 1 && !pagination.hasNextPage;
const content = (() => { const content = (() => {
if (isError) { if (isError) {
...@@ -61,7 +62,7 @@ const TxsContent = ({ ...@@ -61,7 +62,7 @@ const TxsContent = ({
return ( return (
<> <>
<Show below="lg" ssr={ false }><Box>{ txs.map(tx => <TxsListItem tx={ tx } key={ tx.hash }/>) }</Box></Show> <Show below="lg" ssr={ false }><Box>{ txs.map(tx => <TxsListItem tx={ tx } key={ tx.hash }/>) }</Box></Show>
<Hide below="lg" ssr={ false }><TxsTable txs={ txs } sort={ setSortByField } sorting={ sorting }/></Hide> <Hide below="lg" ssr={ false }><TxsTable txs={ txs } sort={ setSortByField } sorting={ sorting } top={ isPaginatorHidden ? 0 : 80 }/></Hide>
</> </>
); );
})(); })();
...@@ -69,7 +70,7 @@ const TxsContent = ({ ...@@ -69,7 +70,7 @@ const TxsContent = ({
return ( return (
<> <>
{ showDescription && <Box mb={{ base: 6, lg: 12 }}>Only the first 10,000 elements are displayed</Box> } { showDescription && <Box mb={{ base: 6, lg: 12 }}>Only the first 10,000 elements are displayed</Box> }
<TxsHeader mt={ -6 } sorting={ sorting } setSorting={ setSortByValue } paginationProps={ pagination }/> <TxsHeader mt={ -6 } sorting={ sorting } setSorting={ setSortByValue } paginationProps={ pagination } showPagination={ !isPaginatorHidden }/>
{ content } { content }
</> </>
); );
......
...@@ -17,11 +17,16 @@ type Props = { ...@@ -17,11 +17,16 @@ type Props = {
setSorting: (val: Sort) => void; setSorting: (val: Sort) => void;
paginationProps: PaginationProps; paginationProps: PaginationProps;
className?: string; className?: string;
showPagination?: boolean;
} }
const TxsHeader = ({ sorting, setSorting, paginationProps, className }: Props) => { const TxsHeader = ({ sorting, setSorting, paginationProps, className, showPagination = true }: Props) => {
const isMobile = useIsMobile(false); const isMobile = useIsMobile(false);
if (!showPagination && !isMobile) {
return null;
}
return ( return (
<ActionBar className={ className }> <ActionBar className={ className }>
<HStack> <HStack>
...@@ -47,7 +52,7 @@ const TxsHeader = ({ sorting, setSorting, paginationProps, className }: Props) = ...@@ -47,7 +52,7 @@ const TxsHeader = ({ sorting, setSorting, paginationProps, className }: Props) =
placeholder="Search by addresses, hash, method..." placeholder="Search by addresses, hash, method..."
/> */ } /> */ }
</HStack> </HStack>
<Pagination { ...paginationProps }/> { showPagination && <Pagination { ...paginationProps }/> }
</ActionBar> </ActionBar>
); );
}; };
......
...@@ -14,12 +14,13 @@ type Props = { ...@@ -14,12 +14,13 @@ type Props = {
txs: Array<Transaction>; txs: Array<Transaction>;
sort: (field: 'val' | 'fee') => () => void; sort: (field: 'val' | 'fee') => () => void;
sorting?: Sort; sorting?: Sort;
top: number;
} }
const TxsTable = ({ txs, sort, sorting }: Props) => { const TxsTable = ({ txs, sort, sorting, top }: Props) => {
return ( return (
<Table variant="simple" minWidth="810px" size="xs"> <Table variant="simple" minWidth="810px" size="xs">
<TheadSticky top={ 80 }> <TheadSticky top={ top }>
<Tr> <Tr>
<Th width="54px"></Th> <Th width="54px"></Th>
<Th width="20%">Type</Th> <Th width="20%">Type</Th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment