Move tweet button into contract details

This commit is contained in:
James Grugett 2022-02-22 21:38:53 -06:00
parent b7af65eec3
commit 7bc43682b8
2 changed files with 25 additions and 31 deletions

View File

@ -19,6 +19,7 @@ import { fromNow } from '../lib/util/time'
import { Avatar } from './avatar' import { Avatar } from './avatar'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
import { useState } from 'react' import { useState } from 'react'
import { TweetButton } from './tweet-button'
export function ContractCard(props: { export function ContractCard(props: {
contract: Contract contract: Contract
@ -165,12 +166,13 @@ function AbbrContractDetails(props: {
export function ContractDetails(props: { export function ContractDetails(props: {
contract: Contract contract: Contract
isCreator?: boolean isCreator?: boolean
children?: any
}) { }) {
const { contract, isCreator, children } = props const { contract, isCreator } = props
const { closeTime, creatorName, creatorUsername } = contract const { closeTime, creatorName, creatorUsername } = contract
const { truePool, createdDate, resolvedDate } = contractMetrics(contract) const { truePool, createdDate, resolvedDate } = contractMetrics(contract)
const tweetText = getTweetText(contract, !!isCreator)
return ( return (
<Col className="gap-2 text-sm text-gray-500 sm:flex-row sm:flex-wrap"> <Col className="gap-2 text-sm text-gray-500 sm:flex-row sm:flex-wrap">
<Row className="flex-wrap items-center gap-x-4 gap-y-2"> <Row className="flex-wrap items-center gap-x-4 gap-y-2">
@ -224,7 +226,7 @@ export function ContractDetails(props: {
<div className="whitespace-nowrap">{formatMoney(truePool)} pool</div> <div className="whitespace-nowrap">{formatMoney(truePool)} pool</div>
</Row> </Row>
{children} <TweetButton className={'self-end'} tweetText={tweetText} />
</Row> </Row>
</Col> </Col>
) )
@ -316,3 +318,22 @@ function EditableCloseDate(props: {
</> </>
) )
} }
const getTweetText = (contract: Contract, isCreator: boolean) => {
const { question, creatorName, resolution, outcomeType } = contract
const isBinary = outcomeType === 'BINARY'
const tweetQuestion = isCreator
? question
: `${question} Asked by ${creatorName}.`
const tweetDescription = resolution
? `Resolved ${resolution}!`
: isBinary
? `Currently ${getBinaryProbPercent(
contract
)} chance, place your bets here:`
: `Submit your own answer:`
const url = `https://manifold.markets${contractPath(contract)}`
return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
}

View File

@ -1,9 +1,7 @@
import { import {
Contract, Contract,
deleteContract, deleteContract,
contractPath,
tradingAllowed, tradingAllowed,
getBinaryProbPercent,
} from '../lib/firebase/contracts' } from '../lib/firebase/contracts'
import { Col } from './layout/col' import { Col } from './layout/col'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
@ -15,7 +13,6 @@ import { Linkify } from './linkify'
import clsx from 'clsx' import clsx from 'clsx'
import { ContractDetails, ResolutionOrChance } from './contract-card' import { ContractDetails, ResolutionOrChance } from './contract-card'
import { ContractFeed } from './contract-feed' import { ContractFeed } from './contract-feed'
import { TweetButton } from './tweet-button'
import { Bet } from '../../common/bet' import { Bet } from '../../common/bet'
import { Comment } from '../../common/comment' import { Comment } from '../../common/comment'
import { RevealableTagsInput, TagsInput } from './tags-input' import { RevealableTagsInput, TagsInput } from './tags-input'
@ -38,8 +35,6 @@ export const ContractOverview = (props: {
const isCreator = user?.id === creatorId const isCreator = user?.id === creatorId
const isBinary = outcomeType === 'BINARY' const isBinary = outcomeType === 'BINARY'
const tweetText = getTweetText(contract, isCreator)
return ( return (
<Col className={clsx('mb-6', className)}> <Col className={clsx('mb-6', className)}>
<Row className="justify-between gap-4 px-2"> <Row className="justify-between gap-4 px-2">
@ -66,9 +61,7 @@ export const ContractOverview = (props: {
)} )}
</Row> </Row>
<ContractDetails contract={contract} isCreator={isCreator}> <ContractDetails contract={contract} isCreator={isCreator} />
<TweetButton className="md:hidden self-end" tweetText={tweetText} />
</ContractDetails>
</Col> </Col>
{(isBinary || resolution) && ( {(isBinary || resolution) && (
@ -78,7 +71,6 @@ export const ContractOverview = (props: {
contract={contract} contract={contract}
large large
/> />
<TweetButton tweetText={tweetText} />
</Col> </Col>
)} )}
</Row> </Row>
@ -137,22 +129,3 @@ export const ContractOverview = (props: {
</Col> </Col>
) )
} }
const getTweetText = (contract: Contract, isCreator: boolean) => {
const { question, creatorName, resolution, outcomeType } = contract
const isBinary = outcomeType === 'BINARY'
const tweetQuestion = isCreator
? question
: `${question} Asked by ${creatorName}.`
const tweetDescription = resolution
? `Resolved ${resolution}!`
: isBinary
? `Currently ${getBinaryProbPercent(
contract
)} chance, place your bets here:`
: `Submit your own answer:`
const url = `https://manifold.markets${contractPath(contract)}`
return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
}