Add loading indicator when algolia search is initially loading

This commit is contained in:
James Grugett 2022-08-05 17:44:55 -07:00
parent 48ac21ffad
commit b3b06896be
3 changed files with 13 additions and 13 deletions

View File

@ -343,7 +343,7 @@ export function ContractSearch(props: {
<>You're not following anyone, nor in any of your own groups yet.</> <>You're not following anyone, nor in any of your own groups yet.</>
) : ( ) : (
<ContractsGrid <ContractsGrid
contracts={contracts} contracts={hitsByPage[0] === undefined ? undefined : contracts}
loadMore={loadMore} loadMore={loadMore}
hasMore={true} hasMore={true}
showTime={showTime} showTime={showTime}

View File

@ -8,6 +8,7 @@ import { ContractSearch } from '../contract-search'
import { useIsVisible } from 'web/hooks/use-is-visible' import { useIsVisible } from 'web/hooks/use-is-visible'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import clsx from 'clsx' import clsx from 'clsx'
import { LoadingIndicator } from '../loading-indicator'
export type ContractHighlightOptions = { export type ContractHighlightOptions = {
contractIds?: string[] contractIds?: string[]
@ -15,7 +16,7 @@ export type ContractHighlightOptions = {
} }
export function ContractsGrid(props: { export function ContractsGrid(props: {
contracts: Contract[] contracts: Contract[] | undefined
loadMore: () => void loadMore: () => void
hasMore: boolean hasMore: boolean
showTime?: ShowTime showTime?: ShowTime
@ -49,6 +50,10 @@ export function ContractsGrid(props: {
} }
}, [isBottomVisible, hasMore, loadMore]) }, [isBottomVisible, hasMore, loadMore])
if (contracts === undefined) {
return <LoadingIndicator />
}
if (contracts.length === 0) { if (contracts.length === 0) {
return ( return (
<p className="mx-2 text-gray-500"> <p className="mx-2 text-gray-500">

View File

@ -3,7 +3,6 @@ import { searchInAny } from 'common/util/parse'
import { sortBy } from 'lodash' import { sortBy } from 'lodash'
import { useState } from 'react' import { useState } from 'react'
import { ContractsGrid } from 'web/components/contract/contracts-list' import { ContractsGrid } from 'web/components/contract/contracts-list'
import { LoadingIndicator } from 'web/components/loading-indicator'
import { useContracts } from 'web/hooks/use-contracts' import { useContracts } from 'web/hooks/use-contracts'
import { import {
Sort, Sort,
@ -118,16 +117,12 @@ export default function ContractSearchFirestore(props: {
<option value="close-date">Closing soon</option> <option value="close-date">Closing soon</option>
</select> </select>
</div> </div>
{contracts === undefined ? (
<LoadingIndicator />
) : (
<ContractsGrid <ContractsGrid
contracts={matches} contracts={matches}
loadMore={() => {}} loadMore={() => {}}
hasMore={false} hasMore={false}
showTime={showTime} showTime={showTime}
/> />
)}
</div> </div>
) )
} }