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
Hide 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>({
...
@@ -158,6 +158,7 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
resetPage
,
resetPage
,
hasNextPage
:
nextPageParams
?
Object
.
keys
(
nextPageParams
).
length
>
0
:
false
,
hasNextPage
:
nextPageParams
?
Object
.
keys
(
nextPageParams
).
length
>
0
:
false
,
canGoBackwards
:
canGoBackwards
.
current
,
canGoBackwards
:
canGoBackwards
.
current
,
isLoading
:
queryResult
.
isPlaceholderData
&&
!
hasPagination
,
};
};
const
isPaginationVisible
=
hasPagination
||
(
!
queryResult
.
isLoading
&&
!
queryResult
.
isError
&&
pagination
.
hasNextPage
);
const
isPaginationVisible
=
hasPagination
||
(
!
queryResult
.
isLoading
&&
!
queryResult
.
isError
&&
pagination
.
hasNextPage
);
...
...
mocks/blocks/block.ts
View file @
34ce2914
...
@@ -47,6 +47,7 @@ export const base: Block = {
...
@@ -47,6 +47,7 @@ export const base: Block = {
tx_fees
:
'
26853607500000000
'
,
tx_fees
:
'
26853607500000000
'
,
type
:
'
block
'
,
type
:
'
block
'
,
uncles_hashes
:
[],
uncles_hashes
:
[],
has_beacon_chain_withdrawals
:
false
,
};
};
export
const
genesis
:
Block
=
{
export
const
genesis
:
Block
=
{
...
@@ -83,6 +84,7 @@ export const genesis: Block = {
...
@@ -83,6 +84,7 @@ export const genesis: Block = {
tx_fees
:
'
0
'
,
tx_fees
:
'
0
'
,
type
:
'
block
'
,
type
:
'
block
'
,
uncles_hashes
:
[],
uncles_hashes
:
[],
has_beacon_chain_withdrawals
:
false
,
};
};
export
const
base2
:
Block
=
{
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 = {
...
@@ -8,7 +8,7 @@ export type HomeStats = {
transactions_today
:
string
;
transactions_today
:
string
;
gas_used_today
:
string
;
gas_used_today
:
string
;
gas_prices
:
GasPrices
|
null
;
gas_prices
:
GasPrices
|
null
;
static_gas_price
:
string
;
static_gas_price
:
string
|
null
;
market_cap
:
string
;
market_cap
:
string
;
network_utilization_percentage
:
number
;
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
type
{
UseQueryResult
}
from
'
@tanstack/react-query
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -77,12 +77,12 @@ const BlocksContent = ({ type, query }: Props) => {
...
@@ -77,12 +77,12 @@ const BlocksContent = ({ type, query }: Props) => {
const
content
=
query
.
data
?.
items
?
(
const
content
=
query
.
data
?.
items
?
(
<>
<>
{
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"
ssr=
{
false
}
>
<
Box
display=
{
{
base
:
'
block
'
,
lg
:
'
none
'
}
}
>
<
BlocksList
data=
{
query
.
data
.
items
}
isLoading=
{
query
.
isPlaceholderData
}
page=
{
query
.
pagination
.
page
}
/>
<
BlocksList
data=
{
query
.
data
.
items
}
isLoading=
{
query
.
isPlaceholderData
}
page=
{
query
.
pagination
.
page
}
/>
</
Show
>
</
Box
>
<
Hide
below=
"lg"
key=
"content-desktop"
ssr=
{
false
}
>
<
Box
display=
{
{
base
:
'
none
'
,
lg
:
'
block
'
}
}
>
<
BlocksTable
data=
{
query
.
data
.
items
}
top=
{
query
.
isPaginationVisible
?
80
:
0
}
page=
{
query
.
pagination
.
page
}
isLoading=
{
query
.
isPlaceholderData
}
/>
<
BlocksTable
data=
{
query
.
data
.
items
}
top=
{
query
.
isPaginationVisible
?
80
:
0
}
page=
{
query
.
pagination
.
page
}
isLoading=
{
query
.
isPlaceholderData
}
/>
</
Hide
>
</
Box
>
</>
</>
)
:
null
;
)
:
null
;
...
...
ui/blocks/BlocksTabSlot.tsx
View file @
34ce2914
...
@@ -2,8 +2,8 @@ import { Flex, Box, Text, Skeleton } from '@chakra-ui/react';
...
@@ -2,8 +2,8 @@ import { Flex, Box, Text, Skeleton } from '@chakra-ui/react';
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
nbsp
}
from
'
lib/html-entities
'
;
import
{
nbsp
}
from
'
lib/html-entities
'
;
import
{
HOMEPAGE_STATS
}
from
'
stubs/stats
'
;
import
type
{
Props
as
PaginationProps
}
from
'
ui/shared/Pagination
'
;
import
type
{
Props
as
PaginationProps
}
from
'
ui/shared/Pagination
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
import
Pagination
from
'
ui/shared/Pagination
'
;
...
@@ -13,24 +13,22 @@ interface Props {
...
@@ -13,24 +13,22 @@ interface Props {
}
}
const
BlocksTabSlot
=
({
pagination
,
isPaginationVisible
}:
Props
)
=>
{
const
BlocksTabSlot
=
({
pagination
,
isPaginationVisible
}:
Props
)
=>
{
const
isMobile
=
useIsMobile
();
const
statsQuery
=
useApiQuery
(
'
homepage_stats
'
,
{
const
statsQuery
=
useApiQuery
(
'
homepage_stats
'
);
queryOptions
:
{
placeholderData
:
HOMEPAGE_STATS
,
if
(
isMobile
)
{
},
return
null
;
});
}
return
(
return
(
<
Flex
alignItems=
"center"
columnGap=
{
8
}
>
<
Flex
alignItems=
"center"
columnGap=
{
8
}
display=
{
{
base
:
'
none
'
,
lg
:
'
flex
'
}
}
>
{
statsQuery
.
isLoading
&&
<
Skeleton
w=
"175px"
h=
"24px"
/>
}
{
statsQuery
.
data
?.
network_utilization_percentage
!==
undefined
&&
(
{
statsQuery
.
data
?.
network_utilization_percentage
!==
undefined
&&
(
<
Box
>
<
Box
>
<
Text
as=
"span"
fontSize=
"sm"
>
<
Text
as=
"span"
fontSize=
"sm"
>
Network utilization (last 50 blocks):
{
nbsp
}
Network utilization (last 50 blocks):
{
nbsp
}
</
Text
>
</
Text
>
<
Text
as=
"span"
fontSize=
"sm"
color=
"blue.400"
fontWeight=
{
600
}
>
<
Skeleton
display=
"inline-block"
fontSize=
"sm"
color=
"blue.400"
fontWeight=
{
600
}
isLoaded=
{
!
statsQuery
.
isPlaceholderData
}
>
{
statsQuery
.
data
.
network_utilization_percentage
.
toFixed
(
2
)
}
%
<
span
>
{
statsQuery
.
data
.
network_utilization_percentage
.
toFixed
(
2
)
}
%
</
span
>
</
Text
>
</
Skeleton
>
</
Box
>
</
Box
>
)
}
)
}
{
isPaginationVisible
&&
<
Pagination
my=
{
1
}
{
...
pagination
}
/>
}
{
isPaginationVisible
&&
<
Pagination
my=
{
1
}
{
...
pagination
}
/>
}
...
...
ui/blocks/BlocksTable.tsx
View file @
34ce2914
...
@@ -36,7 +36,7 @@ const BlocksTable = ({ data, isLoading, top, page }: Props) => {
...
@@ -36,7 +36,7 @@ const BlocksTable = ({ data, isLoading, top, page }: Props) => {
<
AnimatePresence
initial=
{
false
}
>
<
AnimatePresence
initial=
{
false
}
>
{
data
.
map
((
item
,
index
)
=>
(
{
data
.
map
((
item
,
index
)
=>
(
<
BlocksTableItem
<
BlocksTableItem
key=
{
item
.
height
+
(
isLoading
?
String
(
index
)
:
''
)
}
key=
{
item
.
height
+
(
isLoading
?
`${ index }_${ page }`
:
''
)
}
data=
{
item
}
data=
{
item
}
enableTimeIncrement=
{
page
===
1
&&
!
isLoading
}
enableTimeIncrement=
{
page
===
1
&&
!
isLoading
}
isLoading=
{
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
React
from
'
react
'
;
import
arrowIcon
from
'
icons/arrows/east-mini.svg
'
;
import
arrowIcon
from
'
icons/arrows/east-mini.svg
'
;
...
@@ -11,9 +11,10 @@ export type Props = {
...
@@ -11,9 +11,10 @@ export type Props = {
hasNextPage
:
boolean
;
hasNextPage
:
boolean
;
className
?:
string
;
className
?:
string
;
canGoBackwards
:
boolean
;
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
(
return
(
<
Flex
<
Flex
...
@@ -21,46 +22,51 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
...
@@ -21,46 +22,51 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasNext
fontSize=
"sm"
fontSize=
"sm"
alignItems=
"center"
alignItems=
"center"
>
>
<
Button
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
mr=
{
4
}
borderRadius=
"base"
>
variant=
"outline"
<
Button
size=
"sm
"
variant=
"outline
"
onClick=
{
resetPage
}
size=
"sm"
isDisabled=
{
page
===
1
}
onClick=
{
resetPage
}
mr=
{
4
}
isDisabled=
{
page
===
1
}
>
>
First
First
</
Button
>
</
Button
>
<
IconButton
</
Skeleton
>
variant=
"outline"
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
mr=
{
3
}
borderRadius=
"base"
>
onClick=
{
onPrevPageClick
}
<
IconButton
size=
"sm"
variant=
"outline"
aria
-
label=
"Next page"
onClick=
{
onPrevPageClick
}
w=
"36px"
size=
"sm"
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
/>
}
aria
-
label=
"Next page"
mr=
{
3
}
w=
"36px"
isDisabled=
{
!
canGoBackwards
||
page
===
1
}
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
/>
}
/>
isDisabled=
{
!
canGoBackwards
||
page
===
1
}
<
Button
/>
variant=
"outline"
</
Skeleton
>
size=
"sm"
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
borderRadius=
"base"
>
isActive
<
Button
borderWidth=
"1px"
variant=
"outline"
fontWeight=
{
400
}
size=
"sm"
h=
{
8
}
isActive
cursor=
"unset"
borderWidth=
"1px"
>
fontWeight=
{
400
}
{
page
}
h=
{
8
}
</
Button
>
cursor=
"unset"
<
IconButton
>
variant=
"outline"
{
page
}
onClick=
{
onNextPageClick
}
</
Button
>
size=
"sm"
</
Skeleton
>
aria
-
label=
"Next page"
<
Skeleton
isLoaded=
{
!
isLoading
}
display=
"inline-block"
ml=
{
3
}
borderRadius=
"base"
>
w=
"36px"
<
IconButton
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
transform=
"rotate(180deg)"
/>
}
variant=
"outline"
ml=
{
3
}
onClick=
{
onNextPageClick
}
isDisabled=
{
!
hasNextPage
}
size=
"sm"
/>
aria
-
label=
"Next page"
w=
"36px"
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
transform=
"rotate(180deg)"
/>
}
isDisabled=
{
!
hasNextPage
}
/>
</
Skeleton
>
{
/* not implemented yet */
}
{
/* not implemented yet */
}
{
/* <Flex alignItems="center" width="132px" ml={ 16 } display={{ base: 'none', lg: 'flex' }}>
{
/* <Flex alignItems="center" width="132px" ml={ 16 } display={{ base: 'none', lg: 'flex' }}>
Go to <Input w="84px" size="xs" ml={ 2 }/>
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