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:
parent
12567074cc
commit
61cbb07bd5
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user