Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions apps/frontend/src/screens/LiveQuiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) {


const [selectedAnswer, setSelectedAnswer] = useState<string | null>(null);
const [questionStartTime, setQuestionStartTime] = useState<number>(0);
const [qIndex, setQIndex] = useState(0);


Expand Down Expand Up @@ -164,7 +163,6 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) {
setSelectedAnswer(null);
setCorrectAnswers([]);
setGameState(GameState.QUESTION);
setQuestionStartTime(Date.now());

break;
// Sent only to a reconnecting client, to put them back on the
Expand All @@ -179,9 +177,6 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) {
setSelectedAnswer(
payload.alreadyAnswered ? (payload.selectedAnswerId ?? '__answered__') : null
);
// Scoring uses Date.now() - questionStartTime, so anchor it to
// the real remaining time rather than the moment they rejoined.
setQuestionStartTime(Date.now() - (payload.question.timeLimit - payload.timeLeft) * 1000);
setGameState(payload.expired ? GameState.RESULTS : GameState.QUESTION);
break;
case 'quiz:timer-tick':
Expand Down Expand Up @@ -262,16 +257,14 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) {
if (selectedAnswer || gameState !== GameState.QUESTION) return;

setSelectedAnswer(answerId);
const timeMs = Date.now() - questionStartTime;

ws?.send(JSON.stringify({
type: 'quiz:submit-answer',
payload: {
sessionId,
participantId,
questionId: currentQuestion.id,
answerId,
timeMs
answerId
}
}))
}
Expand Down