-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f01c2e9
commit 94e5160
Showing
3 changed files
with
57 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use client' | ||
|
||
import { useAppRouter, usePathname, useSearchParams } from '@siafoundation/next' | ||
import { useCallback } from 'react' | ||
|
||
export type ServerFilterItem = { | ||
id: string | ||
label: string | ||
value?: string | ||
values?: string[] | ||
bool?: boolean | ||
} | ||
|
||
export function useResetPagination() { | ||
const router = useAppRouter() | ||
const pathname = usePathname() | ||
const searchParams = useSearchParams() | ||
|
||
return useCallback(() => { | ||
// These can be undefined when the page is still initializing | ||
if (!router || !pathname) { | ||
return | ||
} | ||
// remove any limit, offset, or marker | ||
const query = new URLSearchParams(searchParams) | ||
const currParams = query.toString() | ||
query.delete('limit') | ||
query.delete('offset') | ||
query.delete('marker') | ||
const nextParams = query.toString() | ||
const currPath = currParams ? `${pathname}?${currParams}` : pathname | ||
const nextPath = nextParams ? `${pathname}?${nextParams}` : pathname | ||
if (nextPath !== currPath) { | ||
router.replace(nextPath) | ||
} | ||
}, [router, searchParams, pathname]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters