This commit is contained in:
Daniel Bulant 2026-05-04 11:06:01 +02:00
parent b01eccb447
commit 14ccaee48c
No known key found for this signature in database
5 changed files with 19 additions and 16 deletions

View file

@ -30,10 +30,10 @@ async function getAlbumReleaseYear({
const correct =
track?.album?.release_date?.getFullYear() ??
new Date().getFullYear() - 1 - index;
const subject = track?.album?.name ?? track?.name ?? "the album";
const subject = track?.album?.name ?? track?.name ?? "unknown album";
return {
type: "numeric",
text: `What number best matches ${subject}?`,
text: `What's the release year of ${subject}?`,
correct,
range: getQuestionRange(correct, 5),
points: 10,

View file

@ -6,15 +6,15 @@ import { db } from "../db";
import { getMemberRecord, getPartyStatus } from "../party-data";
import type { PartySocketEvent, QuizState } from "../party-types";
function userTopic(userId: string) {
export function userTopic(userId: string) {
return `user:${userId}`;
}
function partyTopic(partyId: string) {
export function partyTopic(partyId: string) {
return `party:${partyId}`;
}
const socketPartyId = new WeakMap<object, string>();
export const socketPartyId = new WeakMap<object, string>();
export const pubsub = {
_server: null as ReturnType<typeof Bun.serve> | null,
@ -29,7 +29,7 @@ export const pubsub = {
},
};
async function broadcastQuizState(ws: any, partyId: string) {
export async function broadcastQuizState(ws: any, partyId: string) {
const partyRecord = await db.query.party.findFirst({
where: { id: partyId },
});

View file

@ -6,6 +6,7 @@ import { generatePartyQuestion } from "../party/question-generator";
import type { PartyAnalytics } from "../party/question-utils";
import { updatePartyData } from "../party/state";
import type { Question, QuizResponse, QuizRound, QuizState } from "../party-types";
import { partyAnalysisWorkflow, PartyAnalysisWorkflow } from "./party-analysis";
const TOTAL_QUESTIONS = 5;
@ -34,13 +35,15 @@ export class QuizWorkflow extends ConfiguredInstance {
answers: {},
scores: {},
history: [],
};
};
await partyAnalysisWorkflow.analyzeParty(partyId)
// Initialize quiz state
await QuizWorkflow.updatePartyData(partyId, quizState);
// Get party members to initialize scores
const members = await QuizWorkflow.getPartyMembers(partyId);
let members = await QuizWorkflow.getPartyMembers(partyId);
for (const member of members) {
quizState.scores[member.userId] = 0;
}
@ -63,6 +66,7 @@ export class QuizWorkflow extends ConfiguredInstance {
quizState.history.push(round);
await QuizWorkflow.updatePartyData(partyId, quizState);
members = await QuizWorkflow.getPartyMembers(partyId);
// Wait for all responses with timeout
const memberIds = new Set(members.map((m) => m.userId));
const receivedPlayers = new Set<string>();
@ -72,9 +76,10 @@ export class QuizWorkflow extends ConfiguredInstance {
deadlineEpochMS: question.endTimestamp,
});
if (response === null) {
if (response === null) {
// Timeout - fill in missing players with no answer
const now = Date.now();
if (now < question.endTimestamp) continue;
for (const memberId of memberIds) {
if (!receivedPlayers.has(memberId)) {
receivedPlayers.add(memberId);

View file

@ -22,6 +22,10 @@ Bun.listen({
case "party_status":
const { party: { data: { currentQuestion } } } = data;
console.log(currentQuestion)
let text = currentQuestion?.text
if (text) {
ws?.send(text)
}
break;
}
}

View file

@ -132,12 +132,6 @@ export function Question() {
{question.type === "numeric" ? (
<Item variant="muted">
<ItemContent>
<ItemHeader>
<ItemTitle>Choose a value</ItemTitle>
<ItemDescription>
Closest guesses get more points
</ItemDescription>
</ItemHeader>
<div className="space-y-3">
<Slider
min={numericMin}
@ -148,7 +142,7 @@ export function Question() {
? [currentNumericSelection]
: undefined
}
onValueChange={(value) => setSelectedValue(value[0] ?? null)}
onValueChange={(value) => setSelectedValue(typeof value === "number" ? value : value[0] ?? null)}
/>
<div className="text-sm text-muted-foreground">
Exact value:{" "}