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
fe5bb8b2
Unverified
Commit
fe5bb8b2
authored
Dec 18, 2023
by
Igor Stuev
Committed by
GitHub
Dec 18, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1409 from blockscout/fe-1388
fix canGoBackwards
parents
185707bb
db2930c2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
12 deletions
+9
-12
Pagination.tsx
ui/shared/pagination/Pagination.tsx
+1
-1
useQueryWithPages.test.tsx
ui/shared/pagination/useQueryWithPages.test.tsx
+7
-7
useQueryWithPages.ts
ui/shared/pagination/useQueryWithPages.ts
+1
-4
No files found.
ui/shared/pagination/Pagination.tsx
View file @
fe5bb8b2
...
...
@@ -41,7 +41,7 @@ const Pagination = ({ page, onNextPageClick, onPrevPageClick, resetPage, hasPage
aria
-
label=
"Prev page"
w=
"36px"
icon=
{
<
Icon
as=
{
arrowIcon
}
w=
{
5
}
h=
{
5
}
/>
}
isDisabled=
{
!
canGoBackwards
||
page
===
1
||
isLoading
}
isDisabled=
{
!
canGoBackwards
||
isLoading
}
/>
</
Skeleton
>
<
Skeleton
isLoaded=
{
!
showSkeleton
}
display=
"inline-block"
borderRadius=
"base"
>
...
...
ui/shared/pagination/useQueryWithPages.test.tsx
View file @
fe5bb8b2
...
...
@@ -68,7 +68,7 @@ it('returns correct data if there is only one page', async() => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_empty
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
false
,
isLoading
:
false
,
isVisible
:
false
,
...
...
@@ -91,7 +91,7 @@ describe('if there are multiple pages', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_1
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
true
,
isLoading
:
false
,
isVisible
:
true
,
...
...
@@ -258,7 +258,7 @@ describe('if there are multiple pages', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_1
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
true
,
isLoading
:
false
,
isVisible
:
true
,
...
...
@@ -310,7 +310,7 @@ describe('if there are multiple pages', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_1
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
true
,
isLoading
:
false
,
isVisible
:
true
,
...
...
@@ -404,7 +404,7 @@ describe('if there is page query param in URL', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_3
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
3
,
canGoBackwards
:
fals
e
,
canGoBackwards
:
tru
e
,
hasNextPage
:
false
,
isLoading
:
false
,
isVisible
:
true
,
...
...
@@ -458,7 +458,7 @@ describe('queries with filters', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_filtered
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
true
,
isLoading
:
false
,
isVisible
:
true
,
...
...
@@ -547,7 +547,7 @@ describe('queries with sorting', () => {
expect
(
result
.
current
.
data
).
toEqual
(
responses
.
page_sorted
);
expect
(
result
.
current
.
pagination
).
toMatchObject
({
page
:
1
,
canGoBackwards
:
tru
e
,
canGoBackwards
:
fals
e
,
hasNextPage
:
false
,
isLoading
:
false
,
isVisible
:
false
,
...
...
ui/shared/pagination/useQueryWithPages.ts
View file @
fe5bb8b2
...
...
@@ -61,7 +61,6 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
const
[
hasPages
,
setHasPages
]
=
React
.
useState
(
page
>
1
);
const
isMounted
=
React
.
useRef
(
false
);
const
canGoBackwards
=
React
.
useRef
(
!
router
.
query
.
page
);
const
queryParams
=
{
...
pageParams
[
page
],
...
filters
,
...
sorting
};
const
scrollToTop
=
useCallback
(()
=>
{
...
...
@@ -107,7 +106,6 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
let
nextPageQuery
:
typeof
router
.
query
=
{
...
router
.
query
};
if
(
page
===
2
)
{
nextPageQuery
=
omit
(
router
.
query
,
[
'
next_page_params
'
,
'
page
'
]);
canGoBackwards
.
current
=
true
;
}
else
{
nextPageQuery
.
next_page_params
=
encodeURIComponent
(
JSON
.
stringify
(
pageParams
[
page
-
1
]));
nextPageQuery
.
page
=
String
(
page
-
1
);
...
...
@@ -130,7 +128,6 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
queryClient
.
removeQueries
({
queryKey
:
[
resourceName
]
});
setPage
(
1
);
setPageParams
({});
canGoBackwards
.
current
=
true
;
window
.
setTimeout
(()
=>
{
// FIXME after router is updated we still have inactive queries for previously visited page (e.g third), where we came from
// so have to remove it but with some delay :)
...
...
@@ -193,7 +190,7 @@ export default function useQueryWithPages<Resource extends PaginatedResources>({
resetPage
,
hasPages
,
hasNextPage
,
canGoBackwards
:
canGoBackwards
.
current
,
canGoBackwards
:
Boolean
(
pageParams
[
page
-
1
])
,
isLoading
:
queryResult
.
isPlaceholderData
,
isVisible
:
hasPages
||
hasNextPage
,
};
...
...
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