Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
34ce2914
Commit
34ce2914
authored
May 12, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
skeleton for pagination component
parent
327cee07
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
87 additions
and
60 deletions
+87
-60
useQueryWithPages.ts
lib/hooks/useQueryWithPages.ts
+1
-0
block.ts
mocks/blocks/block.ts
+2
-0
stats.ts
stubs/stats.ts
+20
-0
stats.ts
types/api/stats.ts
+1
-1
BlocksContent.tsx
ui/blocks/BlocksContent.tsx
+5
-5
BlocksTabSlot.tsx
ui/blocks/BlocksTabSlot.tsx
+10
-12
BlocksTable.tsx
ui/blocks/BlocksTable.tsx
+1
-1
Pagination.tsx
ui/shared/Pagination.tsx
+47
-41
No files found.
lib/hooks/useQueryWithPages.ts
View file @
34ce2914
...
...
@@ -158,6 +158,7 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
resetPage
,
hasNextPage
:
nextPageParams
?
Object
.
keys
(
nextPageParams
).
length
>
0
:
false
,
canGoBackwards
:
canGoBackwards
.
current
,
isLoading
:
queryResult
.
isPlaceholderData
&&
!
hasPagination
,
};
const
isPaginationVisible
=
hasPagination
||
(
!
queryResult
.
isLoading
&&
!
queryResult
.
isError
&&
pagination
.
hasNextPage
);
...
...
mocks/blocks/block.ts
View file @
34ce2914
...
...
@@ -47,6 +47,7 @@ export const base: Block = {
tx_fees
:
'
26853607500000000
'
,
type
:
'
block
'
,
uncles_hashes
:
[],
has_beacon_chain_withdrawals
:
false
,
};
export
const
genesis
:
Block
=
{
...
...
@@ -83,6 +84,7 @@ export const genesis: Block = {
tx_fees
:
'
0
'
,
type
:
'
block
'
,
uncles_hashes
:
[],
has_beacon_chain_withdrawals
:
false
,
};
export
const
base2
:
Block
=
{
...
...
stubs/stats.ts
0 → 100644
View file @
34ce2914
import
type
{
HomeStats
}
from
'
types/api/stats
'
;
export
const
HOMEPAGE_STATS
:
HomeStats
=
{
average_block_time
:
14346
,
coin_price
:
'
1807.68
'
,
gas_prices
:
{
average
:
0.1
,
fast
:
0.11
,
slow
:
0.1
,
},
gas_used_today
:
'
0
'
,
market_cap
:
'
0
'
,
network_utilization_percentage
:
22.56
,
static_gas_price
:
null
,
total_addresses
:
'
28634064
'
,
total_blocks
:
'
8940150
'
,
total_gas_used
:
'
0
'
,
total_transactions
:
'
193823272
'
,
transactions_today
:
'
0
'
,
};
types/api/stats.ts
View file @
34ce2914
...
...
@@ -8,7 +8,7 @@ export type HomeStats = {
transactions_today
:
string
;
gas_used_today
:
string
;
gas_prices
:
GasPrices
|
null
;
static_gas_price
:
string
;
static_gas_price
:
string
|
null
;
market_cap
:
string
;
network_utilization_percentage
:
number
;
}
...
...
ui/blocks/BlocksContent.tsx
View file @
34ce2914
import
{
Show
,
Hide
,
Alert
}
from
'
@chakra-ui/react
'
;
import
{
Alert
,
Box
}
from
'
@chakra-ui/react
'
;
import
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
...
...
@@ -77,12 +77,12 @@ const BlocksContent = ({ type, query }: Props) => {
const
content
=
query
.
data
?.
items
?
(
<>
{
socketAlert
&&
<
Alert
status=
"warning"
mb=
{
6
}
as=
"a"
href=
{
window
.
document
.
location
.
href
}
>
{
socketAlert
}
</
Alert
>
}
<
Show
below=
"lg"
key=
"content-mobile"
ssr=
{
false
}
>
<
Box
display=
{
{
base
:
'
block
'
,
lg
:
'
none
'
}
}
>
<
BlocksList
data=
{
query
.
data
.
items
}
isLoading=
{
query
.
isPlaceholderData
}
page=
{
query
.
pagination
.
page
}
/>
</
Show
>
<
Hide
below=
"lg"
key=
"content-desktop"
ssr=
{
false
}
>
</
Box
>
<
Box
display=
{
{
base
:
'
none
'
,
lg
:
'
block
'
}
}
>
<
BlocksTable
data=
{
query
.
data
.
items
}
top=
{
query
.
isPaginationVisible
?
80
:
0
}
page=
{
query
.
pagination
.
page
}
isLoading=
{
query
.
isPlaceholderData
}
/>
</
Hide
>
</
Box
>
</>
)
:
null
;
...
...
ui/blocks/BlocksTabSlot.tsx
View file @
34ce2914
...
...
@@ -2,8 +2,8 @@ import { Flex, Box, Text, Skeleton } from '@chakra-ui/react';
import
React
from
'
react
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
nbsp
}
from
'
lib/html-entities
'
;
import
{
HOMEPAGE_STATS
}
from
'
stubs/stats
'
;
import
type
{
Props
as
PaginationProps
}
from
'
ui/shared/Pagination
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
...
...
@@ -13,24 +13,22 @@ interface Props {
}
const
BlocksTabSlot
=
({
pagination
,
isPaginationVisible
}:
Props
)
=>
{
const
isMobile
=
useIsMobile
();
const
statsQuery
=
useApiQuery
(
'
homepage_stats
'
);
if
(
isMobile
)
{
return
null
;
}
const
statsQuery
=
useApiQuery
(
'
homepage_stats
'
,
{
queryOptions
:
{
placeholderData
:
HOMEPAGE_STATS
,
},
});
return
(
<
Flex
alignItems=
"center"
columnGap=
{
8
}
>
{
statsQuery
.
isLoading
&&
<
Skeleton
w=
"175px"
h=
"24px"
/>
}
<
Flex
alignItems=
"center"
columnGap=
{
8
}
display=
{
{
base
:
'
none
'
,
lg
:
'
flex
'
}
}
>
{
statsQuery
.
data
?.
network_utilization_percentage
!==
undefined
&&
(
<
Box
>
<
Text
as=
"span"
fontSize=
"sm"
>
Network utilization (last 50 blocks):
{
nbsp
}
</
Text
>
<
Text
as=
"span"
fontSize=
"sm"
color=
"blue.400"
fontWeight=
{
600
}
>
{
statsQuery
.
data
.
network_utilization_percentage
.
toFixed
(
2
)
}
%
</
Text
>
<
Skeleton
display=
"inline-block"
fontSize=
"sm"
color=
"blue.400"
fontWeight=
{
600
}
isLoaded=
{
!
statsQuery
.
isPlaceholderData
}
>
<
span
>
{
statsQuery
.
data
.
network_utilization_percentage
.
toFixed
(
2
)
}
%
</
span
>
</
Skeleton
>
</
Box
>
)
}
{
isPaginationVisible
&&
<
Pagination
my=
{
1
}
{
...
pagination
}
/>
}
...
...
ui/blocks/BlocksTable.tsx
View file @
34ce2914
...
...
@@ -36,7 +36,7 @@ const BlocksTable = ({ data, isLoading, top, page }: Props) => {
<
AnimatePresence
initial=
{
false
}
>
{
data
.
map
((
item
,
index
)
=>
(
<
BlocksTableItem
key=
{
item
.
height
+
(
isLoading
?
String
(
index
)
:
''
)
}
key=
{
item
.
height
+
(
isLoading
?
`${ index }_${ page }`
:
''
)
}
data=
{
item
}
enableTimeIncrement=
{
page
===
1
&&
!
isLoading
}
isLoading=
{
isLoading
}
...
...
ui/shared/Pagination.tsx
View file @
34ce2914
import
{
Button
,
Flex
,
Icon
,
IconButton
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
Button
,
Skeleton
,
Flex
,
Icon
,
IconButton
,
chakra
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
arrowIcon
from
'
icons/arrows/east-mini.svg
'
;
...
...
@@ -11,9 +11,10 @@ export type Props = {
hasNextPage
:
boolean
;
className
?:
string
;
canGoBackwards
:
boolean
;
isLoading
?:
boolean
;
}
const
Pagination
=
({
page
,
onNextPageClick
,
onPrevPageClick
,
resetPage
,
hasNextPage
,
className
,
canGoBackwards
}:
Props
)
=>
{
const
Pagination
=
({
page
,
onNextPageClick
,
onPrevPageClick
,
resetPage
,
hasNextPage
,
className
,
canGoBackwards
,
isLoading
}:
Props
)
=>
{
return
(
<
Flex
...
...
@@ -21,15 +22,17 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
fontSize=
"sm"
alignItems=
"center"
>
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
mr=
{
4
}
borderRadius=
"base"
>
<
Button
variant=
"outline"
size=
"sm"
onClick=
{
resetPage
}
isDisabled=
{
page
===
1
}
mr=
{
4
}
>
First
</
Button
>
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
mr=
{
3
}
borderRadius=
"base"
>
<
IconButton
variant=
"outline"
onClick=
{
onPrevPageClick
}
...
...
@@ -37,9 +40,10 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
aria
-
label=
"Next page"
w=
"36px"
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
/>
}
mr=
{
3
}
isDisabled=
{
!
canGoBackwards
||
page
===
1
}
/>
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
borderRadius=
"base"
>
<
Button
variant=
"outline"
size=
"sm"
...
...
@@ -51,6 +55,8 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
>
{
page
}
</
Button
>
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
ml=
{
3
}
borderRadius=
"base"
>
<
IconButton
variant=
"outline"
onClick=
{
onNextPageClick
}
...
...
@@ -58,9 +64,9 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
aria
-
label=
"Next page"
w=
"36px"
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
transform=
"rotate(180deg)"
/>
}
ml=
{
3
}
isDisabled=
{
!
hasNextPage
}
/>
</
Skeleton
>
{
/* not implemented yet */
}
{
/* <Flex alignItems="center" width="132px" ml={ 16 } display={{ base: 'none', lg: 'flex' }}>
Go to <Input w="84px" size="xs" ml={ 2 }/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment