2022-05-09 17:38:33 +00:00
|
|
|
import { Contract } from '../../lib/firebase/contracts'
|
|
|
|
import { User } from '../../lib/firebase/users'
|
2022-04-07 21:15:51 +00:00
|
|
|
import { Col } from '../layout/col'
|
|
|
|
import { SiteLink } from '../site-link'
|
2022-01-02 19:09:01 +00:00
|
|
|
import { ContractCard } from './contract-card'
|
2022-05-09 17:38:33 +00:00
|
|
|
import { ContractSearch } from '../contract-search'
|
2022-05-17 23:29:46 +00:00
|
|
|
import { useIsVisible } from 'web/hooks/use-is-visible'
|
|
|
|
import { useEffect, useState } from 'react'
|
2021-12-14 10:27:22 +00:00
|
|
|
|
2022-01-09 21:21:30 +00:00
|
|
|
export function ContractsGrid(props: {
|
|
|
|
contracts: Contract[]
|
2022-05-09 17:38:33 +00:00
|
|
|
loadMore: () => void
|
|
|
|
hasMore: boolean
|
2022-01-17 22:54:00 +00:00
|
|
|
showCloseTime?: boolean
|
2022-01-09 21:21:30 +00:00
|
|
|
}) {
|
2022-05-09 17:38:33 +00:00
|
|
|
const { contracts, showCloseTime, hasMore, loadMore } = props
|
2021-12-16 21:20:49 +00:00
|
|
|
|
2022-05-17 23:29:46 +00:00
|
|
|
const [elem, setElem] = useState<HTMLElement | null>(null)
|
|
|
|
const isBottomVisible = useIsVisible(elem)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
console.log({ isBottomVisible, hasMore })
|
|
|
|
if (isBottomVisible) {
|
|
|
|
loadMore()
|
|
|
|
}
|
|
|
|
}, [isBottomVisible, hasMore, loadMore])
|
|
|
|
|
2021-12-18 10:28:01 +00:00
|
|
|
if (contracts.length === 0) {
|
|
|
|
return (
|
2022-02-11 18:40:22 +00:00
|
|
|
<p className="mx-2 text-gray-500">
|
2022-02-18 02:32:15 +00:00
|
|
|
No markets found. Why not{' '}
|
|
|
|
<SiteLink href="/home" className="font-bold text-gray-700">
|
|
|
|
create one?
|
|
|
|
</SiteLink>
|
2021-12-18 10:28:01 +00:00
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-14 10:27:22 +00:00
|
|
|
return (
|
2022-05-09 17:38:33 +00:00
|
|
|
<Col className="gap-8">
|
2022-04-28 22:45:26 +00:00
|
|
|
<ul className="grid w-full grid-cols-1 gap-6 md:grid-cols-2">
|
|
|
|
{contracts.map((contract) => (
|
|
|
|
<ContractCard
|
|
|
|
contract={contract}
|
|
|
|
key={contract.id}
|
|
|
|
showCloseTime={showCloseTime}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ul>
|
2022-05-17 23:29:46 +00:00
|
|
|
<div ref={setElem} className="relative -top-96 h-1" />
|
2021-12-30 20:03:32 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-09 17:38:33 +00:00
|
|
|
export function CreatorContractsList(props: { creator: User }) {
|
|
|
|
const { creator } = props
|
2021-12-16 02:50:03 +00:00
|
|
|
|
2022-01-02 22:46:04 +00:00
|
|
|
return (
|
2022-05-09 17:38:33 +00:00
|
|
|
<ContractSearch
|
2022-03-29 15:09:46 +00:00
|
|
|
querySortOptions={{
|
2022-05-09 17:38:33 +00:00
|
|
|
defaultSort: 'newest',
|
2022-05-11 04:19:13 +00:00
|
|
|
defaultFilter: 'all',
|
2022-03-29 15:09:46 +00:00
|
|
|
shouldLoadFromStorage: false,
|
|
|
|
}}
|
2022-05-17 17:56:10 +00:00
|
|
|
additionalFilter={{
|
|
|
|
creatorId: creator.id,
|
|
|
|
}}
|
|
|
|
showCategorySelector={false}
|
2022-01-02 22:46:04 +00:00
|
|
|
/>
|
|
|
|
)
|
2021-12-10 17:54:16 +00:00
|
|
|
}
|