From 94624c5387d1048f16957227f913fca267745a29 Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Wed, 5 Oct 2022 18:02:24 -0700 Subject: [PATCH] Create common card component (#1012) * Create common card component * lint --- web/components/card.tsx | 16 +++++ web/components/charity/charity-card.tsx | 67 ++++++++++--------- web/components/contract/contract-card.tsx | 22 ++---- web/components/contract/prob-change-table.tsx | 42 ++---------- web/components/post-card.tsx | 8 +-- 5 files changed, 69 insertions(+), 86 deletions(-) create mode 100644 web/components/card.tsx diff --git a/web/components/card.tsx b/web/components/card.tsx new file mode 100644 index 00000000..e9d7f8c5 --- /dev/null +++ b/web/components/card.tsx @@ -0,0 +1,16 @@ +import clsx from 'clsx' + +export function Card(props: JSX.IntrinsicElements['div']) { + const { children, className, ...rest } = props + return ( +
+ {children} +
+ ) +} diff --git a/web/components/charity/charity-card.tsx b/web/components/charity/charity-card.tsx index fc327b9f..5222f284 100644 --- a/web/components/charity/charity-card.tsx +++ b/web/components/charity/charity-card.tsx @@ -6,6 +6,8 @@ import { Charity } from 'common/charity' import { useCharityTxns } from 'web/hooks/use-charity-txns' import { manaToUSD } from '../../../common/util/format' import { Row } from '../layout/row' +import { Col } from '../layout/col' +import { Card } from '../card' export function CharityCard(props: { charity: Charity; match?: number }) { const { charity } = props @@ -15,43 +17,44 @@ export function CharityCard(props: { charity: Charity; match?: number }) { const raised = sumBy(txns, (txn) => txn.amount) return ( - -
- - {tags?.includes('Featured') && } - -
-
- {photo ? ( - - ) : ( -
- )} -
-
-
- {/*

{name}

*/} -
{preview}
- {raised > 0 && ( - <> - - - - {formatUsd(raised)} - - raised - - {/* {match && ( + + + + + {tags?.includes('Featured') && } + +
+
+ {photo ? ( + + ) : ( +
+ )} +
+
+ +
{preview}
+ {raised > 0 && ( + <> + + + + {formatUsd(raised)} + + raised + + {/* {match && ( +{formatUsd(match)} match )} */} - - - )} -
-
+ + + )} + + + ) } diff --git a/web/components/contract/contract-card.tsx b/web/components/contract/contract-card.tsx index 401005bf..a9ee6318 100644 --- a/web/components/contract/contract-card.tsx +++ b/web/components/contract/contract-card.tsx @@ -8,6 +8,7 @@ import { BinaryContract, Contract, CPMMBinaryContract, + CPMMContract, FreeResponseContract, MultipleChoiceContract, NumericContract, @@ -35,6 +36,7 @@ import { getMappedValue } from 'common/pseudo-numeric' import { Tooltip } from '../tooltip' import { SiteLink } from '../site-link' import { ProbChange } from './prob-change-table' +import { Card } from '../card' export function ContractCard(props: { contract: Contract @@ -75,12 +77,7 @@ export function ContractCard(props: { !hideQuickBet return ( - + )} - + ) } @@ -391,7 +388,7 @@ export function PseudoNumericResolutionOrExpectation(props: { } export function ContractCardProbChange(props: { - contract: CPMMBinaryContract + contract: CPMMContract noLinkAvatar?: boolean className?: string }) { @@ -399,12 +396,7 @@ export function ContractCardProbChange(props: { const contract = useContractWithPreload(props.contract) as CPMMBinaryContract return ( - + - + ) } diff --git a/web/components/contract/prob-change-table.tsx b/web/components/contract/prob-change-table.tsx index 6b671830..70eaf18c 100644 --- a/web/components/contract/prob-change-table.tsx +++ b/web/components/contract/prob-change-table.tsx @@ -1,13 +1,10 @@ -import { sortBy } from 'lodash' import clsx from 'clsx' -import { contractPath } from 'web/lib/firebase/contracts' import { CPMMContract } from 'common/contract' import { formatPercent } from 'common/util/format' -import { SiteLink } from '../site-link' +import { sortBy } from 'lodash' import { Col } from '../layout/col' -import { Row } from '../layout/row' import { LoadingIndicator } from '../loading-indicator' -import { useContractWithPreload } from 'web/hooks/use-contract' +import { ContractCardProbChange } from './contract-card' export function ProbChangeTable(props: { changes: CPMMContract[] | undefined @@ -39,46 +36,21 @@ export function ProbChangeTable(props: { if (rows === 0) return
None
return ( - - + + {filteredPositiveChanges.map((contract) => ( - + ))} - + {filteredNegativeChanges.map((contract) => ( - + ))} ) } -export function ProbChangeRow(props: { - contract: CPMMContract - className?: string -}) { - const { className } = props - const contract = - (useContractWithPreload(props.contract) as CPMMContract) ?? props.contract - return ( - - - {contract.question} - - - - ) -} - export function ProbChange(props: { contract: CPMMContract className?: string diff --git a/web/components/post-card.tsx b/web/components/post-card.tsx index ed208f63..19dce45a 100644 --- a/web/components/post-card.tsx +++ b/web/components/post-card.tsx @@ -7,8 +7,8 @@ import { useUserById } from 'web/hooks/use-user' import { postPath } from 'web/lib/firebase/posts' import { fromNow } from 'web/lib/util/time' import { Avatar } from './avatar' +import { Card } from './card' import { CardHighlightOptions } from './contract/contracts-grid' -import { Row } from './layout/row' import { UserLink } from './user-link' export function PostCard(props: { @@ -26,9 +26,9 @@ export function PostCard(props: { return (
- @@ -58,7 +58,7 @@ export function PostCard(props: { Post
- + {onPostClick ? (