From e2a14fa340225c0727e03ac573c20bbcb0979841 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Fri, 22 Nov 2024 17:59:56 +0100 Subject: [PATCH] feat: pages and timed answers --- src/components/ActionRegistry.tsx | 57 +++++++------ src/components/Clock.jsx | 18 ++++ src/components/LiveLeaderboard.tsx | 86 +++++++++++-------- src/components/NewRoom.tsx | 14 ++- src/components/SubmitAction.tsx | 133 ++++++++++++++++++++++++++--- src/pages/api/room/[id]/action.ts | 4 + src/styles.css | 4 +- 7 files changed, 238 insertions(+), 78 deletions(-) create mode 100644 src/components/Clock.jsx diff --git a/src/components/ActionRegistry.tsx b/src/components/ActionRegistry.tsx index c37d82b..3685dc9 100644 --- a/src/components/ActionRegistry.tsx +++ b/src/components/ActionRegistry.tsx @@ -5,8 +5,8 @@ import { format } from 'date-fns' import { type Dispatch, type StateUpdater } from 'preact/hooks' type ActionCardProps = { - moveUp: () => void - moveDown: () => void + // moveUp: () => void + // moveDown: () => void remove: () => void @@ -20,14 +20,17 @@ type Props = { refreshRoom: () => void } -const CardActions = ({ moveUp, moveDown, remove }: ActionCardProps) => ( +const CardActions = ({ + // moveUp, moveDown, + remove, +}: ActionCardProps) => ( <> - + */} {/* - +

+ — {room.id} (pag. {page + 1}/3) +

+ ) } diff --git a/src/components/NewRoom.tsx b/src/components/NewRoom.tsx index 129890e..071f450 100644 --- a/src/components/NewRoom.tsx +++ b/src/components/NewRoom.tsx @@ -53,12 +53,22 @@ export const NewRoom = ({}) => { + + + ) +} + +export const SubmitActionAnswerAtTime = ({ + room, + sendAction, + onTeamQuestionIndex, +}: { + room: RoomData + sendAction: (action: Action) => void + onTeamQuestionIndex?: Receiver<{ team: string; question: string }> +}) => { + const [answer, setAnswer] = useState({ + timestamp: '', + question: '', + team: '', + outcome: 'correct', + }) + + onTeamQuestionIndex?.('SubmitActionAnswerAtTime', ({ team, question }) => { + console.log('onTeamQuestionIndex', team, question) + setAnswer(answer => ({ ...answer, team, question })) + }) + + return ( +
+

Invia Risposta al Tempo

+ +
+ setAnswer({ ...answer, timestamp: e.currentTarget.value })} + /> + + +
+ + + + + + + +
+ +
) } @@ -190,6 +299,8 @@ export const SubmitAction = ({ return ( <> + + ) diff --git a/src/pages/api/room/[id]/action.ts b/src/pages/api/room/[id]/action.ts index acd3126..c96748c 100644 --- a/src/pages/api/room/[id]/action.ts +++ b/src/pages/api/room/[id]/action.ts @@ -28,6 +28,10 @@ export const POST: APIRoute = async ({ params, request, cookies }) => { const action = (await request.json()) as Action room.actions.push(action) + room.actions.sort((a, b) => { + return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime() + }) + updateRoom(roomId, room) return new Response(JSON.stringify('ok'), { diff --git a/src/styles.css b/src/styles.css index 896bc10..75f2885 100644 --- a/src/styles.css +++ b/src/styles.css @@ -44,8 +44,8 @@ body { justify-items: center; align-content: start; - padding: 6rem 1rem 12rem; - gap: 3rem; + padding: 2rem 1rem 12rem; + gap: 2rem; } /* Typography */