2022-01-04 07:21:14 +00:00
|
|
|
// From https://tailwindui.com/components/application-ui/lists/feeds
|
2022-08-09 22:28:27 +00:00
|
|
|
import React from 'react'
|
2022-01-04 07:21:14 +00:00
|
|
|
import {
|
|
|
|
BanIcon,
|
|
|
|
CheckIcon,
|
|
|
|
LockClosedIcon,
|
|
|
|
XIcon,
|
|
|
|
} from '@heroicons/react/solid'
|
2022-01-27 23:14:18 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
import { OutcomeLabel } from '../outcome-label'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
2022-01-12 19:01:04 +00:00
|
|
|
contractPath,
|
2022-01-26 20:08:03 +00:00
|
|
|
tradingAllowed,
|
2022-05-09 13:04:36 +00:00
|
|
|
} from 'web/lib/firebase/contracts'
|
2022-04-18 23:02:40 +00:00
|
|
|
import { BinaryResolutionOrChance } from '../contract/contract-card'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { SiteLink } from '../site-link'
|
|
|
|
import { Col } from '../layout/col'
|
|
|
|
import { UserLink } from '../user-page'
|
2022-08-19 17:07:48 +00:00
|
|
|
import BetButton from '../bet-button'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { Avatar } from '../avatar'
|
2022-05-17 15:55:26 +00:00
|
|
|
import { ActivityItem } from './activity-items'
|
2022-07-21 07:38:26 +00:00
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { trackClick } from 'web/lib/firebase/tracking'
|
|
|
|
import { DAY_MS } from 'common/util/time'
|
2022-04-21 06:03:16 +00:00
|
|
|
import NewContractBadge from '../new-contract-badge'
|
2022-05-05 22:30:30 +00:00
|
|
|
import { RelativeTimestamp } from '../relative-timestamp'
|
2022-05-17 15:55:26 +00:00
|
|
|
import { FeedAnswerCommentGroup } from 'web/components/feed/feed-answer-comment-group'
|
2022-05-18 14:42:13 +00:00
|
|
|
import {
|
|
|
|
FeedCommentThread,
|
|
|
|
CommentInput,
|
|
|
|
} from 'web/components/feed/feed-comments'
|
2022-06-14 13:13:24 +00:00
|
|
|
import { FeedBet } from 'web/components/feed/feed-bets'
|
2022-07-10 18:05:44 +00:00
|
|
|
import { CPMMBinaryContract, NumericContract } from 'common/contract'
|
2022-06-27 00:00:02 +00:00
|
|
|
import { FeedLiquidity } from './feed-liquidity'
|
2022-07-26 00:45:33 +00:00
|
|
|
import { SignUpPrompt } from '../sign-up-prompt'
|
|
|
|
import { User } from 'common/user'
|
|
|
|
import { PlayMoneyDisclaimer } from '../play-money-disclaimer'
|
2022-08-19 17:43:57 +00:00
|
|
|
import { contractMetrics } from 'common/contract-details'
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
export function FeedItems(props: {
|
|
|
|
contract: Contract
|
|
|
|
items: ActivityItem[]
|
2022-04-06 05:22:43 +00:00
|
|
|
className?: string
|
2022-03-14 20:29:32 +00:00
|
|
|
betRowClassName?: string
|
2022-07-26 00:45:33 +00:00
|
|
|
user: User | null | undefined
|
2022-03-14 20:29:32 +00:00
|
|
|
}) {
|
2022-07-26 00:45:33 +00:00
|
|
|
const { contract, items, className, betRowClassName, user } = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { outcomeType } = contract
|
|
|
|
|
|
|
|
return (
|
2022-08-09 22:28:27 +00:00
|
|
|
<div className={clsx('flow-root', className)}>
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className={clsx(tradingAllowed(contract) ? '' : '-mb-6')}>
|
|
|
|
{items.map((item, activityItemIdx) => (
|
2022-05-23 22:09:40 +00:00
|
|
|
<div key={item.id} className={'relative pb-4'}>
|
2022-03-14 20:29:32 +00:00
|
|
|
{activityItemIdx !== items.length - 1 ||
|
|
|
|
item.type === 'answergroup' ? (
|
|
|
|
<span
|
|
|
|
className="absolute top-5 left-5 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
2022-05-23 22:09:40 +00:00
|
|
|
<div className="relative flex-col items-start space-x-3">
|
2022-03-14 20:29:32 +00:00
|
|
|
<FeedItem item={item} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-07-26 00:45:33 +00:00
|
|
|
|
|
|
|
{!user ? (
|
|
|
|
<Col className="mt-4 max-w-sm items-center xl:hidden">
|
|
|
|
<SignUpPrompt />
|
|
|
|
<PlayMoneyDisclaimer />
|
|
|
|
</Col>
|
|
|
|
) : (
|
|
|
|
outcomeType === 'BINARY' &&
|
|
|
|
tradingAllowed(contract) && (
|
2022-08-19 17:07:48 +00:00
|
|
|
<BetButton
|
2022-07-26 00:45:33 +00:00
|
|
|
contract={contract as CPMMBinaryContract}
|
|
|
|
className={clsx('mb-2', betRowClassName)}
|
|
|
|
/>
|
|
|
|
)
|
2022-03-14 20:29:32 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-17 15:55:26 +00:00
|
|
|
export function FeedItem(props: { item: ActivityItem }) {
|
2022-03-14 20:29:32 +00:00
|
|
|
const { item } = props
|
|
|
|
|
|
|
|
switch (item.type) {
|
|
|
|
case 'question':
|
|
|
|
return <FeedQuestion {...item} />
|
|
|
|
case 'description':
|
|
|
|
return <FeedDescription {...item} />
|
|
|
|
case 'bet':
|
|
|
|
return <FeedBet {...item} />
|
2022-06-27 00:00:02 +00:00
|
|
|
case 'liquidity':
|
|
|
|
return <FeedLiquidity {...item} />
|
2022-03-14 20:29:32 +00:00
|
|
|
case 'answergroup':
|
2022-05-17 15:55:26 +00:00
|
|
|
return <FeedAnswerCommentGroup {...item} />
|
2022-03-14 20:29:32 +00:00
|
|
|
case 'close':
|
|
|
|
return <FeedClose {...item} />
|
|
|
|
case 'resolve':
|
|
|
|
return <FeedResolve {...item} />
|
2022-04-21 17:09:06 +00:00
|
|
|
case 'commentInput':
|
|
|
|
return <CommentInput {...item} />
|
2022-05-11 21:11:46 +00:00
|
|
|
case 'commentThread':
|
|
|
|
return <FeedCommentThread {...item} />
|
2022-03-14 20:29:32 +00:00
|
|
|
}
|
2022-03-10 06:29:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
export function FeedQuestion(props: {
|
2022-03-05 00:06:11 +00:00
|
|
|
contract: Contract
|
2022-04-11 21:13:26 +00:00
|
|
|
contractPath?: string
|
2022-03-05 00:06:11 +00:00
|
|
|
}) {
|
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 { contract } = props
|
2022-04-20 22:25:29 +00:00
|
|
|
const {
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
question,
|
|
|
|
outcomeType,
|
|
|
|
volume,
|
|
|
|
createdTime,
|
2022-06-17 03:52:53 +00:00
|
|
|
isResolved,
|
2022-04-20 22:25:29 +00:00
|
|
|
} = contract
|
2022-03-23 05:02:47 +00:00
|
|
|
const { volumeLabel } = contractMetrics(contract)
|
2022-02-17 23:00:19 +00:00
|
|
|
const isBinary = outcomeType === 'BINARY'
|
2022-06-17 03:52:53 +00:00
|
|
|
const isNew = createdTime > Date.now() - DAY_MS && !isResolved
|
2022-07-21 07:38:26 +00:00
|
|
|
const user = useUser()
|
2022-01-11 16:56:26 +00:00
|
|
|
|
|
|
|
return (
|
2022-05-23 22:09:40 +00:00
|
|
|
<div className={'flex gap-2'}>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-11 16:56:26 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-2 text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-01-22 00:10:38 +00:00
|
|
|
asked
|
2022-02-24 04:20:42 +00:00
|
|
|
{/* Currently hidden on mobile; ideally we'd fit this in somewhere. */}
|
2022-04-21 06:03:16 +00:00
|
|
|
<div className="relative -top-2 float-right ">
|
2022-04-20 22:25:29 +00:00
|
|
|
{isNew || volume === 0 ? (
|
2022-04-21 06:03:16 +00:00
|
|
|
<NewContractBadge />
|
2022-04-20 22:25:29 +00:00
|
|
|
) : (
|
2022-04-21 06:03:16 +00:00
|
|
|
<span className="hidden text-gray-400 sm:inline">
|
2022-04-20 22:25:29 +00:00
|
|
|
{volumeLabel}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
2022-03-05 00:06:11 +00:00
|
|
|
<Col className="items-start justify-between gap-2 sm:flex-row sm:gap-4">
|
2022-05-09 22:50:20 +00:00
|
|
|
<SiteLink
|
|
|
|
href={
|
|
|
|
props.contractPath ? props.contractPath : contractPath(contract)
|
|
|
|
}
|
2022-07-21 07:38:26 +00:00
|
|
|
onClick={() => user && trackClick(user.id, contract.id)}
|
2022-05-09 22:50:20 +00:00
|
|
|
className="text-lg text-indigo-700 sm:text-xl"
|
|
|
|
>
|
|
|
|
{question}
|
|
|
|
</SiteLink>
|
2022-04-18 23:02:40 +00:00
|
|
|
{isBinary && (
|
|
|
|
<BinaryResolutionOrChance
|
|
|
|
className="items-center"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
2022-02-17 23:00:19 +00:00
|
|
|
)}
|
2022-01-11 20:57:44 +00:00
|
|
|
</Col>
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
2022-05-23 22:09:40 +00:00
|
|
|
</div>
|
2022-01-11 16:56:26 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedDescription(props: { contract: Contract }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
created this market <RelativeTimestamp time={contract.createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
function OutcomeIcon(props: { outcome?: string }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { outcome } = props
|
|
|
|
switch (outcome) {
|
|
|
|
case 'YES':
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'NO':
|
|
|
|
return <XIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'CANCEL':
|
|
|
|
return <BanIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-02-17 23:00:19 +00:00
|
|
|
default:
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-01-04 07:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedResolve(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-05-19 17:42:03 +00:00
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
const resolution = contract.resolution || 'CANCEL'
|
|
|
|
|
2022-05-19 17:42:03 +00:00
|
|
|
const resolutionValue = (contract as NumericContract).resolutionValue
|
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<OutcomeIcon outcome={resolution} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
resolved this market to{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={resolution}
|
2022-05-19 17:42:03 +00:00
|
|
|
value={resolutionValue}
|
2022-04-18 23:02:40 +00:00
|
|
|
contract={contract}
|
|
|
|
truncate="long"
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.resolutionTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedClose(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<LockClosedIcon
|
|
|
|
className="h-5 w-5 text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
|
|
|
Trading closed in this market{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.closeTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|