Show "Buy" and % directly in FR feed
This commit is contained in:
parent
94f6f08784
commit
e4c9508340
|
@ -31,8 +31,9 @@ export function AnswerBetPanel(props: {
|
||||||
contract: FullContract<DPM, FreeResponse>
|
contract: FullContract<DPM, FreeResponse>
|
||||||
closePanel: () => void
|
closePanel: () => void
|
||||||
className?: string
|
className?: string
|
||||||
|
isModal?: boolean
|
||||||
}) {
|
}) {
|
||||||
const { answer, contract, closePanel, className } = props
|
const { answer, contract, closePanel, className, isModal } = props
|
||||||
const { id: answerId } = answer
|
const { id: answerId } = answer
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
@ -99,11 +100,18 @@ export function AnswerBetPanel(props: {
|
||||||
return (
|
return (
|
||||||
<Col className={clsx('px-2 pb-2 pt-4 sm:pt-0', className)}>
|
<Col className={clsx('px-2 pb-2 pt-4 sm:pt-0', className)}>
|
||||||
<Row className="items-center justify-between self-stretch">
|
<Row className="items-center justify-between self-stretch">
|
||||||
<div className="text-xl">Buy this answer</div>
|
<div className="text-xl">
|
||||||
|
Buy {isModal ? `"${answer.text}"` : 'this answer'}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!isModal && (
|
||||||
<button className="btn-ghost btn-circle" onClick={closePanel}>
|
<button className="btn-ghost btn-circle" onClick={closePanel}>
|
||||||
<XIcon className="mx-auto h-8 w-8 text-gray-500" aria-hidden="true" />
|
<XIcon
|
||||||
|
className="mx-auto h-8 w-8 text-gray-500"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
<div className="my-3 text-left text-sm text-gray-500">Amount </div>
|
<div className="my-3 text-left text-sm text-gray-500">Amount </div>
|
||||||
<AmountInput
|
<AmountInput
|
||||||
|
|
|
@ -26,7 +26,7 @@ import { useUser } from '../../hooks/use-user'
|
||||||
import { Linkify } from '../linkify'
|
import { Linkify } from '../linkify'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { createComment, MAX_COMMENT_LENGTH } from '../../lib/firebase/comments'
|
import { createComment, MAX_COMMENT_LENGTH } from '../../lib/firebase/comments'
|
||||||
import { formatMoney } from '../../../common/util/format'
|
import { formatMoney, formatPercent } from '../../../common/util/format'
|
||||||
import { Comment } from '../../../common/comment'
|
import { Comment } from '../../../common/comment'
|
||||||
import { ResolutionOrChance } from '../contract-card'
|
import { ResolutionOrChance } from '../contract-card'
|
||||||
import { SiteLink } from '../site-link'
|
import { SiteLink } from '../site-link'
|
||||||
|
@ -36,13 +36,18 @@ import { DateTimeTooltip } from '../datetime-tooltip'
|
||||||
import { Bet } from '../../lib/firebase/bets'
|
import { Bet } from '../../lib/firebase/bets'
|
||||||
import { JoinSpans } from '../join-spans'
|
import { JoinSpans } from '../join-spans'
|
||||||
import { fromNow } from '../../lib/util/time'
|
import { fromNow } from '../../lib/util/time'
|
||||||
import BetRow from '../bet-row'
|
import BetRow, { Modal } from '../bet-row'
|
||||||
import { parseTags } from '../../../common/util/parse'
|
import { parseTags } from '../../../common/util/parse'
|
||||||
import { Avatar } from '../avatar'
|
import { Avatar } from '../avatar'
|
||||||
import { useAdmin } from '../../hooks/use-admin'
|
import { useAdmin } from '../../hooks/use-admin'
|
||||||
import { Answer } from '../../../common/answer'
|
import { Answer } from '../../../common/answer'
|
||||||
import { ActivityItem } from './activity-items'
|
import { ActivityItem } from './activity-items'
|
||||||
import { FreeResponse, FullContract } from '../../../common/contract'
|
import { FreeResponse, FullContract } from '../../../common/contract'
|
||||||
|
import { BuyButton } from '../yes-no-selector'
|
||||||
|
import { AnswerItem } from '../answers/answer-item'
|
||||||
|
import { getDpmOutcomeProbability } from '../../../common/calculate-dpm'
|
||||||
|
import { BetPanel } from '../bet-panel'
|
||||||
|
import { AnswerBetPanel } from '../answers/answer-bet-panel'
|
||||||
|
|
||||||
export function FeedItems(props: {
|
export function FeedItems(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -659,11 +664,25 @@ function FeedAnswerGroup(props: {
|
||||||
answer: Answer
|
answer: Answer
|
||||||
items: ActivityItem[]
|
items: ActivityItem[]
|
||||||
}) {
|
}) {
|
||||||
const { answer, items } = props
|
const { answer, items, contract } = props
|
||||||
const { username, avatarUrl, name, text } = answer
|
const { username, avatarUrl, name, text } = answer
|
||||||
|
|
||||||
|
const prob = getDpmOutcomeProbability(contract.totalShares, answer.id)
|
||||||
|
const probPercent = formatPercent(prob)
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="flex-1 gap-2">
|
<Col className="flex-1 gap-2">
|
||||||
|
<Modal open={open} setOpen={setOpen}>
|
||||||
|
<AnswerBetPanel
|
||||||
|
answer={answer}
|
||||||
|
contract={contract}
|
||||||
|
closePanel={() => setOpen(false)}
|
||||||
|
className="sm:max-w-84 !rounded-md bg-white !px-8 !py-6"
|
||||||
|
isModal={true}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<Row className="my-4 gap-3">
|
<Row className="my-4 gap-3">
|
||||||
<div className="px-1">
|
<div className="px-1">
|
||||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
||||||
|
@ -674,9 +693,29 @@ function FeedAnswerGroup(props: {
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
<UserLink username={username} name={name} /> answered
|
<UserLink username={username} name={name} /> answered
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Row className="align-items justify-between gap-4">
|
||||||
<span className="text-lg">
|
<span className="text-lg">
|
||||||
<Linkify text={text} />
|
<Linkify text={text} />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<Row className="align-items justify-end gap-4">
|
||||||
|
<span
|
||||||
|
className={clsx(
|
||||||
|
'text-2xl',
|
||||||
|
tradingAllowed(contract) ? 'text-green-500' : 'text-gray-500'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{probPercent}
|
||||||
|
</span>
|
||||||
|
<BuyButton
|
||||||
|
className="btn-sm hidden flex-initial !px-6 sm:flex"
|
||||||
|
onClick={() => {
|
||||||
|
setOpen(true)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Row>
|
||||||
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
@ -699,6 +738,15 @@ function FeedAnswerGroup(props: {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
<div className="ml-10 mt-4">
|
||||||
|
<BuyButton
|
||||||
|
className="btn-sm !px-6 sm:hidden"
|
||||||
|
onClick={() => {
|
||||||
|
setOpen(true)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,10 +158,18 @@ export function FundsSelector(props: {
|
||||||
|
|
||||||
export function BuyButton(props: { className?: string; onClick?: () => void }) {
|
export function BuyButton(props: { className?: string; onClick?: () => void }) {
|
||||||
const { className, onClick } = props
|
const { className, onClick } = props
|
||||||
|
// Note: styles coppied from YesNoSelector
|
||||||
return (
|
return (
|
||||||
<Button className={className} onClick={onClick} color="green">
|
<button
|
||||||
BUY
|
className={clsx(
|
||||||
</Button>
|
'hover:bg-primary-focus border-primary hover:border-primary-focus inline-flex flex-1 items-center justify-center rounded-lg border-2 p-2 hover:text-white',
|
||||||
|
'text-primary bg-transparent text-lg',
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
Buy
|
||||||
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user