import React from 'react' import { useRouter } from 'next/router' import { useContract } from '../../hooks/use-contract' import { Header } from '../../components/header' import { ContractOverview } from '../../components/contract-overview' import { BetPanel } from '../../components/bet-panel' import { Col } from '../../components/layout/col' import { useUser } from '../../hooks/use-user' import { ResolutionPanel } from '../../components/resolution-panel' import clsx from 'clsx' import { ContractBetsTable, MyBetsSummary } from '../../components/bets-list' import { useBets } from '../../hooks/use-bets' import { Title } from '../../components/title' import { Spacer } from '../../components/layout/spacer' import { Contract } from '../../lib/firebase/contracts' import { User } from '../../lib/firebase/users' export default function ContractPage() { const user = useUser() const router = useRouter() const { contractId } = router.query as { contractId: string } const contract = useContract(contractId) if (contract === 'loading') { return
} if (!contract) { return
Contract not found...
} const { creatorId, isResolved } = contract const isCreator = user?.id === creatorId return (
{!isResolved && ( <>
{isCreator && ( )} )} ) } function BetsSection(props: { contract: Contract; user: User | null }) { const { contract, user } = props const bets = useBets(contract.id) if (bets === 'loading' || bets.length === 0) return <> // Decending creation time. bets.sort((bet1, bet2) => bet2.createdTime - bet1.createdTime) const userBets = user && bets.filter((bet) => bet.userId === user.id) return (
{userBets && userBets.length > 0 && ( <> <MyBetsSummary className="ml-1" contract={contract} bets={userBets} /> <Spacer h={6} /> <ContractBetsTable contract={contract} bets={userBets} /> <Spacer h={6} /> </> )} <Title text="All bets" /> <ContractBetsTable contract={contract} bets={bets} /> </div> ) }