import { sendJSON } from '@/client/utils' import type { Room, RoomData } from '@/db/model' import { type Action, type ActionAnswer, type ActionJolly } from '@/ggwp' import { formatDate, parse } from 'date-fns' import { useState } from 'preact/hooks' import { Clock } from './time' type Outcome = 'correct' | 'partial' | 'wrong' export const SubmitActionAnswer = ({ room, sendAction, onTeamQuestionIndex, }: { room: RoomData sendAction: (action: Action) => void onTeamQuestionIndex?: Receiver<{ team: string; question: string }> }) => { const [answer, setAnswer] = useState>({ question: '', team: '', outcome: 'correct', }) onTeamQuestionIndex?.('SubmitActionAnswer', ({ team, question }) => { console.log('onTeamQuestionIndex', team, question) setAnswer(answer => ({ ...answer, team, question })) }) return (

Invia Risposta Immediata ()

) } export const SubmitActionAnswerAtTime = ({ room, sendAction, onTeamQuestionIndex, }: { room: RoomData sendAction: (action: Action) => void onTeamQuestionIndex?: Receiver<{ team: string; question: string }> }) => { type ActionTimeAnswer = Omit & { timestampRaw: string } const [answer, setAnswer] = useState({ timestampRaw: '', 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, timestampRaw: e.currentTarget.value })} />
) } type Receiver = (key: string, cb: (data: T) => void) => void export const SubmitActionJolly = ({ room, sendAction, onTeamQuestionIndex, }: { room: RoomData sendAction: (action: Action) => void onTeamQuestionIndex?: Receiver<{ team: string; question: string }> }) => { const groupsMap: Record = {} room.questions.forEach(question => { groupsMap[question.group] = true }) const groups = Object.keys(groupsMap) const questionToGroup: Record = {} room.questions.forEach(question => { questionToGroup[question.id] = question.group }) const [answer, setAnswer] = useState>({ team: '', group: '', }) onTeamQuestionIndex?.('SubmitActionJolly', ({ team, question }) => { console.log('onTeamQuestionIndex', team, question) setAnswer(answer => ({ ...answer, team, group: questionToGroup[question] })) }) return (

Invia Jolly

) } export const SubmitAction = ({ room, refreshRoom, onTeamQuestionIndex, }: { room: Room refreshRoom: () => void onTeamQuestionIndex?: Receiver<{ team: string; question: string }> }) => { const sendAction = async (action: Action) => { await sendJSON(`/api/room/${room.id}/action`, action) refreshRoom() } if (!room) { return
Loading...
} return ( <> ) }