diff --git a/src/components/Clock.jsx b/src/components/Clock.jsx deleted file mode 100644 index 7d0ab14..0000000 --- a/src/components/Clock.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import { formatDate } from 'date-fns' -import { useEffect, useState } from 'preact/hooks' - -export const Clock = ({}) => { - const [time, setTime] = useState(new Date()) - - useEffect(() => { - const timer = setInterval(() => { - setTime(new Date()) - }, 1000) - - return () => { - clearInterval(timer) - } - }, []) - - return <>{formatDate(time, 'HH:mm:ss')}> -} diff --git a/src/components/LiveLeaderboard.tsx b/src/components/LiveLeaderboard.tsx index c536c02..c30dae7 100644 --- a/src/components/LiveLeaderboard.tsx +++ b/src/components/LiveLeaderboard.tsx @@ -3,7 +3,8 @@ import type { Room } from '@/db/model' import { useEffect, useRef, useState } from 'preact/hooks' import { Leaderboard } from './Leaderboard' import { computeScoreboardState } from '@/ggwp' -import { Clock } from './Clock' +import { Clock, Countdown } from './time' +import { parse } from 'date-fns' type Props = { roomId: string @@ -52,6 +53,9 @@ export const LiveLeaderboard = ({ roomId }: Props) => { ) const url = new URL(window.location.href) + + const finishTime = url.searchParams.has('finish') && parse(url.searchParams.get('finish')!, 'HH:mm', new Date()) + const pagesCount = parseInt(url.searchParams.get('pages') ?? '1') const pageInterval = parseInt(url.searchParams.get('interval') ?? '5000') @@ -79,7 +83,12 @@ export const LiveLeaderboard = ({ roomId }: Props) => { return ( <>