fix(web): update QuestionCard to handle null selectedOptionId for timeout case #8
Labels
No labels
debt
feature
feature
infra
multiplayer
multiplayer
security
ux
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: forgejo-lila/lila#8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
QuestionCardcurrently expectscurrentResult: AnswerResult | nullwhereAnswerResult.selectedOptionIdisnumber(non-nullable). This comes fromthe single-player flow where a player always selects an option before submitting.
In multiplayer, a player can time out without answering. The server sends
selectedOptionId: nullinWsGameAnswerResult.resultsfor timed-out players.Currently in
game.$code.tsx, we work around this with?? 0— falling backto option 0 when the player timed out. This incorrectly highlights option 0 as
"wrong" on the score display rather than showing a neutral "timed out" state.
What needs to change
packages/shared/src/schemas/game.tsUpdate
AnswerResultSchemato allowselectedOptionId: number | null:apps/web/src/components/game/QuestionCard.tsxUpdate
QuestionCardProps.currentResultto accept the nullable type.Update
getOptionStateto handleselectedOptionId === null— in thiscase no option should be highlighted as "wrong", only the correct option
should be highlighted green.
apps/api/src/controllers/gameController.tsand relatedVerify the single-player flow still works with the nullable type — single-player
never produces null but the type change should be backwards compatible.
Acceptance criteria
AnswerResult.selectedOptionIdisnumber | nullin shared schemas.QuestionCardrenders correctly whenselectedOptionIdis null —only correct answer highlighted, no "wrong" highlight.
QuestionCardrenders correctly for normal answer — correct/wronghighlights unchanged.
Related
packages/shared/src/schemas/game.tsapps/web/src/components/game/QuestionCard.tsxapps/web/src/routes/multiplayer/game.$code.tsx