Prevent flash of "No markets found" on search load

This commit is contained in:
James Grugett 2022-05-21 13:51:41 -04:00
parent 688ebb797a
commit c5660ab762

View File

@ -191,13 +191,16 @@ export function ContractSearchInner(props: {
filter === 'resolved' ? true : filter === 'all' ? undefined : false filter === 'resolved' ? true : filter === 'all' ? undefined : false
) )
const { showMore, hits, isLastPage, results } = useInfiniteHits() const [isInitialLoad, setIsInitialLoad] = useState(true)
useEffect(() => {
const id = setTimeout(() => setIsInitialLoad(false), 1000)
return () => clearTimeout(id)
}, [])
const { showMore, hits, isLastPage } = useInfiniteHits()
const contracts = hits as any as Contract[] const contracts = hits as any as Contract[]
const router = useRouter() if (isInitialLoad && contracts.length === 0) return <></>
const hasLoaded = contracts.length > 0 || router.isReady
if (!hasLoaded || !results) return <></>
return ( return (
<ContractsGrid <ContractsGrid