manifold/web/pages/contract/[contractId].tsx

54 lines
1.5 KiB
TypeScript
Raw Normal View History

import React from 'react'
2021-12-09 21:31:02 +00:00
import { useRouter } from 'next/router'
2021-12-09 22:05:55 +00:00
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'
2021-12-14 00:00:02 +00:00
import { useUser } from '../../hooks/use-user'
import { ResolutionPanel } from '../../components/resolution-panel'
2021-12-14 06:12:25 +00:00
import { ResolvedPanel } from '../../components/resolved-panel'
2021-12-09 21:31:02 +00:00
export default function ContractPage() {
2021-12-14 00:00:02 +00:00
const user = useUser()
2021-12-09 22:05:55 +00:00
const router = useRouter()
const { contractId } = router.query as { contractId: string }
const contract = useContract(contractId)
if (contract === 'loading') {
return <div />
2021-12-09 22:05:55 +00:00
}
if (!contract) {
2021-12-09 22:05:55 +00:00
return <div>Contract not found...</div>
}
2021-12-14 06:12:25 +00:00
const { creatorId, isResolved } = contract
const isCreator = user?.id === creatorId
2021-12-14 00:00:02 +00:00
2021-12-09 22:05:55 +00:00
return (
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<Header />
<Col className="w-full items-start md:justify-between md:flex-row mt-4">
2021-12-14 06:12:25 +00:00
<ContractOverview
contract={contract}
className="max-w-4xl w-full p-4"
/>
2021-12-14 04:54:51 +00:00
<div className="mt-12 md:mt-0 md:ml-8" />
2021-12-14 06:12:25 +00:00
{isResolved ? (
<ResolvedPanel contract={contract} />
2021-12-14 06:12:25 +00:00
) : isCreator ? (
<ResolutionPanel creator={user} contract={contract} />
2021-12-14 00:00:02 +00:00
) : (
<BetPanel contract={contract} />
2021-12-14 00:00:02 +00:00
)}
2021-12-12 22:14:52 +00:00
</Col>
2021-12-09 22:05:55 +00:00
</div>
)
}