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
b274a4f2
Commit
b274a4f2
authored
Dec 12, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some pagination bug
parent
8e14571e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
useQueryWithPages.ts
lib/hooks/useQueryWithPages.ts
+11
-5
No files found.
lib/hooks/useQueryWithPages.ts
View file @
b274a4f2
...
...
@@ -73,7 +73,7 @@ export default function useQueryWithPages<QueryName extends PaginatedQueryKeys>(
const
onPrevPageClick
=
useCallback
(()
=>
{
// returning to the first page
// we dont have pagination params for the first page
let
nextPageQuery
:
typeof
router
.
query
=
{};
let
nextPageQuery
:
typeof
router
.
query
=
{
...
router
.
query
};
if
(
page
===
2
)
{
nextPageQuery
=
omit
(
router
.
query
,
paginationFields
,
'
page
'
);
canGoBackwards
.
current
=
true
;
...
...
@@ -87,19 +87,25 @@ export default function useQueryWithPages<QueryName extends PaginatedQueryKeys>(
.
then
(()
=>
{
animateScroll
.
scrollToTop
({
duration
:
0
});
setPage
(
prev
=>
prev
-
1
);
page
===
2
&&
queryClient
.
clear
(
);
page
===
2
&&
queryClient
.
removeQueries
({
queryKey
:
[
queryName
]
}
);
});
},
[
router
,
page
,
paginationFields
,
pageParams
,
queryClient
]);
},
[
router
,
page
,
paginationFields
,
pageParams
,
queryClient
,
queryName
]);
const
resetPage
=
useCallback
(()
=>
{
queryClient
.
clear
();
queryClient
.
removeQueries
({
queryKey
:
[
queryName
]
});
router
.
push
({
pathname
:
router
.
pathname
,
query
:
omit
(
router
.
query
,
paginationFields
,
'
page
'
)
},
undefined
,
{
shallow
:
true
}).
then
(()
=>
{
animateScroll
.
scrollToTop
({
duration
:
0
});
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 :)
queryClient
.
removeQueries
({
queryKey
:
[
queryName
],
type
:
'
inactive
'
});
},
100
);
});
},
[
queryClient
,
router
,
paginationFields
]);
},
[
queryClient
,
queryName
,
router
,
paginationFields
]);
const
hasPaginationParams
=
Object
.
keys
(
currPageParams
).
length
>
0
;
const
nextPageParams
=
data
?.
next_page_params
;
...
...
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