Ameliorate homepage search spam (#564)
* Don't recompute search filters when follows loaded unnecessarily * Don't wait for router to get saved search sort
This commit is contained in:
parent
4f9e303daa
commit
603bec9e88
|
@ -116,8 +116,8 @@ export function ContractSearch(props: {
|
|||
showCategorySelector,
|
||||
mode,
|
||||
Object.values(additionalFilter ?? {}).join(','),
|
||||
followedCategories?.join(','),
|
||||
follows?.join(','),
|
||||
(followedCategories ?? []).join(','),
|
||||
(follows ?? []).join(','),
|
||||
])
|
||||
|
||||
const indexName = `${indexPrefix}contracts-${sort}`
|
||||
|
|
|
@ -20,6 +20,16 @@ export function checkAgainstQuery(query: string, corpus: string) {
|
|||
return queryWords.every((word) => corpus.toLowerCase().includes(word))
|
||||
}
|
||||
|
||||
export function getSavedSort() {
|
||||
// TODO: this obviously doesn't work with SSR, common sense would suggest
|
||||
// that we should save things like this in cookies so the server has them
|
||||
if (typeof window !== 'undefined') {
|
||||
return localStorage.getItem(MARKETS_SORT) as Sort | null
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function useInitialQueryAndSort(options?: {
|
||||
defaultSort: Sort
|
||||
shouldLoadFromStorage?: boolean
|
||||
|
@ -45,7 +55,7 @@ export function useInitialQueryAndSort(options?: {
|
|||
|
||||
if (!sort && shouldLoadFromStorage) {
|
||||
console.log('ready loading from storage ', sort ?? defaultSort)
|
||||
const localSort = localStorage.getItem(MARKETS_SORT) as Sort
|
||||
const localSort = getSavedSort()
|
||||
if (localSort) {
|
||||
router.query.s = localSort
|
||||
// Use replace to not break navigating back.
|
||||
|
|
|
@ -5,6 +5,7 @@ import { PlusSmIcon } from '@heroicons/react/solid'
|
|||
import { Page } from 'web/components/page'
|
||||
import { Col } from 'web/components/layout/col'
|
||||
import { useUser } from 'web/hooks/use-user'
|
||||
import { getSavedSort } from 'web/hooks/use-sort-and-query-params'
|
||||
import { ContractSearch } from 'web/components/contract-search'
|
||||
import { Contract } from 'common/contract'
|
||||
import { ContractPageContent } from './[username]/[contractSlug]'
|
||||
|
@ -17,7 +18,6 @@ const Home = () => {
|
|||
const [contract, setContract] = useContractPage()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useTracking('view home')
|
||||
|
||||
if (user === null) {
|
||||
|
@ -32,7 +32,7 @@ const Home = () => {
|
|||
<ContractSearch
|
||||
querySortOptions={{
|
||||
shouldLoadFromStorage: true,
|
||||
defaultSort: '24-hour-vol',
|
||||
defaultSort: getSavedSort() ?? '24-hour-vol',
|
||||
}}
|
||||
showCategorySelector
|
||||
onContractClick={(c) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user