From b375256e96824c7205103cd100bc384723386b0d Mon Sep 17 00:00:00 2001 From: jahooma Date: Sun, 2 Jan 2022 14:53:42 -0600 Subject: [PATCH] Reuse ResolutionOrChance component. Make smaller for card, larger for contract page. --- web/components/contract-card.tsx | 80 +++++++++++++++++++--------- web/components/contract-overview.tsx | 38 ++----------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx index bcfd0935..8fc729f7 100644 --- a/web/components/contract-card.tsx +++ b/web/components/contract-card.tsx @@ -5,27 +5,13 @@ import { formatMoney } from '../lib/util/format' import { UserLink } from './user-page' import { Linkify } from './linkify' import { Contract, compute, path } from '../lib/firebase/contracts' +import { Col } from './layout/col' export function ContractCard(props: { contract: Contract }) { const { contract } = props + const { resolution } = contract 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 ( @@ -36,14 +22,11 @@ export function ContractCard(props: { contract: Contract }) {

-
- {resolutionText || ( -
- {probPercent} -
chance
-
- )} -
+ @@ -54,6 +37,55 @@ export function ContractCard(props: { contract: Contract }) { ) } +export function ResolutionOrChance(props: { + resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL' + probPercent: string + large?: boolean + className?: string +}) { + const { resolution, probPercent, large, className } = props + + const resolutionColor = { + YES: 'text-primary', + NO: 'text-red-400', + MKT: 'text-blue-400', + CANCEL: 'text-yellow-400', + '': '', // Empty if unresolved + }[resolution || ''] + + const resolutionText = { + YES: 'YES', + NO: 'NO', + MKT: 'MKT', + CANCEL: 'N/A', + '': '', + }[resolution || ''] + + return ( + + {resolution ? ( + <> +
+ Resolved +
+
{resolutionText}
+ + ) : ( + <> +
{probPercent}
+
+ chance +
+ + )} + + ) +} + export function ContractDetails(props: { contract: Contract }) { const { contract } = props const { truePool, createdDate, resolvedDate } = compute(contract) diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 3dc5230c..23f2e7fb 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -14,7 +14,7 @@ import { Row } from './layout/row' import dayjs from 'dayjs' import { Linkify } from './linkify' import clsx from 'clsx' -import { ContractDetails } from './contract-card' +import { ContractDetails, ResolutionOrChance } from './contract-card' function ContractDescription(props: { contract: Contract @@ -84,40 +84,6 @@ 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 @@ -141,6 +107,7 @@ export const ContractOverview = (props: { className="md:hidden" resolution={resolution} probPercent={probPercent} + large /> @@ -150,6 +117,7 @@ export const ContractOverview = (props: { className="hidden md:flex md:items-end" resolution={resolution} probPercent={probPercent} + large />