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-05-17 23:29:46 +00:00
|
|
|
import { useIsVisible } from 'web/hooks/use-is-visible'
|
|
|
|
import { useEffect, useState } 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'
|
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-05-09 17:38:33 +00:00
|
|
|
loadMore: () => void
|
|
|
|
hasMore: boolean
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime?: ShowTime
|
2022-06-05 00:00:13 +00:00
|
|
|
onContractClick?: (contract: Contract) => void
|
2022-06-22 16:35:50 +00:00
|
|
|
overrideGridClassName?: string
|
2022-07-26 01:27:43 +00:00
|
|
|
cardHideOptions?: {
|
|
|
|
hideQuickBet?: boolean
|
|
|
|
hideGroupLink?: boolean
|
|
|
|
}
|
|
|
|
highlightOptions?: ContractHighlightOptions
|
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
|
|
|
hasMore,
|
|
|
|
loadMore,
|
|
|
|
onContractClick,
|
|
|
|
overrideGridClassName,
|
2022-07-26 01:27:43 +00:00
|
|
|
cardHideOptions,
|
|
|
|
highlightOptions,
|
2022-06-22 16:35:50 +00:00
|
|
|
} = props
|
2022-07-26 01:27:43 +00:00
|
|
|
const { hideQuickBet, hideGroupLink } = cardHideOptions || {}
|
2021-12-16 21:20:49 +00:00
|
|
|
|
2022-07-26 01:27:43 +00:00
|
|
|
const { contractIds, highlightClassName } = highlightOptions || {}
|
2022-05-17 23:29:46 +00:00
|
|
|
const [elem, setElem] = useState<HTMLElement | null>(null)
|
|
|
|
const isBottomVisible = useIsVisible(elem)
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-05-28 20:36:16 +00:00
|
|
|
if (isBottomVisible && hasMore) {
|
2022-05-17 23:29:46 +00:00
|
|
|
loadMore()
|
|
|
|
}
|
|
|
|
}, [isBottomVisible, hasMore, loadMore])
|
|
|
|
|
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-06-22 16:35:50 +00:00
|
|
|
<ul
|
|
|
|
className={clsx(
|
|
|
|
overrideGridClassName
|
|
|
|
? overrideGridClassName
|
|
|
|
: 'grid w-full grid-cols-1 gap-4 md:grid-cols-2'
|
|
|
|
)}
|
|
|
|
>
|
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}
|
|
|
|
className={
|
|
|
|
contractIds?.includes(contract.id)
|
|
|
|
? highlightClassName
|
|
|
|
: undefined
|
|
|
|
}
|
2022-04-28 22:45:26 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</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,
|
|
|
|
}}
|
2022-01-02 22:46:04 +00:00
|
|
|
/>
|
|
|
|
)
|
2021-12-10 17:54:16 +00:00
|
|
|
}
|