import { useState } from "react" import type { QuizPerPlayerResult, QuizQuestionPayload, QuizRevealTruth, RoomSnapshot, } from "@nerdware/shared" import { Button } from "@workspace/ui/components/button" import { useRoomStore } from "@/store/room" import { Countdown } from "@/components/countdown" const inputClass = "border-input bg-background h-10 w-full rounded-md border px-3 py-2 text-sm focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none disabled:opacity-50" export function QuizView({ snapshot }: { snapshot: RoomSnapshot }) { const round = useRoomStore((s) => s.round) const reveal = useRoomStore((s) => s.reveal) const voteProgress = useRoomStore((s) => s.voteProgress) const myChoiceIndex = useRoomStore((s) => s.myChoiceIndex) const hasVoted = useRoomStore((s) => s.hasVoted) const playerId = useRoomStore((s) => s.playerId) const vote = useRoomStore((s) => s.vote) const voteText = useRoomStore((s) => s.voteText) if (!round) { return (
Préparation de la manche…
) } const question = round.payload as QuizQuestionPayload const truth = reveal ? (reveal.truth as QuizRevealTruth) : null const showReveal = truth !== null const isFree = question.format === "free" const myResult = reveal ? (reveal.perPlayerResult as QuizPerPlayerResult)[playerId ?? ""] : undefined function choiceClass(index: number): string { const base = "w-full rounded-lg border px-4 py-3 text-left text-sm transition-colors" if (showReveal) { if (index === truth?.correctIndex) { return `${base} border-green-500 bg-green-500/15 font-medium` } if (index === myChoiceIndex) { return `${base} border-red-500 bg-red-500/10` } return `${base} border-input opacity-60` } if (index === myChoiceIndex) { return `${base} border-primary bg-primary/10 font-medium` } return `${base} border-input hover:bg-muted/60` } return (Réponse envoyée — en attente des autres {voteProgress ? ` (${voteProgress.count}/${voteProgress.total})` : ""}
) : ( voteProgress && ({voteProgress.count}/{voteProgress.total} ont répondu
) ))} {showReveal && (Réponse : {truth?.answer}
)}{myResult?.correct ? "Bonne réponse ! 🎉" : !hasVoted ? "Pas de réponse 😴" : "Raté 💥"}