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,
|
showCategorySelector,
|
||||||
mode,
|
mode,
|
||||||
Object.values(additionalFilter ?? {}).join(','),
|
Object.values(additionalFilter ?? {}).join(','),
|
||||||
followedCategories?.join(','),
|
(followedCategories ?? []).join(','),
|
||||||
follows?.join(','),
|
(follows ?? []).join(','),
|
||||||
])
|
])
|
||||||
|
|
||||||
const indexName = `${indexPrefix}contracts-${sort}`
|
const indexName = `${indexPrefix}contracts-${sort}`
|
||||||
|
|
|
@ -20,6 +20,16 @@ export function checkAgainstQuery(query: string, corpus: string) {
|
||||||
return queryWords.every((word) => corpus.toLowerCase().includes(word))
|
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?: {
|
export function useInitialQueryAndSort(options?: {
|
||||||
defaultSort: Sort
|
defaultSort: Sort
|
||||||
shouldLoadFromStorage?: boolean
|
shouldLoadFromStorage?: boolean
|
||||||
|
@ -45,7 +55,7 @@ export function useInitialQueryAndSort(options?: {
|
||||||
|
|
||||||
if (!sort && shouldLoadFromStorage) {
|
if (!sort && shouldLoadFromStorage) {
|
||||||
console.log('ready loading from storage ', sort ?? defaultSort)
|
console.log('ready loading from storage ', sort ?? defaultSort)
|
||||||
const localSort = localStorage.getItem(MARKETS_SORT) as Sort
|
const localSort = getSavedSort()
|
||||||
if (localSort) {
|
if (localSort) {
|
||||||
router.query.s = localSort
|
router.query.s = localSort
|
||||||
// Use replace to not break navigating back.
|
// Use replace to not break navigating back.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { PlusSmIcon } from '@heroicons/react/solid'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
import { Col } from 'web/components/layout/col'
|
import { Col } from 'web/components/layout/col'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
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 { ContractSearch } from 'web/components/contract-search'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { ContractPageContent } from './[username]/[contractSlug]'
|
import { ContractPageContent } from './[username]/[contractSlug]'
|
||||||
|
@ -17,7 +18,6 @@ const Home = () => {
|
||||||
const [contract, setContract] = useContractPage()
|
const [contract, setContract] = useContractPage()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
useTracking('view home')
|
useTracking('view home')
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
|
@ -32,7 +32,7 @@ const Home = () => {
|
||||||
<ContractSearch
|
<ContractSearch
|
||||||
querySortOptions={{
|
querySortOptions={{
|
||||||
shouldLoadFromStorage: true,
|
shouldLoadFromStorage: true,
|
||||||
defaultSort: '24-hour-vol',
|
defaultSort: getSavedSort() ?? '24-hour-vol',
|
||||||
}}
|
}}
|
||||||
showCategorySelector
|
showCategorySelector
|
||||||
onContractClick={(c) => {
|
onContractClick={(c) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user