From c5660ab7621038c3700d003b2b2425d6240414eb Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 21 May 2022 13:51:41 -0400 Subject: [PATCH] Prevent flash of "No markets found" on search load --- web/components/contract-search.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/components/contract-search.tsx b/web/components/contract-search.tsx index b7e16eb2..acddaa6e 100644 --- a/web/components/contract-search.tsx +++ b/web/components/contract-search.tsx @@ -191,13 +191,16 @@ export function ContractSearchInner(props: { 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 router = useRouter() - const hasLoaded = contracts.length > 0 || router.isReady - - if (!hasLoaded || !results) return <> + if (isInitialLoad && contracts.length === 0) return <> return (