2021-12-10 14:56:17 +00:00
|
|
|
import React from 'react'
|
2021-12-09 21:31:02 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2021-12-16 03:14:00 +00:00
|
|
|
import Head from 'next/head'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
2021-12-09 22:05:55 +00:00
|
|
|
import { useContract } from '../../hooks/use-contract'
|
2021-12-10 14:56:17 +00:00
|
|
|
import { Header } from '../../components/header'
|
|
|
|
import { ContractOverview } from '../../components/contract-overview'
|
|
|
|
import { BetPanel } from '../../components/bet-panel'
|
2021-12-10 18:52:11 +00:00
|
|
|
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-16 03:24:11 +00:00
|
|
|
import { Contract, getContract } from '../../lib/firebase/contracts'
|
2021-12-16 03:42:05 +00:00
|
|
|
|
2021-12-16 03:45:31 +00:00
|
|
|
export async function getServerSideProps({ params }: { params: any }) {
|
2021-12-16 03:24:11 +00:00
|
|
|
console.log('params', params)
|
|
|
|
const contract = await getContract(params.contractId)
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
contract: contract || null,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-12-09 21:31:02 +00:00
|
|
|
|
2021-12-16 03:45:31 +00:00
|
|
|
// export async function getStaticPaths() {
|
|
|
|
// return {
|
|
|
|
// paths: [],
|
|
|
|
// fallback: 'blocking',
|
|
|
|
// }
|
|
|
|
// }
|
2021-12-16 03:14:00 +00:00
|
|
|
|
2021-12-16 03:24:11 +00:00
|
|
|
export default function ContractPage({ contract }: { contract: Contract }) {
|
2021-12-16 04:10:14 +00:00
|
|
|
const user = null // useUser()
|
2021-12-09 22:05:55 +00:00
|
|
|
|
2021-12-16 04:10:14 +00:00
|
|
|
// const router = useRouter()
|
|
|
|
// const { contractId } = router.query as { contractId: string }
|
2021-12-16 03:24:11 +00:00
|
|
|
// const contract = useContract(contractId)
|
|
|
|
// if (contract === 'loading') {
|
|
|
|
// return <div />
|
|
|
|
// }
|
|
|
|
// if (!contract) {
|
2021-12-16 03:14:00 +00:00
|
|
|
// return <div>Contract not found...</div>
|
|
|
|
// }
|
2021-12-16 03:24:11 +00:00
|
|
|
|
|
|
|
if (contract === null) {
|
|
|
|
return <div>Contract not found...</div>
|
|
|
|
}
|
|
|
|
if (!contract) return <div />
|
2021-12-16 03:14:00 +00:00
|
|
|
|
2021-12-14 06:12:25 +00:00
|
|
|
const { creatorId, isResolved } = contract
|
2021-12-16 04:12:27 +00:00
|
|
|
// const isCreator = user?.id === creatorId
|
|
|
|
|
|
|
|
const isCreator = false
|
2021-12-14 00:00:02 +00:00
|
|
|
|
2021-12-09 22:05:55 +00:00
|
|
|
return (
|
2021-12-16 04:10:14 +00:00
|
|
|
<>
|
2021-12-16 03:14:00 +00:00
|
|
|
<Head>
|
|
|
|
<title>{contract.question}</title>
|
|
|
|
|
|
|
|
<meta
|
|
|
|
property="og:title"
|
|
|
|
name="twitter:title"
|
|
|
|
content={contract.question}
|
|
|
|
key="title"
|
|
|
|
/>
|
2021-12-16 03:24:11 +00:00
|
|
|
<meta name="description" content={contract.description} />
|
2021-12-16 03:14:00 +00:00
|
|
|
<meta
|
|
|
|
property="og:description"
|
|
|
|
name="twitter:description"
|
|
|
|
content={contract.description}
|
|
|
|
/>
|
|
|
|
</Head>
|
|
|
|
|
2021-12-16 04:10:14 +00:00
|
|
|
<Col className="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
|
|
|
<Header />
|
|
|
|
|
|
|
|
<Col
|
|
|
|
className={clsx(
|
|
|
|
'w-full items-start md:flex-row mt-4',
|
|
|
|
isResolved ? 'md:justify-center' : 'md:justify-between'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<ContractOverview
|
|
|
|
contract={contract}
|
|
|
|
className="max-w-4xl w-full p-4"
|
|
|
|
/>
|
|
|
|
|
|
|
|
{!isResolved && (
|
|
|
|
<>
|
|
|
|
<div className="mt-12 md:mt-0 md:ml-8" />
|
|
|
|
|
|
|
|
<Col className="w-full sm:w-auto sm:self-center">
|
|
|
|
<BetPanel contract={contract} />
|
|
|
|
|
2021-12-16 04:12:27 +00:00
|
|
|
{isCreator && user && (
|
2021-12-16 04:10:14 +00:00
|
|
|
<ResolutionPanel creator={user} contract={contract} />
|
|
|
|
)}
|
|
|
|
</Col>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Col>
|
2021-12-12 22:14:52 +00:00
|
|
|
</Col>
|
2021-12-16 04:10:14 +00:00
|
|
|
</>
|
2021-12-09 22:05:55 +00:00
|
|
|
)
|
|
|
|
}
|