Fix some broken stuff on the homepage contract search routing (#664)

* Use Next router more appropriately

* Replace instead of push when modifying search query params
This commit is contained in:
Marshall Polaris 2022-07-19 12:33:53 -07:00 committed by GitHub
parent 12567074cc
commit 61cbb07bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,9 +53,12 @@ export function useInitialQueryAndSort(options?: {
console.log('ready loading from storage ', sort ?? defaultSort) console.log('ready loading from storage ', sort ?? defaultSort)
const localSort = getSavedSort() const localSort = getSavedSort()
if (localSort) { if (localSort) {
router.query.s = localSort
// Use replace to not break navigating back. // Use replace to not break navigating back.
router.replace(router, undefined, { shallow: true }) router.replace(
{ query: { ...router.query, s: localSort } },
undefined,
{ shallow: true }
)
} }
setInitialSort(localSort ?? defaultSort) setInitialSort(localSort ?? defaultSort)
} else { } else {
@ -79,7 +82,9 @@ export function useUpdateQueryAndSort(props: {
const setSort = (sort: Sort | undefined) => { const setSort = (sort: Sort | undefined) => {
if (sort !== router.query.s) { if (sort !== router.query.s) {
router.query.s = sort router.query.s = sort
router.push(router, undefined, { shallow: true }) router.replace({ query: { ...router.query, s: sort } }, undefined, {
shallow: true,
})
if (shouldLoadFromStorage) { if (shouldLoadFromStorage) {
localStorage.setItem(MARKETS_SORT, sort || '') localStorage.setItem(MARKETS_SORT, sort || '')
} }
@ -97,7 +102,9 @@ export function useUpdateQueryAndSort(props: {
} else { } else {
delete router.query.q delete router.query.q
} }
router.push(router, undefined, { shallow: true }) router.replace({ query: router.query }, undefined, {
shallow: true,
})
track('search', { query }) track('search', { query })
}, 500), }, 500),
[router] [router]