Skip to content

Commit

Permalink
Implement search block (#16)
Browse files Browse the repository at this point in the history
* Implement block filter

* Fix layout

On this way the filters are properly aligned at the end
  • Loading branch information
selankon authored Jun 28, 2024
1 parent 7f991d1 commit dbda560
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
34 changes: 33 additions & 1 deletion src/components/Blocks/BlocksList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useParams } from 'react-router-dom'
import { generatePath, useNavigate, useParams } from 'react-router-dom'
import { RoutedPagination } from '~components/Pagination/Pagination'
import { RoutedPaginationProvider } from '~components/Pagination/PaginationProvider'
import { PaginationItemsPerPage, RoutePath } from '~constants'
Expand All @@ -7,6 +7,38 @@ import LoadingError from '~src/layout/LoadingError'
import { useBlockList } from '~queries/blocks'
import { useChainInfo } from '~queries/stats'
import { BlockCard } from '~components/Blocks/BlockCard'
import { useTranslation } from 'react-i18next'
import { InputSearch } from '~src/layout/Inputs'

export const BlocksFilter = () => {
const { t } = useTranslation()
const navigate = useNavigate()
const { data: stats, isLoading: isLoadingStats } = useChainInfo({
refetchInterval: 1000,
})

const blockCount = stats?.height || 0

return (
<InputSearch
maxW={'300px'}
placeholder={t('blocks.search_block')}
onChange={(value: string) => {
if (!blockCount) {
return
}
const num = parseInt(value)
let page = 0 // By default return to first page
if (!isNaN(num) && num >= 0) {
page = Math.ceil((blockCount - num + 1) / PaginationItemsPerPage)
}
navigate(generatePath(RoutePath.BlocksList, { page: page.toString() }))
}}
debounceTime={500}
type={'number'}
/>
)
}

export const PaginatedBlocksList = () => {
const { page }: { page?: number } = useParams()
Expand Down
2 changes: 1 addition & 1 deletion src/layout/ListPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ListPageLayout = ({
{subtitle && <Text color={'lighterText'}>{subtitle}</Text>}
</Flex>
{rightComponent && (
<Flex align={'end'} justify={'end'} w={'full'}>
<Flex align={'end'} justify={'end'}>
{rightComponent}
</Flex>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/blocks.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ListPageLayout from '~src/layout/ListPageLayout'
import { useTranslation } from 'react-i18next'
import { useChainInfo } from '~queries/stats'
import { PaginatedBlocksList } from '~components/Blocks/BlocksList'
import { BlocksFilter, PaginatedBlocksList } from '~components/Blocks/BlocksList'

const BlocksList = () => {
const { t } = useTranslation()
Expand All @@ -10,7 +10,7 @@ const BlocksList = () => {
const subtitle = !isLoadingStats && !!stats?.height ? t('blocks.blocks_count', { count: stats.height }) : ''

return (
<ListPageLayout title={t('blocks.blocks_list')} subtitle={subtitle}>
<ListPageLayout title={t('blocks.blocks_list')} subtitle={subtitle} rightComponent={<BlocksFilter />}>
<PaginatedBlocksList />
</ListPageLayout>
)
Expand Down

2 comments on commit dbda560

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.