2022-07-26 01:27:43 +00:00
|
|
|
import { Contract } from 'web/lib/firebase/contracts'
|
|
|
|
import { User } from 'web/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-06-23 17:12:57 +00:00
|
|
|
import { ShowTime } from './contract-details'
|
2022-05-09 17:38:33 +00:00
|
|
|
import { ContractSearch } from '../contract-search'
|
2022-08-09 22:28:27 +00:00
|
|
|
import { useCallback } from 'react'
|
2022-06-22 16:35:50 +00:00
|
|
|
import clsx from 'clsx'
|
2022-08-06 00:44:55 +00:00
|
|
|
import { LoadingIndicator } from '../loading-indicator'
|
2022-08-09 22:28:27 +00:00
|
|
|
import { VisibilityObserver } from '../visibility-observer'
|
2022-08-19 23:57:23 +00:00
|
|
|
import Masonry from 'react-masonry-css'
|
2021-12-14 10:27:22 +00:00
|
|
|
|
2022-07-26 01:27:43 +00:00
|
|
|
export type ContractHighlightOptions = {
|
|
|
|
contractIds?: string[]
|
|
|
|
highlightClassName?: string
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:21:30 +00:00
|
|
|
export function ContractsGrid(props: {
|
2022-08-06 00:44:55 +00:00
|
|
|
contracts: Contract[] | undefined
|
2022-08-09 22:28:27 +00:00
|
|
|
loadMore?: () => void
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime?: ShowTime
|
2022-06-05 00:00:13 +00:00
|
|
|
onContractClick?: (contract: Contract) => void
|
2022-07-26 01:27:43 +00:00
|
|
|
cardHideOptions?: {
|
|
|
|
hideQuickBet?: boolean
|
|
|
|
hideGroupLink?: boolean
|
|
|
|
}
|
|
|
|
highlightOptions?: ContractHighlightOptions
|
2022-08-29 05:15:21 +00:00
|
|
|
trackingPostfix?: string
|
2022-09-01 16:47:45 +00:00
|
|
|
breakpointColumns?: { [key: string]: number }
|
2022-01-09 21:21:30 +00:00
|
|
|
}) {
|
2022-06-22 16:35:50 +00:00
|
|
|
const {
|
|
|
|
contracts,
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime,
|
2022-06-22 16:35:50 +00:00
|
|
|
loadMore,
|
|
|
|
onContractClick,
|
2022-07-26 01:27:43 +00:00
|
|
|
cardHideOptions,
|
|
|
|
highlightOptions,
|
2022-08-29 05:15:21 +00:00
|
|
|
trackingPostfix,
|
2022-06-22 16:35:50 +00:00
|
|
|
} = props
|
2022-07-26 01:27:43 +00:00
|
|
|
const { hideQuickBet, hideGroupLink } = cardHideOptions || {}
|
|
|
|
const { contractIds, highlightClassName } = highlightOptions || {}
|
2022-08-09 22:28:27 +00:00
|
|
|
const onVisibilityUpdated = useCallback(
|
|
|
|
(visible) => {
|
|
|
|
if (visible && loadMore) {
|
|
|
|
loadMore()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[loadMore]
|
|
|
|
)
|
2022-05-17 23:29:46 +00:00
|
|
|
|
2022-08-06 00:44:55 +00:00
|
|
|
if (contracts === undefined) {
|
|
|
|
return <LoadingIndicator />
|
|
|
|
}
|
|
|
|
|
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{' '}
|
2022-05-24 00:49:07 +00:00
|
|
|
<SiteLink href="/create" className="font-bold text-gray-700">
|
2022-02-18 02:32:15 +00:00
|
|
|
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-08-19 23:57:23 +00:00
|
|
|
<Masonry
|
|
|
|
// Show only 1 column on tailwind's md breakpoint (768px)
|
2022-09-01 16:47:45 +00:00
|
|
|
breakpointCols={props.breakpointColumns ?? { default: 2, 768: 1 }}
|
2022-08-19 23:57:23 +00:00
|
|
|
className="-ml-4 flex w-auto"
|
|
|
|
columnClassName="pl-4 bg-clip-padding"
|
2022-06-22 16:35:50 +00:00
|
|
|
>
|
2022-04-28 22:45:26 +00:00
|
|
|
{contracts.map((contract) => (
|
|
|
|
<ContractCard
|
|
|
|
contract={contract}
|
|
|
|
key={contract.id}
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime={showTime}
|
2022-06-05 04:21:24 +00:00
|
|
|
onClick={
|
|
|
|
onContractClick ? () => onContractClick(contract) : undefined
|
|
|
|
}
|
2022-06-22 16:35:50 +00:00
|
|
|
hideQuickBet={hideQuickBet}
|
2022-07-26 01:27:43 +00:00
|
|
|
hideGroupLink={hideGroupLink}
|
2022-08-29 05:15:21 +00:00
|
|
|
trackingPostfix={trackingPostfix}
|
2022-08-19 23:57:23 +00:00
|
|
|
className={clsx(
|
2022-08-19 23:59:42 +00:00
|
|
|
'mb-4 break-inside-avoid-column overflow-hidden', // prevent content from wrapping (needs overflow on firefox)
|
2022-08-19 23:57:23 +00:00
|
|
|
contractIds?.includes(contract.id) && highlightClassName
|
|
|
|
)}
|
2022-04-28 22:45:26 +00:00
|
|
|
/>
|
|
|
|
))}
|
2022-08-19 23:57:23 +00:00
|
|
|
</Masonry>
|
2022-08-24 23:30:29 +00:00
|
|
|
{loadMore && (
|
|
|
|
<VisibilityObserver
|
|
|
|
onVisibilityUpdated={onVisibilityUpdated}
|
|
|
|
className="relative -top-96 h-1"
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-30 20:03:32 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-09 22:28:52 +00:00
|
|
|
export function CreatorContractsList(props: {
|
|
|
|
user: User | null | undefined
|
|
|
|
creator: User
|
|
|
|
}) {
|
|
|
|
const { user, 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-08-09 22:28:52 +00:00
|
|
|
user={user}
|
2022-08-15 05:09:25 +00:00
|
|
|
defaultSort="newest"
|
|
|
|
defaultFilter="all"
|
2022-05-17 17:56:10 +00:00
|
|
|
additionalFilter={{
|
|
|
|
creatorId: creator.id,
|
|
|
|
}}
|
2022-09-08 06:39:01 +00:00
|
|
|
persistPrefix={`user-${creator.id}`}
|
2022-01-02 22:46:04 +00:00
|
|
|
/>
|
|
|
|
)
|
2021-12-10 17:54:16 +00:00
|
|
|
}
|