forked from code100x/job-board
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated-filters * removed jobFilterQuery action * provided key to suspense to make it work * minmal changes --------- Co-authored-by: aakash singh <[email protected]>
- Loading branch information
1 parent
5558796
commit 0401a3b
Showing
11 changed files
with
96 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,5 @@ next-env.d.ts | |
pnpm-lock.yaml | ||
bun.lockb | ||
package-lock.json | ||
yarn.lock | ||
yarn.lock | ||
|
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
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
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
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,29 @@ | ||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | ||
import _ from 'lodash'; | ||
import { useCallback } from 'react'; | ||
import { debounce } from 'lodash'; | ||
|
||
//pass in key value pairs to update query params | ||
export default function useSetQueryParams() { | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
const pathName = usePathname(); | ||
|
||
const updateQueryParams = useCallback( | ||
debounce((params) => { | ||
const newSearchParams = new URLSearchParams(searchParams?.toString()); | ||
for (const [key, value] of Object.entries(params)) { | ||
//isEmpty reads number as empty too | ||
if (_.isEmpty(value) && typeof value !== 'number') { | ||
newSearchParams.delete(key); | ||
} else { | ||
newSearchParams.set(key, String(value)); | ||
} | ||
} | ||
router.push(`${pathName}?${newSearchParams}`, { scroll: false }); | ||
}, 300), // 300ms debounce | ||
[router, searchParams, pathName] | ||
); | ||
|
||
return updateQueryParams; | ||
} |
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
Oops, something went wrong.