diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 30b9c747..20933e73 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -39,7 +39,7 @@ export const ContractOverview = (props: { - + {probPercent}
chance
diff --git a/web/components/contract-prob-graph.tsx b/web/components/contract-prob-graph.tsx index be59d55a..1f000142 100644 --- a/web/components/contract-prob-graph.tsx +++ b/web/components/contract-prob-graph.tsx @@ -2,6 +2,7 @@ import { DatumValue } from '@nivo/core' import { ResponsiveLine } from '@nivo/line' import dayjs from 'dayjs' import { useBets } from '../hooks/use-bets' +import { useWindowSize } from '../hooks/use-window-size' import { Contract } from '../lib/firebase/contracts' export function ContractProbGraph(props: { contract: Contract }) { @@ -28,6 +29,8 @@ export function ContractProbGraph(props: { contract: Contract }) { const tickValues = [0, 25, 50, 75, 100] + const { width } = useWindowSize() + return (
formatTime(+d.valueOf(), lessThanAWeek)} axisBottom={{ + tickValues: !width || width < 800 ? 4 : 8, format: (time) => formatTime(+time, lessThanAWeek), }} colors={{ datum: 'color' }} @@ -49,8 +53,9 @@ export function ContractProbGraph(props: { contract: Contract }) { pointBorderWidth={1} pointBorderColor="#fff" enableSlices="x" + enableGridX={!!width && width >= 800} enableArea - margin={{ top: 20, right: 22, bottom: 22, left: 40 }} + margin={{ top: 20, right: 28, bottom: 22, left: 40 }} />
) diff --git a/web/hooks/use-window-size.ts b/web/hooks/use-window-size.ts new file mode 100644 index 00000000..94b3d6ae --- /dev/null +++ b/web/hooks/use-window-size.ts @@ -0,0 +1,20 @@ +import { useEffect, useState } from 'react' + +export const useWindowSize = () => { + const [size, setSize] = useState( + typeof window === 'undefined' + ? { width: undefined, height: undefined } + : { width: window.innerWidth, height: window.innerHeight } + ) + + useEffect(() => { + const onResize = () => { + setSize({ width: window.innerWidth, height: window.innerHeight }) + } + + window.addEventListener('resize', onResize) + return () => window.removeEventListener('resize', onResize) + }, []) + + return size +} diff --git a/web/pages/contract/[contractId].tsx b/web/pages/contract/[contractId].tsx index 248cf6b5..0bf354e4 100644 --- a/web/pages/contract/[contractId].tsx +++ b/web/pages/contract/[contractId].tsx @@ -32,7 +32,7 @@ export default function ContractPage() {
- + {isResolved ? ( - + ) : isCreator ? ( - + ) : ( - + )}