From 443b742c4a9d5aba0beb986c1aa3f456092782fe Mon Sep 17 00:00:00 2001 From: jahooma Date: Fri, 10 Dec 2021 00:21:12 -0600 Subject: [PATCH] Implement skeleton ContractPage --- web/components/bet-panel.tsx | 55 +++++++++++++++++++++++ web/components/contract-overview.tsx | 67 ++++++++++++++++++++++++---- web/lib/firebase/contracts.ts | 3 ++ web/pages/contract/[contractId].tsx | 25 +++++++---- 4 files changed, 133 insertions(+), 17 deletions(-) create mode 100644 web/components/bet-panel.tsx diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx new file mode 100644 index 00000000..2949ffef --- /dev/null +++ b/web/components/bet-panel.tsx @@ -0,0 +1,55 @@ +import React, { useState } from 'react' +import { Contract } from '../lib/firebase/contracts' +import { Button } from './button' +import { Col } from './layout/col' +import { Spacer } from './layout/spacer' +import { YesNoSelector } from './yes-no-selector' + +export function BetPanel(props: { contract: Contract }) { + const { contract } = props + + const [betChoice, setBetChoice] = useState<'yes' | 'no'>('yes') + const [shares, setShares] = useState(0) + + return ( + + + +
Pick outcome
+ + + + +
Shares
+
+ setShares(parseInt(e.target.value) || 0)} + onFocus={(e) => e.target.select()} + /> +
+ + + +
Price
+
+ {shares * (betChoice === 'yes' ? 57 : 43)} points +
+ + + + {shares !== 0 && ( + + )} + + ) +} diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index fb90749f..543aa98a 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -1,15 +1,64 @@ +import React from 'react' +import { Line } from 'react-chartjs-2' +import { + CategoryScale, + Chart, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, +} from 'chart.js' import { Contract } from '../lib/firebase/contracts' +import { Col } from './layout/col' +import { Row } from './layout/row' +import { Spacer } from './layout/spacer' -export const ContractOverview = (props: { - contract: Contract -}) => { +// Auto import doesn't work for some reason... +// So we manually register ChartJS components instead: +Chart.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend +) +const chartData = { + labels: Array.from({ length: 0 }, (_, i) => i + 1), + datasets: [ + { + label: 'Implied probability', + data: [], + borderColor: 'rgb(75, 192, 192)', + }, + ], +} + +export const ContractOverview = (props: { contract: Contract }) => { const { contract } = props return ( -
-
- {contract.question} -
-
+ +
{contract.question}
+ + +
By {contract.creatorName}
+
+
Dec 9
+
+
200,000 volume
+
+ + + + + + + +
{contract.description}
+ ) -} \ No newline at end of file +} diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 42166817..87d49c04 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -3,7 +3,10 @@ import { db } from './init' export type Contract = { id: string + creatorId: string + creatorName: string question: string + description: string } const contractCollection = collection(db, 'contracts') diff --git a/web/pages/contract/[contractId].tsx b/web/pages/contract/[contractId].tsx index 4b34715a..f2e9c785 100644 --- a/web/pages/contract/[contractId].tsx +++ b/web/pages/contract/[contractId].tsx @@ -1,27 +1,36 @@ +import React from 'react' import { useRouter } from 'next/router' import { useContract } from '../../hooks/use-contract' -import { useUser } from '../../hooks/use-user' +import { Header } from '../../components/header' +import { Row } from '../../components/layout/row' +import { ContractOverview } from '../../components/contract-overview' +import { BetPanel } from '../../components/bet-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
Loading...
+ return
} - if (contract === null) { + if (!contract) { return
Contract not found...
} return ( -
-
{contract.id}
-
{contract.question}
+
+
+ +
+ + + + + +
) }