Use sort linked in the url and not saved sort.

This commit is contained in:
James Grugett 2022-03-19 11:34:22 -05:00
parent ae0cb4fc8c
commit a3c72214b8

View File

@ -21,6 +21,7 @@ export function useQueryAndSortParams(options?: {
shouldLoadFromStorage?: boolean shouldLoadFromStorage?: boolean
}) { }) {
const { defaultSort, shouldLoadFromStorage } = _.defaults(options, { const { defaultSort, shouldLoadFromStorage } = _.defaults(options, {
defaultSort: '24-hour-vol',
shouldLoadFromStorage: true, shouldLoadFromStorage: true,
}) })
const router = useRouter() const router = useRouter()
@ -65,7 +66,7 @@ export function useQueryAndSortParams(options?: {
useEffect(() => { useEffect(() => {
// If there's no sort option, then set the one from localstorage // If there's no sort option, then set the one from localstorage
if (!sort && shouldLoadFromStorage) { if (router.isReady && !sort && shouldLoadFromStorage) {
const localSort = localStorage.getItem(MARKETS_SORT) as Sort const localSort = localStorage.getItem(MARKETS_SORT) as Sort
if (localSort) { if (localSort) {
setSort(localSort) setSort(localSort)
@ -74,7 +75,7 @@ export function useQueryAndSortParams(options?: {
}) })
return { return {
sort: sort ?? defaultSort ?? '24-hour-vol', sort: sort ?? defaultSort,
query: queryState ?? '', query: queryState ?? '',
setSort, setSort,
setQuery, setQuery,