Move loading indicator into SearchableGrid.
This commit is contained in:
parent
7e9007aad1
commit
fa8ebe36bd
|
@ -18,6 +18,7 @@ import {
|
||||||
useQueryAndSortParams,
|
useQueryAndSortParams,
|
||||||
} from '../../hooks/use-sort-and-query-params'
|
} from '../../hooks/use-sort-and-query-params'
|
||||||
import { Answer } from '../../../common/answer'
|
import { Answer } from '../../../common/answer'
|
||||||
|
import { LoadingIndicator } from '../loading-indicator'
|
||||||
|
|
||||||
export function ContractsGrid(props: {
|
export function ContractsGrid(props: {
|
||||||
contracts: Contract[]
|
contracts: Contract[]
|
||||||
|
@ -213,7 +214,7 @@ function TagContractsGrid(props: { contracts: Contract[] }) {
|
||||||
const MAX_CONTRACTS_DISPLAYED = 99
|
const MAX_CONTRACTS_DISPLAYED = 99
|
||||||
|
|
||||||
export function SearchableGrid(props: {
|
export function SearchableGrid(props: {
|
||||||
contracts: Contract[]
|
contracts: Contract[] | undefined
|
||||||
byOneCreator?: boolean
|
byOneCreator?: boolean
|
||||||
querySortOptions?: {
|
querySortOptions?: {
|
||||||
defaultSort: Sort
|
defaultSort: Sort
|
||||||
|
@ -230,7 +231,7 @@ export function SearchableGrid(props: {
|
||||||
return queryWords.every((word) => corpus.toLowerCase().includes(word))
|
return queryWords.every((word) => corpus.toLowerCase().includes(word))
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = contracts.filter(
|
let matches = (contracts ?? []).filter(
|
||||||
(c) =>
|
(c) =>
|
||||||
check(c.question) ||
|
check(c.question) ||
|
||||||
check(c.description) ||
|
check(c.description) ||
|
||||||
|
@ -324,7 +325,9 @@ export function SearchableGrid(props: {
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{sort === 'tag' ? (
|
{contracts === undefined ? (
|
||||||
|
<LoadingIndicator />
|
||||||
|
) : sort === 'tag' ? (
|
||||||
<TagContractsGrid contracts={matches} />
|
<TagContractsGrid contracts={matches} />
|
||||||
) : !byOneCreator && sort === 'creator' ? (
|
) : !byOneCreator && sort === 'creator' ? (
|
||||||
<CreatorContractsGrid contracts={matches} />
|
<CreatorContractsGrid contracts={matches} />
|
||||||
|
|
|
@ -2,7 +2,6 @@ import {
|
||||||
ContractsGrid,
|
ContractsGrid,
|
||||||
SearchableGrid,
|
SearchableGrid,
|
||||||
} from '../components/contract/contracts-list'
|
} from '../components/contract/contracts-list'
|
||||||
import { LoadingIndicator } from '../components/loading-indicator'
|
|
||||||
import { Page } from '../components/page'
|
import { Page } from '../components/page'
|
||||||
import { SEO } from '../components/SEO'
|
import { SEO } from '../components/SEO'
|
||||||
import { Title } from '../components/title'
|
import { Title } from '../components/title'
|
||||||
|
@ -20,11 +19,7 @@ export default function Markets() {
|
||||||
description="Discover what's new, trending, or soon-to-close. Or search among our hundreds of markets."
|
description="Discover what's new, trending, or soon-to-close. Or search among our hundreds of markets."
|
||||||
url="/markets"
|
url="/markets"
|
||||||
/>
|
/>
|
||||||
{contracts === undefined ? (
|
|
||||||
<LoadingIndicator />
|
|
||||||
) : (
|
|
||||||
<SearchableGrid contracts={contracts} />
|
<SearchableGrid contracts={contracts} />
|
||||||
)}
|
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,27 +3,24 @@ import { useRouter } from 'next/router'
|
||||||
import { SearchableGrid } from '../../components/contract/contracts-list'
|
import { SearchableGrid } from '../../components/contract/contracts-list'
|
||||||
import { Page } from '../../components/page'
|
import { Page } from '../../components/page'
|
||||||
import { Title } from '../../components/title'
|
import { Title } from '../../components/title'
|
||||||
import { useContracts } from '../../hooks/use-contracts'
|
|
||||||
import {
|
import {
|
||||||
Contract,
|
Contract,
|
||||||
listTaggedContractsCaseInsensitive,
|
listTaggedContractsCaseInsensitive,
|
||||||
} from '../../lib/firebase/contracts'
|
} from '../../lib/firebase/contracts'
|
||||||
|
|
||||||
export default function TagPage(props: { contracts: Contract[] }) {
|
export default function TagPage() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { tag } = router.query as { tag: string }
|
const { tag } = router.query as { tag: string }
|
||||||
|
|
||||||
// mqp: i wrote this in a panic to make the page literally work at all so if you
|
// mqp: i wrote this in a panic to make the page literally work at all so if you
|
||||||
// want to e.g. listen for new contracts you may want to fix it up
|
// want to e.g. listen for new contracts you may want to fix it up
|
||||||
const [contracts, setContracts] = useState<Contract[] | 'loading'>('loading')
|
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
listTaggedContractsCaseInsensitive(tag).then(setContracts)
|
listTaggedContractsCaseInsensitive(tag).then(setContracts)
|
||||||
}
|
}
|
||||||
}, [tag])
|
}, [tag])
|
||||||
|
|
||||||
if (contracts === 'loading') return <></>
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<Title text={`#${tag}`} />
|
<Title text={`#${tag}`} />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user