2022-09-16 00:41:25 +00:00
|
|
|
import { ClockIcon } from '@heroicons/react/outline'
|
2022-10-03 22:21:56 +00:00
|
|
|
import {
|
|
|
|
ExclamationIcon,
|
|
|
|
PencilIcon,
|
|
|
|
PlusCircleIcon,
|
2022-10-14 02:05:13 +00:00
|
|
|
UserGroupIcon,
|
2022-10-03 22:21:56 +00:00
|
|
|
} from '@heroicons/react/solid'
|
2022-08-26 06:23:50 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { Editor } from '@tiptap/react'
|
|
|
|
import dayjs from 'dayjs'
|
2022-09-02 02:37:41 +00:00
|
|
|
import Link from 'next/link'
|
2022-04-20 03:34:41 +00:00
|
|
|
import { Row } from '../layout/row'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-08-24 23:07:22 +00:00
|
|
|
import { Contract, updateContract } from 'web/lib/firebase/contracts'
|
2022-04-20 03:34:41 +00:00
|
|
|
import { DateTimeTooltip } from '../datetime-tooltip'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { fromNow } from 'web/lib/util/time'
|
2022-04-20 03:34:41 +00:00
|
|
|
import { Avatar } from '../avatar'
|
|
|
|
import { useState } from 'react'
|
2022-04-21 06:03:16 +00:00
|
|
|
import NewContractBadge from '../new-contract-badge'
|
2022-09-16 00:41:25 +00:00
|
|
|
import { MiniUserFollowButton } from '../follow-button'
|
2022-06-17 03:52:53 +00:00
|
|
|
import { DAY_MS } from 'common/util/time'
|
2022-10-03 09:49:19 +00:00
|
|
|
import { useUser, useUserById } from 'web/hooks/use-user'
|
2022-07-22 17:34:10 +00:00
|
|
|
import { Button } from 'web/components/button'
|
|
|
|
import { Modal } from 'web/components/layout/modal'
|
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { ContractGroupsList } from 'web/components/groups/contract-groups-list'
|
2022-09-02 02:37:41 +00:00
|
|
|
import { linkClass } from 'web/components/site-link'
|
2022-09-01 14:29:56 +00:00
|
|
|
import { getGroupLinkToDisplay, groupPath } from 'web/lib/firebase/groups'
|
2022-08-11 21:32:02 +00:00
|
|
|
import { insertContent } from '../editor/utils'
|
2022-08-19 17:43:57 +00:00
|
|
|
import { contractMetrics } from 'common/contract-details'
|
2022-08-30 15:38:59 +00:00
|
|
|
import { UserLink } from 'web/components/user-link'
|
2022-08-26 02:17:50 +00:00
|
|
|
import { FeaturedContractBadge } from 'web/components/contract/featured-contract-badge'
|
2022-08-30 23:13:25 +00:00
|
|
|
import { Tooltip } from 'web/components/tooltip'
|
2022-09-16 00:41:25 +00:00
|
|
|
import { ExtraContractActionsRow } from './extra-contract-actions-row'
|
|
|
|
import { GroupLink } from 'common/group'
|
2022-09-16 07:38:09 +00:00
|
|
|
import { Subtitle } from '../subtitle'
|
2022-09-16 15:28:39 +00:00
|
|
|
import { useIsMobile } from 'web/hooks/use-is-mobile'
|
2022-10-12 21:07:07 +00:00
|
|
|
import { useIsClient } from 'web/hooks/use-is-client'
|
2022-09-30 16:00:55 +00:00
|
|
|
import {
|
|
|
|
BountiedContractBadge,
|
|
|
|
BountiedContractSmallBadge,
|
|
|
|
} from 'web/components/contract/bountied-contract-badge'
|
2022-10-10 02:37:24 +00:00
|
|
|
import { Input } from '../input'
|
2022-10-11 01:47:02 +00:00
|
|
|
import { editorExtensions } from '../editor'
|
2022-04-20 03:34:41 +00:00
|
|
|
|
2022-06-23 17:12:57 +00:00
|
|
|
export type ShowTime = 'resolve-date' | 'close-date'
|
|
|
|
|
2022-05-24 06:44:16 +00:00
|
|
|
export function MiscDetails(props: {
|
2022-04-20 03:34:41 +00:00
|
|
|
contract: Contract
|
2022-06-23 17:12:57 +00:00
|
|
|
showTime?: ShowTime
|
2022-07-26 01:27:43 +00:00
|
|
|
hideGroupLink?: boolean
|
2022-04-20 03:34:41 +00:00
|
|
|
}) {
|
2022-09-05 21:25:46 +00:00
|
|
|
const { contract, showTime, hideGroupLink } = props
|
2022-10-14 02:05:13 +00:00
|
|
|
const {
|
|
|
|
closeTime,
|
|
|
|
isResolved,
|
|
|
|
createdTime,
|
|
|
|
resolutionTime,
|
|
|
|
uniqueBettorCount,
|
|
|
|
} = contract
|
2022-07-22 22:28:53 +00:00
|
|
|
|
2022-10-12 21:07:07 +00:00
|
|
|
const isClient = useIsClient()
|
2022-06-17 03:52:53 +00:00
|
|
|
const isNew = createdTime > Date.now() - DAY_MS && !isResolved
|
2022-09-01 14:29:56 +00:00
|
|
|
const groupToDisplay = getGroupLinkToDisplay(contract)
|
2022-04-20 03:34:41 +00:00
|
|
|
|
|
|
|
return (
|
2022-08-16 22:03:55 +00:00
|
|
|
<Row className="items-center gap-3 truncate text-sm text-gray-400">
|
2022-10-12 21:07:07 +00:00
|
|
|
{isClient && showTime === 'close-date' ? (
|
2022-08-16 22:03:55 +00:00
|
|
|
<Row className="gap-0.5 whitespace-nowrap">
|
2022-05-24 06:44:16 +00:00
|
|
|
<ClockIcon className="h-5 w-5" />
|
|
|
|
{(closeTime || 0) < Date.now() ? 'Closed' : 'Closes'}{' '}
|
|
|
|
{fromNow(closeTime || 0)}
|
2022-04-20 03:34:41 +00:00
|
|
|
</Row>
|
2022-10-12 21:07:07 +00:00
|
|
|
) : isClient && showTime === 'resolve-date' && resolutionTime ? (
|
2022-06-23 17:12:57 +00:00
|
|
|
<Row className="gap-0.5">
|
|
|
|
<ClockIcon className="h-5 w-5" />
|
|
|
|
{'Resolved '}
|
2022-10-12 21:07:07 +00:00
|
|
|
{fromNow(resolutionTime)}
|
2022-06-23 17:12:57 +00:00
|
|
|
</Row>
|
2022-08-25 13:05:26 +00:00
|
|
|
) : (contract?.featuredOnHomeRank ?? 0) > 0 ? (
|
|
|
|
<FeaturedContractBadge />
|
2022-09-30 15:27:42 +00:00
|
|
|
) : (contract.openCommentBounties ?? 0) > 0 ? (
|
|
|
|
<BountiedContractBadge />
|
2022-10-14 02:05:13 +00:00
|
|
|
) : !isNew || (uniqueBettorCount ?? 0) > 1 ? (
|
|
|
|
<Row className={'shrink-0'}>
|
|
|
|
<UserGroupIcon className="mr-1 h-4 w-4" />
|
|
|
|
{uniqueBettorCount} trader{uniqueBettorCount !== 1 ? 's' : ''}
|
|
|
|
</Row>
|
2022-05-24 06:44:16 +00:00
|
|
|
) : (
|
|
|
|
<NewContractBadge />
|
|
|
|
)}
|
2022-05-24 23:57:34 +00:00
|
|
|
|
2022-09-01 14:29:56 +00:00
|
|
|
{!hideGroupLink && groupToDisplay && (
|
2022-09-02 02:37:41 +00:00
|
|
|
<Link prefetch={false} href={groupPath(groupToDisplay.slug)}>
|
|
|
|
<a className={clsx(linkClass, 'truncate text-sm text-gray-400')}>
|
|
|
|
{groupToDisplay.name}
|
|
|
|
</a>
|
|
|
|
</Link>
|
2022-05-24 23:57:34 +00:00
|
|
|
)}
|
2022-05-24 06:44:16 +00:00
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
2022-04-20 03:34:41 +00:00
|
|
|
|
2022-08-15 19:49:33 +00:00
|
|
|
export function AvatarDetails(props: {
|
|
|
|
contract: Contract
|
|
|
|
className?: string
|
|
|
|
short?: boolean
|
2022-09-15 15:51:52 +00:00
|
|
|
noLink?: boolean
|
2022-08-15 19:49:33 +00:00
|
|
|
}) {
|
2022-09-15 15:51:52 +00:00
|
|
|
const { contract, short, className, noLink } = props
|
2022-08-30 23:13:25 +00:00
|
|
|
const { creatorName, creatorUsername, creatorAvatarUrl } = contract
|
2022-05-16 23:15:22 +00:00
|
|
|
|
2022-05-24 06:44:16 +00:00
|
|
|
return (
|
2022-08-15 19:49:33 +00:00
|
|
|
<Row
|
|
|
|
className={clsx('items-center gap-2 text-sm text-gray-400', className)}
|
|
|
|
>
|
2022-05-24 06:44:16 +00:00
|
|
|
<Avatar
|
|
|
|
username={creatorUsername}
|
2022-08-30 23:13:25 +00:00
|
|
|
avatarUrl={creatorAvatarUrl}
|
2022-05-24 06:44:16 +00:00
|
|
|
size={6}
|
2022-09-15 15:51:52 +00:00
|
|
|
noLink={noLink}
|
|
|
|
/>
|
|
|
|
<UserLink
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
short={short}
|
|
|
|
noLink={noLink}
|
2022-05-24 06:44:16 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-20 03:34:41 +00:00
|
|
|
export function ContractDetails(props: {
|
|
|
|
contract: Contract
|
2022-05-17 17:31:19 +00:00
|
|
|
disabled?: boolean
|
2022-04-20 03:34:41 +00:00
|
|
|
}) {
|
2022-09-01 21:42:50 +00:00
|
|
|
const { contract, disabled } = props
|
2022-09-16 00:41:25 +00:00
|
|
|
const isMobile = useIsMobile()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Col>
|
|
|
|
<Row className="justify-between">
|
|
|
|
<MarketSubheader contract={contract} disabled={disabled} />
|
|
|
|
<div className="mt-0">
|
|
|
|
<ExtraContractActionsRow contract={contract} />
|
|
|
|
</div>
|
2022-09-15 12:55:57 +00:00
|
|
|
</Row>
|
2022-09-16 00:41:25 +00:00
|
|
|
{/* GROUPS */}
|
|
|
|
{isMobile && (
|
2022-09-30 16:00:55 +00:00
|
|
|
<Row className="mt-2 gap-1">
|
|
|
|
<BountiedContractSmallBadge contract={contract} />
|
2022-09-16 22:21:07 +00:00
|
|
|
<MarketGroups contract={contract} disabled={disabled} />
|
2022-09-30 16:00:55 +00:00
|
|
|
</Row>
|
2022-09-16 00:41:25 +00:00
|
|
|
)}
|
|
|
|
</Col>
|
2022-08-05 05:47:59 +00:00
|
|
|
)
|
2022-09-16 00:41:25 +00:00
|
|
|
}
|
2022-09-15 12:55:57 +00:00
|
|
|
|
2022-09-16 00:41:25 +00:00
|
|
|
export function MarketSubheader(props: {
|
|
|
|
contract: Contract
|
|
|
|
disabled?: boolean
|
|
|
|
}) {
|
|
|
|
const { contract, disabled } = props
|
|
|
|
const { creatorName, creatorUsername, creatorId, creatorAvatarUrl } = contract
|
|
|
|
const { resolvedDate } = contractMetrics(contract)
|
|
|
|
const user = useUser()
|
2022-10-10 20:32:29 +00:00
|
|
|
const creator = useUserById(creatorId)
|
|
|
|
const correctResolutionPercentage = creator?.fractionResolvedCorrectly
|
2022-09-16 00:41:25 +00:00
|
|
|
const isCreator = user?.id === creatorId
|
|
|
|
const isMobile = useIsMobile()
|
2022-04-20 03:34:41 +00:00
|
|
|
return (
|
2022-09-16 00:41:25 +00:00
|
|
|
<Row>
|
|
|
|
<Avatar
|
|
|
|
username={creatorUsername}
|
|
|
|
avatarUrl={creatorAvatarUrl}
|
|
|
|
noLink={disabled}
|
|
|
|
size={9}
|
|
|
|
className="mr-1.5"
|
|
|
|
/>
|
2022-10-03 09:49:19 +00:00
|
|
|
|
2022-09-16 00:41:25 +00:00
|
|
|
{!disabled && (
|
|
|
|
<div className="absolute mt-3 ml-[11px]">
|
|
|
|
<MiniUserFollowButton userId={creatorId} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<Col className="text-greyscale-6 ml-2 flex-1 flex-wrap text-sm">
|
2022-10-03 09:49:19 +00:00
|
|
|
<Row className="w-full space-x-1 ">
|
2022-09-16 00:41:25 +00:00
|
|
|
{disabled ? (
|
|
|
|
creatorName
|
|
|
|
) : (
|
2022-10-10 20:32:29 +00:00
|
|
|
<Row className={'gap-2'}>
|
|
|
|
<UserLink
|
|
|
|
className="my-auto whitespace-nowrap"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>
|
|
|
|
{/*<BadgeDisplay user={creator} />*/}
|
|
|
|
</Row>
|
2022-09-16 00:41:25 +00:00
|
|
|
)}
|
2022-10-03 09:49:19 +00:00
|
|
|
{correctResolutionPercentage != null &&
|
|
|
|
correctResolutionPercentage < BAD_CREATOR_THRESHOLD && (
|
|
|
|
<Tooltip text="This creator has a track record of creating contracts that are resolved incorrectly.">
|
|
|
|
<ExclamationIcon className="h-6 w-6 text-yellow-500" />
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2022-09-16 00:41:25 +00:00
|
|
|
</Row>
|
2022-09-30 19:44:32 +00:00
|
|
|
<Row className="text-2xs text-greyscale-4 flex-wrap gap-2 sm:text-xs">
|
2022-09-16 00:41:25 +00:00
|
|
|
<CloseOrResolveTime
|
|
|
|
contract={contract}
|
|
|
|
resolvedDate={resolvedDate}
|
|
|
|
isCreator={isCreator}
|
2022-10-01 01:30:45 +00:00
|
|
|
disabled={disabled}
|
2022-09-15 12:55:57 +00:00
|
|
|
/>
|
2022-09-16 00:41:25 +00:00
|
|
|
{!isMobile && (
|
2022-09-30 16:00:55 +00:00
|
|
|
<Row className={'gap-1'}>
|
|
|
|
<BountiedContractSmallBadge contract={contract} />
|
|
|
|
<MarketGroups contract={contract} disabled={disabled} />
|
|
|
|
</Row>
|
2022-09-16 00:41:25 +00:00
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function CloseOrResolveTime(props: {
|
|
|
|
contract: Contract
|
|
|
|
resolvedDate: any
|
|
|
|
isCreator: boolean
|
2022-10-01 01:30:45 +00:00
|
|
|
disabled?: boolean
|
2022-09-16 00:41:25 +00:00
|
|
|
}) {
|
2022-10-01 01:30:45 +00:00
|
|
|
const { contract, resolvedDate, isCreator, disabled } = props
|
2022-09-16 00:41:25 +00:00
|
|
|
const { resolutionTime, closeTime } = contract
|
|
|
|
if (!!closeTime || !!resolvedDate) {
|
|
|
|
return (
|
|
|
|
<Row className="select-none items-center gap-1">
|
|
|
|
{resolvedDate && resolutionTime ? (
|
|
|
|
<>
|
|
|
|
<DateTimeTooltip text="Market resolved:" time={resolutionTime}>
|
|
|
|
<Row>
|
|
|
|
<div>resolved </div>
|
|
|
|
{resolvedDate}
|
|
|
|
</Row>
|
|
|
|
</DateTimeTooltip>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{!resolvedDate && closeTime && (
|
|
|
|
<Row>
|
|
|
|
{dayjs().isBefore(closeTime) && <div>closes </div>}
|
|
|
|
{!dayjs().isBefore(closeTime) && <div>closed </div>}
|
|
|
|
<EditableCloseDate
|
|
|
|
closeTime={closeTime}
|
|
|
|
contract={contract}
|
|
|
|
isCreator={isCreator ?? false}
|
2022-10-01 01:30:45 +00:00
|
|
|
disabled={disabled}
|
2022-09-16 00:41:25 +00:00
|
|
|
/>
|
|
|
|
</Row>
|
2022-09-15 12:55:57 +00:00
|
|
|
)}
|
|
|
|
</Row>
|
2022-09-16 00:41:25 +00:00
|
|
|
)
|
|
|
|
} else return <></>
|
|
|
|
}
|
|
|
|
|
|
|
|
export function MarketGroups(props: {
|
|
|
|
contract: Contract
|
2022-09-16 22:21:07 +00:00
|
|
|
disabled?: boolean
|
2022-09-16 00:41:25 +00:00
|
|
|
}) {
|
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
const user = useUser()
|
2022-09-16 22:21:07 +00:00
|
|
|
const { contract, disabled } = props
|
2022-09-16 00:41:25 +00:00
|
|
|
const groupToDisplay = getGroupLinkToDisplay(contract)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-09-16 22:21:07 +00:00
|
|
|
<Row className="items-center gap-1">
|
2022-10-01 01:30:45 +00:00
|
|
|
<GroupDisplay groupToDisplay={groupToDisplay} disabled={disabled} />
|
|
|
|
|
2022-09-16 22:21:07 +00:00
|
|
|
{!disabled && user && (
|
|
|
|
<button
|
|
|
|
className="text-greyscale-4 hover:text-greyscale-3"
|
|
|
|
onClick={() => setOpen(true)}
|
|
|
|
>
|
|
|
|
<PlusCircleIcon className="h-[18px]" />
|
|
|
|
</button>
|
2022-08-05 05:47:59 +00:00
|
|
|
)}
|
2022-07-22 17:34:10 +00:00
|
|
|
</Row>
|
|
|
|
<Modal open={open} setOpen={setOpen} size={'md'}>
|
|
|
|
<Col
|
|
|
|
className={
|
|
|
|
'max-h-[70vh] min-h-[20rem] overflow-auto rounded bg-white p-6'
|
|
|
|
}
|
|
|
|
>
|
2022-09-01 14:29:56 +00:00
|
|
|
<ContractGroupsList contract={contract} user={user} />
|
2022-07-22 17:34:10 +00:00
|
|
|
</Col>
|
|
|
|
</Modal>
|
2022-09-16 00:41:25 +00:00
|
|
|
</>
|
2022-04-20 03:34:41 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-30 23:13:25 +00:00
|
|
|
export function ExtraMobileContractDetails(props: {
|
|
|
|
contract: Contract
|
|
|
|
forceShowVolume?: boolean
|
|
|
|
}) {
|
2022-09-01 21:42:50 +00:00
|
|
|
const { contract, forceShowVolume } = props
|
2022-08-30 23:13:25 +00:00
|
|
|
const { volume, resolutionTime, closeTime, creatorId, uniqueBettorCount } =
|
|
|
|
contract
|
2022-09-01 21:42:50 +00:00
|
|
|
const user = useUser()
|
2022-08-30 23:13:25 +00:00
|
|
|
const uniqueBettors = uniqueBettorCount ?? 0
|
|
|
|
const { resolvedDate } = contractMetrics(contract)
|
|
|
|
const volumeTranslation =
|
2022-09-01 13:23:43 +00:00
|
|
|
volume > 800 || uniqueBettors >= 20
|
2022-08-30 23:13:25 +00:00
|
|
|
? 'High'
|
2022-09-01 13:23:43 +00:00
|
|
|
: volume > 300 || uniqueBettors >= 10
|
2022-08-30 23:13:25 +00:00
|
|
|
? 'Medium'
|
|
|
|
: 'Low'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Row
|
|
|
|
className={clsx(
|
|
|
|
'items-center justify-around md:hidden',
|
|
|
|
user ? 'w-full' : ''
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{resolvedDate && resolutionTime ? (
|
|
|
|
<Col className={'items-center text-sm'}>
|
|
|
|
<Row className={'text-gray-500'}>
|
|
|
|
<DateTimeTooltip text="Market resolved:" time={resolutionTime}>
|
|
|
|
{resolvedDate}
|
|
|
|
</DateTimeTooltip>
|
|
|
|
</Row>
|
|
|
|
<Row className={'text-gray-400'}>Ended</Row>
|
|
|
|
</Col>
|
|
|
|
) : (
|
|
|
|
!resolvedDate &&
|
|
|
|
closeTime && (
|
|
|
|
<Col className={'items-center text-sm text-gray-500'}>
|
2022-09-16 00:41:25 +00:00
|
|
|
<Row className={'text-gray-400'}>Closes </Row>
|
2022-08-30 23:13:25 +00:00
|
|
|
<EditableCloseDate
|
|
|
|
closeTime={closeTime}
|
|
|
|
contract={contract}
|
|
|
|
isCreator={creatorId === user?.id}
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
{(user || forceShowVolume) && (
|
|
|
|
<Col className={'items-center text-sm text-gray-500'}>
|
|
|
|
<Tooltip
|
|
|
|
text={`${formatMoney(
|
|
|
|
volume
|
2022-09-19 19:03:45 +00:00
|
|
|
)} bet - ${uniqueBettors} unique traders`}
|
2022-08-30 23:13:25 +00:00
|
|
|
>
|
|
|
|
{volumeTranslation}
|
|
|
|
</Tooltip>
|
|
|
|
<Row className={'text-gray-400'}>Activity</Row>
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-01 01:30:45 +00:00
|
|
|
export function GroupDisplay(props: {
|
|
|
|
groupToDisplay?: GroupLink | null
|
|
|
|
disabled?: boolean
|
|
|
|
}) {
|
|
|
|
const { groupToDisplay, disabled } = props
|
|
|
|
|
2022-09-16 00:41:25 +00:00
|
|
|
if (groupToDisplay) {
|
2022-10-01 01:30:45 +00:00
|
|
|
const groupSection = (
|
|
|
|
<a
|
|
|
|
className={clsx(
|
2022-10-04 15:23:07 +00:00
|
|
|
'bg-greyscale-4 max-w-[200px] truncate whitespace-nowrap rounded-full py-0.5 px-2 text-xs text-white sm:max-w-[250px]',
|
2022-10-01 01:30:45 +00:00
|
|
|
!disabled && 'hover:bg-greyscale-3 cursor-pointer'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{groupToDisplay.name}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
|
|
|
|
return disabled ? (
|
|
|
|
groupSection
|
|
|
|
) : (
|
2022-09-16 00:41:25 +00:00
|
|
|
<Link prefetch={false} href={groupPath(groupToDisplay.slug)}>
|
2022-10-01 01:30:45 +00:00
|
|
|
{groupSection}
|
2022-09-16 00:41:25 +00:00
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
} else
|
|
|
|
return (
|
2022-09-30 16:00:55 +00:00
|
|
|
<div className="bg-greyscale-4 truncate rounded-full py-0.5 px-2 text-xs text-white">
|
2022-09-16 22:21:07 +00:00
|
|
|
No Group
|
|
|
|
</div>
|
2022-09-16 00:41:25 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-20 03:34:41 +00:00
|
|
|
function EditableCloseDate(props: {
|
|
|
|
closeTime: number
|
|
|
|
contract: Contract
|
|
|
|
isCreator: boolean
|
2022-10-01 01:30:45 +00:00
|
|
|
disabled?: boolean
|
2022-04-20 03:34:41 +00:00
|
|
|
}) {
|
2022-10-01 01:30:45 +00:00
|
|
|
const { closeTime, contract, isCreator, disabled } = props
|
2022-04-20 03:34:41 +00:00
|
|
|
|
2022-10-12 21:07:07 +00:00
|
|
|
const isClient = useIsClient()
|
2022-08-13 00:48:41 +00:00
|
|
|
const dayJsCloseTime = dayjs(closeTime)
|
|
|
|
const dayJsNow = dayjs()
|
|
|
|
|
2022-04-20 03:34:41 +00:00
|
|
|
const [isEditingCloseTime, setIsEditingCloseTime] = useState(false)
|
|
|
|
const [closeDate, setCloseDate] = useState(
|
2022-08-28 05:35:22 +00:00
|
|
|
closeTime && dayJsCloseTime.format('YYYY-MM-DD')
|
2022-04-20 03:34:41 +00:00
|
|
|
)
|
2022-08-28 05:35:22 +00:00
|
|
|
const [closeHoursMinutes, setCloseHoursMinutes] = useState(
|
|
|
|
closeTime && dayJsCloseTime.format('HH:mm')
|
|
|
|
)
|
|
|
|
|
2022-08-13 00:48:41 +00:00
|
|
|
const isSameYear = dayJsCloseTime.isSame(dayJsNow, 'year')
|
|
|
|
const isSameDay = dayJsCloseTime.isSame(dayJsNow, 'day')
|
2022-04-20 03:34:41 +00:00
|
|
|
|
2022-09-30 14:40:46 +00:00
|
|
|
let newCloseTime = closeDate
|
|
|
|
? dayjs(`${closeDate}T${closeHoursMinutes}`).valueOf()
|
|
|
|
: undefined
|
|
|
|
function onSave(customTime?: number) {
|
|
|
|
if (customTime) {
|
|
|
|
newCloseTime = customTime
|
|
|
|
setCloseDate(dayjs(newCloseTime).format('YYYY-MM-DD'))
|
|
|
|
setCloseHoursMinutes(dayjs(newCloseTime).format('HH:mm'))
|
|
|
|
}
|
2022-08-28 05:35:22 +00:00
|
|
|
if (!newCloseTime) return
|
|
|
|
|
2022-04-20 03:34:41 +00:00
|
|
|
if (newCloseTime === closeTime) setIsEditingCloseTime(false)
|
2022-09-30 14:40:46 +00:00
|
|
|
else {
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
const content = contract.description
|
2022-04-20 03:34:41 +00:00
|
|
|
const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a')
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
|
2022-10-11 01:47:02 +00:00
|
|
|
const editor = new Editor({ content, extensions: editorExtensions() })
|
2022-08-11 21:32:02 +00:00
|
|
|
editor.commands.focus('end')
|
|
|
|
insertContent(
|
2022-08-06 22:43:41 +00:00
|
|
|
editor,
|
|
|
|
`<br><p>Close date updated to ${formattedCloseDate}</p>`
|
|
|
|
)
|
2022-04-20 03:34:41 +00:00
|
|
|
|
2022-06-15 04:31:20 +00:00
|
|
|
updateContract(contract.id, {
|
2022-04-20 03:34:41 +00:00
|
|
|
closeTime: newCloseTime,
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* fix extension import (backend)
In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`
Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *
If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
description: editor.getJSON(),
|
2022-06-15 04:31:20 +00:00
|
|
|
})
|
|
|
|
|
2022-04-20 03:34:41 +00:00
|
|
|
setIsEditingCloseTime(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-09-16 07:38:09 +00:00
|
|
|
<Modal
|
2022-10-05 00:06:59 +00:00
|
|
|
size="md"
|
2022-09-16 07:38:09 +00:00
|
|
|
open={isEditingCloseTime}
|
|
|
|
setOpen={setIsEditingCloseTime}
|
|
|
|
position="top"
|
|
|
|
>
|
|
|
|
<Col className="rounded bg-white px-8 pb-8">
|
2022-10-05 00:06:59 +00:00
|
|
|
<Subtitle text="Edit market close time" />
|
|
|
|
<Row className="z-10 mr-2 mt-4 w-full shrink-0 flex-wrap items-center gap-2">
|
2022-10-10 02:37:24 +00:00
|
|
|
<Input
|
2022-09-16 07:38:09 +00:00
|
|
|
type="date"
|
2022-10-10 02:37:24 +00:00
|
|
|
className="w-full shrink-0 sm:w-fit"
|
2022-09-16 07:38:09 +00:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setCloseDate(e.target.value)}
|
2022-10-12 21:07:07 +00:00
|
|
|
min={isClient ? Date.now() : undefined}
|
2022-09-16 07:38:09 +00:00
|
|
|
value={closeDate}
|
|
|
|
/>
|
2022-10-10 02:37:24 +00:00
|
|
|
<Input
|
2022-09-16 07:38:09 +00:00
|
|
|
type="time"
|
2022-10-10 02:37:24 +00:00
|
|
|
className="w-full shrink-0 sm:w-max"
|
2022-09-16 07:38:09 +00:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => setCloseHoursMinutes(e.target.value)}
|
|
|
|
min="00:00"
|
|
|
|
value={closeHoursMinutes}
|
|
|
|
/>
|
2022-10-05 00:06:59 +00:00
|
|
|
<Button size={'xs'} color={'indigo'} onClick={() => onSave()}>
|
|
|
|
Set
|
|
|
|
</Button>
|
2022-09-16 07:38:09 +00:00
|
|
|
</Row>
|
2022-10-05 00:06:59 +00:00
|
|
|
|
2022-09-16 07:38:09 +00:00
|
|
|
<Button
|
2022-10-05 00:06:59 +00:00
|
|
|
className="mt-8"
|
2022-09-30 14:40:46 +00:00
|
|
|
size={'xs'}
|
2022-10-05 00:06:59 +00:00
|
|
|
color="red"
|
2022-09-30 14:40:46 +00:00
|
|
|
onClick={() => onSave(Date.now())}
|
|
|
|
>
|
2022-10-05 00:06:59 +00:00
|
|
|
Close market now
|
2022-09-30 14:40:46 +00:00
|
|
|
</Button>
|
2022-09-16 07:38:09 +00:00
|
|
|
</Col>
|
|
|
|
</Modal>
|
|
|
|
<DateTimeTooltip
|
2022-10-12 21:07:07 +00:00
|
|
|
text={
|
|
|
|
isClient && closeTime <= Date.now()
|
|
|
|
? 'Trading ended:'
|
|
|
|
: 'Trading ends:'
|
|
|
|
}
|
2022-09-16 07:38:09 +00:00
|
|
|
time={closeTime}
|
|
|
|
>
|
2022-10-03 22:18:56 +00:00
|
|
|
<Row
|
|
|
|
className={clsx(!disabled && isCreator ? 'cursor-pointer' : '')}
|
2022-10-01 01:30:45 +00:00
|
|
|
onClick={() => !disabled && isCreator && setIsEditingCloseTime(true)}
|
2022-04-20 03:34:41 +00:00
|
|
|
>
|
2022-10-12 21:07:07 +00:00
|
|
|
{isSameDay && isClient ? (
|
2022-09-16 07:38:09 +00:00
|
|
|
<span className={'capitalize'}> {fromNow(closeTime)}</span>
|
|
|
|
) : isSameYear ? (
|
|
|
|
dayJsCloseTime.format('MMM D')
|
|
|
|
) : (
|
|
|
|
dayJsCloseTime.format('MMM D, YYYY')
|
|
|
|
)}
|
2022-10-03 22:18:56 +00:00
|
|
|
{isCreator && !disabled && <PencilIcon className="ml-1 h-4 w-4" />}
|
|
|
|
</Row>
|
2022-09-16 07:38:09 +00:00
|
|
|
</DateTimeTooltip>
|
2022-04-20 03:34:41 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-10-03 09:49:19 +00:00
|
|
|
|
|
|
|
const BAD_CREATOR_THRESHOLD = 0.8
|