Fix browser redirect warning
This commit is contained in:
parent
ab6b826530
commit
f74be9a491
|
@ -2,7 +2,11 @@
|
||||||
import algoliasearch from 'algoliasearch/lite'
|
import algoliasearch from 'algoliasearch/lite'
|
||||||
|
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { Sort, useQueryAndSortParams } from '../hooks/use-sort-and-query-params'
|
import {
|
||||||
|
QuerySortOptions,
|
||||||
|
Sort,
|
||||||
|
useQueryAndSortParams,
|
||||||
|
} from '../hooks/use-sort-and-query-params'
|
||||||
import {
|
import {
|
||||||
ContractHighlightOptions,
|
ContractHighlightOptions,
|
||||||
ContractsGrid,
|
ContractsGrid,
|
||||||
|
@ -45,11 +49,7 @@ export const DEFAULT_SORT = 'score'
|
||||||
type filter = 'personal' | 'open' | 'closed' | 'resolved' | 'all'
|
type filter = 'personal' | 'open' | 'closed' | 'resolved' | 'all'
|
||||||
|
|
||||||
export function ContractSearch(props: {
|
export function ContractSearch(props: {
|
||||||
querySortOptions?: {
|
querySortOptions?: { defaultFilter?: filter } & QuerySortOptions
|
||||||
defaultSort: Sort
|
|
||||||
defaultFilter?: filter
|
|
||||||
shouldLoadFromStorage?: boolean
|
|
||||||
}
|
|
||||||
additionalFilter?: {
|
additionalFilter?: {
|
||||||
creatorId?: string
|
creatorId?: string
|
||||||
tag?: string
|
tag?: string
|
||||||
|
@ -100,11 +100,8 @@ export function ContractSearch(props: {
|
||||||
|
|
||||||
const follows = useFollows(user?.id)
|
const follows = useFollows(user?.id)
|
||||||
|
|
||||||
const { shouldLoadFromStorage, defaultSort } = querySortOptions ?? {}
|
const { query, setQuery, sort, setSort } =
|
||||||
const { query, setQuery, sort, setSort } = useQueryAndSortParams({
|
useQueryAndSortParams(querySortOptions)
|
||||||
defaultSort,
|
|
||||||
shouldLoadFromStorage,
|
|
||||||
})
|
|
||||||
|
|
||||||
const [filter, setFilter] = useState<filter>(
|
const [filter, setFilter] = useState<filter>(
|
||||||
querySortOptions?.defaultFilter ?? 'open'
|
querySortOptions?.defaultFilter ?? 'open'
|
||||||
|
|
|
@ -76,6 +76,7 @@ export function MarketModal(props: {
|
||||||
}
|
}
|
||||||
showPlaceHolder
|
showPlaceHolder
|
||||||
cardHideOptions={{ hideGroupLink: true, hideQuickBet: true }}
|
cardHideOptions={{ hideGroupLink: true, hideQuickBet: true }}
|
||||||
|
querySortOptions={{ disableQueryString: true }}
|
||||||
highlightOptions={{
|
highlightOptions={{
|
||||||
contractIds: contracts.map((c) => c.id),
|
contractIds: contracts.map((c) => c.id),
|
||||||
highlightClassName:
|
highlightClassName:
|
||||||
|
|
|
@ -25,12 +25,18 @@ export function getSavedSort() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useQueryAndSortParams(options?: {
|
export interface QuerySortOptions {
|
||||||
defaultSort?: Sort
|
defaultSort?: Sort
|
||||||
shouldLoadFromStorage?: boolean
|
shouldLoadFromStorage?: boolean
|
||||||
}) {
|
/** Use normal react state instead of url query string */
|
||||||
const { defaultSort = DEFAULT_SORT, shouldLoadFromStorage = true } =
|
disableQueryString?: boolean
|
||||||
options ?? {}
|
}
|
||||||
|
|
||||||
|
export function useQueryAndSortParams({
|
||||||
|
defaultSort = DEFAULT_SORT,
|
||||||
|
shouldLoadFromStorage = true,
|
||||||
|
disableQueryString,
|
||||||
|
}: QuerySortOptions = {}) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const { s: sort, q: query } = router.query as {
|
const { s: sort, q: query } = router.query as {
|
||||||
|
@ -68,7 +74,9 @@ export function useQueryAndSortParams(options?: {
|
||||||
|
|
||||||
const setQuery = (query: string | undefined) => {
|
const setQuery = (query: string | undefined) => {
|
||||||
setQueryState(query)
|
setQueryState(query)
|
||||||
pushQuery(query)
|
if (!disableQueryString) {
|
||||||
|
pushQuery(query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -86,10 +94,13 @@ export function useQueryAndSortParams(options?: {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// use normal state if querydisableQueryString
|
||||||
|
const [sortState, setSortState] = useState(defaultSort)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sort: sort ?? defaultSort,
|
sort: disableQueryString ? sortState : sort ?? defaultSort,
|
||||||
query: queryState ?? '',
|
query: queryState ?? '',
|
||||||
setSort,
|
setSort: disableQueryString ? setSortState : setSort,
|
||||||
setQuery,
|
setQuery,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { sortBy } from 'lodash'
|
||||||
import { ContractsGrid } from 'web/components/contract/contracts-grid'
|
import { ContractsGrid } from 'web/components/contract/contracts-grid'
|
||||||
import { useContracts } from 'web/hooks/use-contracts'
|
import { useContracts } from 'web/hooks/use-contracts'
|
||||||
import {
|
import {
|
||||||
|
QuerySortOptions,
|
||||||
Sort,
|
Sort,
|
||||||
useQueryAndSortParams,
|
useQueryAndSortParams,
|
||||||
} from 'web/hooks/use-sort-and-query-params'
|
} from 'web/hooks/use-sort-and-query-params'
|
||||||
|
@ -11,10 +12,7 @@ import {
|
||||||
const MAX_CONTRACTS_RENDERED = 100
|
const MAX_CONTRACTS_RENDERED = 100
|
||||||
|
|
||||||
export default function ContractSearchFirestore(props: {
|
export default function ContractSearchFirestore(props: {
|
||||||
querySortOptions?: {
|
querySortOptions?: QuerySortOptions
|
||||||
defaultSort: Sort
|
|
||||||
shouldLoadFromStorage?: boolean
|
|
||||||
}
|
|
||||||
additionalFilter?: {
|
additionalFilter?: {
|
||||||
creatorId?: string
|
creatorId?: string
|
||||||
tag?: string
|
tag?: string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user