Random contract page fixups (#712)
* Remove some divs and so on * Correctly align bet avatars and text in feed * Extract sidebar component on contract page
This commit is contained in:
		
							parent
							
								
									1e3c5cb936
								
							
						
					
					
						commit
						5715b0e44a
					
				|  | @ -47,14 +47,21 @@ export function Avatar(props: { | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function EmptyAvatar(props: { size?: number; multi?: boolean }) { | export function EmptyAvatar(props: { | ||||||
|   const { size = 8, multi } = props |   className?: string | ||||||
|  |   size?: number | ||||||
|  |   multi?: boolean | ||||||
|  | }) { | ||||||
|  |   const { className, size = 8, multi } = props | ||||||
|   const insize = size - 3 |   const insize = size - 3 | ||||||
|   const Icon = multi ? UsersIcon : UserIcon |   const Icon = multi ? UsersIcon : UserIcon | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div |     <div | ||||||
|       className={`flex flex-shrink-0 h-${size} w-${size} items-center justify-center rounded-full bg-gray-200`} |       className={clsx( | ||||||
|  |         `flex flex-shrink-0 h-${size} w-${size} items-center justify-center rounded-full bg-gray-200`, | ||||||
|  |         className | ||||||
|  |       )} | ||||||
|     > |     > | ||||||
|       <Icon className={`h-${insize} w-${insize} text-gray-500`} aria-hidden /> |       <Icon className={`h-${insize} w-${insize} text-gray-500`} aria-hidden /> | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|  | @ -36,8 +36,7 @@ export function FeedBet(props: { | ||||||
|   const isSelf = user?.id === userId |   const isSelf = user?.id === userId | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <> |     <Row className={'flex w-full items-center gap-2 pt-3'}> | ||||||
|       <Row className={'flex w-full gap-2 pt-3'}> |  | ||||||
|       {isSelf ? ( |       {isSelf ? ( | ||||||
|         <Avatar |         <Avatar | ||||||
|           className={clsx(smallAvatar && 'ml-1')} |           className={clsx(smallAvatar && 'ml-1')} | ||||||
|  | @ -53,21 +52,17 @@ export function FeedBet(props: { | ||||||
|           username={bettor.username} |           username={bettor.username} | ||||||
|         /> |         /> | ||||||
|       ) : ( |       ) : ( | ||||||
|           <div className="relative px-1"> |         <EmptyAvatar className="mx-1" /> | ||||||
|             <EmptyAvatar /> |  | ||||||
|           </div> |  | ||||||
|       )} |       )} | ||||||
|         <div className={'min-w-0 flex-1 py-1.5'}> |  | ||||||
|       <BetStatusText |       <BetStatusText | ||||||
|         bet={bet} |         bet={bet} | ||||||
|         contract={contract} |         contract={contract} | ||||||
|         isSelf={isSelf} |         isSelf={isSelf} | ||||||
|         bettor={bettor} |         bettor={bettor} | ||||||
|         hideOutcome={hideOutcome} |         hideOutcome={hideOutcome} | ||||||
|  |         className="flex-1" | ||||||
|       /> |       /> | ||||||
|         </div> |  | ||||||
|     </Row> |     </Row> | ||||||
|     </> |  | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -77,8 +72,9 @@ export function BetStatusText(props: { | ||||||
|   isSelf: boolean |   isSelf: boolean | ||||||
|   bettor?: User |   bettor?: User | ||||||
|   hideOutcome?: boolean |   hideOutcome?: boolean | ||||||
|  |   className?: string | ||||||
| }) { | }) { | ||||||
|   const { bet, contract, bettor, isSelf, hideOutcome } = props |   const { bet, contract, bettor, isSelf, hideOutcome, className } = props | ||||||
|   const { outcomeType } = contract |   const { outcomeType } = contract | ||||||
|   const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' |   const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' | ||||||
|   const isFreeResponse = outcomeType === 'FREE_RESPONSE' |   const isFreeResponse = outcomeType === 'FREE_RESPONSE' | ||||||
|  | @ -123,7 +119,7 @@ export function BetStatusText(props: { | ||||||
|       : formatPercent(bet.limitProb ?? bet.probAfter) |       : formatPercent(bet.limitProb ?? bet.probAfter) | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div className="text-sm text-gray-500"> |     <div className={clsx('text-sm text-gray-500', className)}> | ||||||
|       {bettor ? ( |       {bettor ? ( | ||||||
|         <UserLink name={bettor.name} username={bettor.username} /> |         <UserLink name={bettor.name} username={bettor.username} /> | ||||||
|       ) : ( |       ) : ( | ||||||
|  |  | ||||||
|  | @ -106,6 +106,43 @@ export default function ContractPage(props: { | ||||||
|   return <ContractPageContent {...{ ...props, contract }} /> |   return <ContractPageContent {...{ ...props, contract }} /> | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function ContractPageSidebar(props: { | ||||||
|  |   user: User | null | undefined | ||||||
|  |   contract: Contract | ||||||
|  | }) { | ||||||
|  |   const { contract, user } = props | ||||||
|  |   const { creatorId, isResolved, outcomeType } = contract | ||||||
|  | 
 | ||||||
|  |   const isCreator = user?.id === creatorId | ||||||
|  |   const isBinary = outcomeType === 'BINARY' | ||||||
|  |   const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' | ||||||
|  |   const isNumeric = outcomeType === 'NUMERIC' | ||||||
|  |   const allowTrade = tradingAllowed(contract) | ||||||
|  |   const allowResolve = !isResolved && isCreator && !!user | ||||||
|  |   const hasSidePanel = | ||||||
|  |     (isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve) | ||||||
|  | 
 | ||||||
|  |   return hasSidePanel ? ( | ||||||
|  |     <Col className="gap-4"> | ||||||
|  |       {allowTrade && | ||||||
|  |         (isNumeric ? ( | ||||||
|  |           <NumericBetPanel className="hidden xl:flex" contract={contract} /> | ||||||
|  |         ) : ( | ||||||
|  |           <BetPanel | ||||||
|  |             className="hidden xl:flex" | ||||||
|  |             contract={contract as CPMMBinaryContract} | ||||||
|  |           /> | ||||||
|  |         ))} | ||||||
|  |       {allowResolve && | ||||||
|  |         (isNumeric || isPseudoNumeric ? ( | ||||||
|  |           <NumericResolutionPanel creator={user} contract={contract} /> | ||||||
|  |         ) : ( | ||||||
|  |           <ResolutionPanel creator={user} contract={contract} /> | ||||||
|  |         ))} | ||||||
|  |     </Col> | ||||||
|  |   ) : null | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function ContractPageContent( | export function ContractPageContent( | ||||||
|   props: Parameters<typeof ContractPage>[0] & { contract: Contract } |   props: Parameters<typeof ContractPage>[0] & { contract: Contract } | ||||||
| ) { | ) { | ||||||
|  | @ -142,16 +179,9 @@ export function ContractPageContent( | ||||||
|     setShowConfetti(shouldSeeConfetti) |     setShowConfetti(shouldSeeConfetti) | ||||||
|   }, [contract, user]) |   }, [contract, user]) | ||||||
| 
 | 
 | ||||||
|   const { creatorId, isResolved, question, outcomeType } = contract |   const { isResolved, question, outcomeType } = contract | ||||||
| 
 | 
 | ||||||
|   const isCreator = user?.id === creatorId |  | ||||||
|   const isBinary = outcomeType === 'BINARY' |  | ||||||
|   const isPseudoNumeric = outcomeType === 'PSEUDO_NUMERIC' |  | ||||||
|   const isNumeric = outcomeType === 'NUMERIC' |  | ||||||
|   const allowTrade = tradingAllowed(contract) |   const allowTrade = tradingAllowed(contract) | ||||||
|   const allowResolve = !isResolved && isCreator && !!user |  | ||||||
|   const hasSidePanel = |  | ||||||
|     (isBinary || isNumeric || isPseudoNumeric) && (allowTrade || allowResolve) |  | ||||||
| 
 | 
 | ||||||
|   const ogCardProps = getOpenGraphProps(contract) |   const ogCardProps = getOpenGraphProps(contract) | ||||||
| 
 | 
 | ||||||
|  | @ -160,26 +190,7 @@ export function ContractPageContent( | ||||||
|     contractId: contract.id, |     contractId: contract.id, | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|   const rightSidebar = hasSidePanel ? ( |   const rightSidebar = <ContractPageSidebar user={user} contract={contract} /> | ||||||
|     <Col className="gap-4"> |  | ||||||
|       {allowTrade && |  | ||||||
|         (isNumeric ? ( |  | ||||||
|           <NumericBetPanel className="hidden xl:flex" contract={contract} /> |  | ||||||
|         ) : ( |  | ||||||
|           <BetPanel |  | ||||||
|             className="hidden xl:flex" |  | ||||||
|             contract={contract as CPMMBinaryContract} |  | ||||||
|           /> |  | ||||||
|         ))} |  | ||||||
|       {allowResolve && |  | ||||||
|         (isNumeric || isPseudoNumeric ? ( |  | ||||||
|           <NumericResolutionPanel creator={user} contract={contract} /> |  | ||||||
|         ) : ( |  | ||||||
|           <ResolutionPanel creator={user} contract={contract} /> |  | ||||||
|         ))} |  | ||||||
|     </Col> |  | ||||||
|   ) : null |  | ||||||
| 
 |  | ||||||
|   return ( |   return ( | ||||||
|     <Page rightSidebar={rightSidebar}> |     <Page rightSidebar={rightSidebar}> | ||||||
|       {showConfetti && ( |       {showConfetti && ( | ||||||
|  | @ -216,7 +227,7 @@ export function ContractPageContent( | ||||||
|           bets={bets.filter((b) => !b.challengeSlug)} |           bets={bets.filter((b) => !b.challengeSlug)} | ||||||
|         /> |         /> | ||||||
| 
 | 
 | ||||||
|         {isNumeric && ( |         {outcomeType === 'NUMERIC' && ( | ||||||
|           <AlertBox |           <AlertBox | ||||||
|             title="Warning" |             title="Warning" | ||||||
|             text="Distributional numeric markets were introduced as an experimental feature and are now deprecated." |             text="Distributional numeric markets were introduced as an experimental feature and are now deprecated." | ||||||
|  | @ -232,7 +243,7 @@ export function ContractPageContent( | ||||||
|           </> |           </> | ||||||
|         )} |         )} | ||||||
| 
 | 
 | ||||||
|         {isNumeric && allowTrade && ( |         {outcomeType === 'NUMERIC' && allowTrade && ( | ||||||
|           <NumericBetPanel className="xl:hidden" contract={contract} /> |           <NumericBetPanel className="xl:hidden" contract={contract} /> | ||||||
|         )} |         )} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user