manifold/web/pages/contract/[contractId].tsx
2021-12-14 00:12:25 -06:00

58 lines
1.6 KiB
TypeScript

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 { ResolvedPanel } from '../../components/resolved-panel'
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 <div />
}
if (!contract) {
return <div>Contract not found...</div>
}
const { creatorId, isResolved } = contract
const isCreator = user?.id === creatorId
return (
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<Header />
<Col className="w-full md:justify-between md:flex-row mt-4">
<ContractOverview
contract={contract}
className="max-w-4xl w-full p-4"
/>
<div className="mt-12 md:mt-0 md:ml-8" />
{isResolved ? (
<ResolvedPanel className="self-start" contract={contract} />
) : isCreator ? (
<ResolutionPanel
className="self-start"
creator={user}
contract={contract}
/>
) : (
<BetPanel className="self-start" contract={contract} />
)}
</Col>
</div>
)
}