diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx new file mode 100644 index 00000000..bcfd0935 --- /dev/null +++ b/web/components/contract-card.tsx @@ -0,0 +1,74 @@ +import clsx from 'clsx' +import Link from 'next/link' +import { Row } from '../components/layout/row' +import { formatMoney } from '../lib/util/format' +import { UserLink } from './user-page' +import { Linkify } from './linkify' +import { Contract, compute, path } from '../lib/firebase/contracts' + +export function ContractCard(props: { contract: Contract }) { + const { contract } = props + const { probPercent } = compute(contract) + + const resolutionColor = { + YES: 'text-primary', + NO: 'text-red-400', + MKT: 'text-blue-400', + CANCEL: 'text-yellow-400', + '': '', // Empty if unresolved + }[contract.resolution || ''] + + const resolutionText = { + YES: 'YES', + NO: 'NO', + MKT: 'MKT', + CANCEL: 'N/A', + '': '', + }[contract.resolution || ''] + + return ( + + +
  • +
    +
    + +

    + +

    +
    + {resolutionText || ( +
    + {probPercent} +
    chance
    +
    + )} +
    +
    + +
    +
    +
  • +
    + + ) +} + +export function ContractDetails(props: { contract: Contract }) { + const { contract } = props + const { truePool, createdDate, resolvedDate } = compute(contract) + + return ( + +
    + +
    +
    +
    + {resolvedDate ? `${createdDate} - ${resolvedDate}` : createdDate} +
    +
    +
    {formatMoney(truePool)} pool
    +
    + ) +} diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index ec2fc4cb..3dc5230c 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -8,13 +8,13 @@ import { import { Col } from './layout/col' import { Spacer } from './layout/spacer' import { ContractProbGraph } from './contract-prob-graph' -import { ContractDetails } from './contracts-list' import router from 'next/router' import { useUser } from '../hooks/use-user' import { Row } from './layout/row' import dayjs from 'dayjs' import { Linkify } from './linkify' import clsx from 'clsx' +import { ContractDetails } from './contract-card' function ContractDescription(props: { contract: Contract @@ -35,7 +35,7 @@ function ContractDescription(props: { } return ( -
    +

    {isCreator && @@ -84,6 +84,40 @@ function ContractDescription(props: { ) } +function ResolutionOrChance(props: { + resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL' + probPercent: string + className?: string +}) { + const { resolution, probPercent, className } = props + + const resolutionColor = { + YES: 'text-primary', + NO: 'text-red-400', + MKT: 'text-blue-400', + CANCEL: 'text-yellow-400', + '': '', // Empty if unresolved + }[resolution || ''] + + return ( + + {resolution ? ( + <> +
    Resolved
    +
    + {resolution === 'CANCEL' ? 'N/A' : resolution} +
    + + ) : ( + <> +
    {probPercent}
    +
    chance
    + + )} + + ) +} + export const ContractOverview = (props: { contract: Contract className?: string @@ -95,39 +129,29 @@ export const ContractOverview = (props: { const user = useUser() const isCreator = user?.id === creatorId - const resolutionColor = { - YES: 'text-primary', - NO: 'text-red-400', - MKT: 'text-blue-400', - CANCEL: 'text-yellow-400', - '': '', // Empty if unresolved - }[contract.resolution || ''] - return ( - - -
    + + +
    + + - {resolution ? ( - -
    Resolved
    -
    - {resolution === 'CANCEL' ? 'N/A' : resolution} -
    - - ) : ( - - {probPercent} -
    chance
    - - )} - + +
    diff --git a/web/components/contracts-list.tsx b/web/components/contracts-list.tsx index dc83bafb..715a7ffe 100644 --- a/web/components/contracts-list.tsx +++ b/web/components/contracts-list.tsx @@ -3,87 +3,17 @@ import Link from 'next/link' import clsx from 'clsx' import { useEffect, useState } from 'react' -import { Row } from '../components/layout/row' import { compute, Contract, listContracts, path, } from '../lib/firebase/contracts' -import { formatMoney } from '../lib/util/format' import { User } from '../lib/firebase/users' -import { UserLink } from './user-page' -import { Linkify } from './linkify' import { Col } from './layout/col' import { SiteLink } from './site-link' import { parseTags } from '../lib/util/parse' - -export function ContractDetails(props: { contract: Contract }) { - const { contract } = props - const { truePool, createdDate, resolvedDate } = compute(contract) - - return ( - -
    - -
    -
    -
    - {resolvedDate ? `${createdDate} - ${resolvedDate}` : createdDate} -
    -
    -
    {formatMoney(truePool)} pool
    -
    - ) -} - -function ContractCard(props: { contract: Contract }) { - const { contract } = props - const { probPercent } = compute(contract) - - const resolutionColor = { - YES: 'text-primary', - NO: 'text-red-400', - MKT: 'text-blue-400', - CANCEL: 'text-yellow-400', - '': '', // Empty if unresolved - }[contract.resolution || ''] - - const resolutionText = { - YES: 'YES', - NO: 'NO', - MKT: 'MKT', - CANCEL: 'N/A', - '': '', - }[contract.resolution || ''] - - return ( - - -
  • -
    -
    - -

    - -

    -
    - {resolutionText || ( -
    - {probPercent} -
    chance
    -
    - )} -
    -
    - -
    -
    -
  • -
    - - ) -} +import { ContractCard } from './contract-card' function ContractsGrid(props: { contracts: Contract[] }) { const [resolvedContracts, activeContracts] = _.partition( @@ -117,7 +47,7 @@ function ContractsGrid(props: { contracts: Contract[] }) { const MAX_GROUPED_CONTRACTS_DISPLAYED = 6 -export function CreatorContractsGrid(props: { contracts: Contract[] }) { +function CreatorContractsGrid(props: { contracts: Contract[] }) { const { contracts } = props const byCreator = _.groupBy(contracts, (contract) => contract.creatorId) @@ -165,7 +95,7 @@ export function CreatorContractsGrid(props: { contracts: Contract[] }) { ) } -export function TagContractsGrid(props: { contracts: Contract[] }) { +function TagContractsGrid(props: { contracts: Contract[] }) { const { contracts } = props const contractTags = _.flatMap(contracts, (contract) =>