From 9e02536e02b0783ec2854a6635f5ce09bbf6e647 Mon Sep 17 00:00:00 2001 From: Void Date: Wed, 11 Nov 2026 18:23:14 +0000 Subject: [PATCH] Desk: card contract at CultLib 3a51bbab: decider_count, answerer_count, nullable answerer; the counts show when the ids are withheld Co-Authored-By: Claude Sonnet 5.5 --- src/app/features/desk/DeskView.test.tsx | 28 +++++++++++++++++++++++++ src/app/features/desk/DeskView.tsx | 5 +++++ src/app/features/desk/buildDesk.ts | 5 +++++ src/app/features/desk/fixtures.ts | 2 ++ src/app/features/desk/forkContract.ts | 11 +++++++++- src/preview-demo/deskForks.test.ts | 10 ++++++++- src/preview-demo/deskForks.ts | 2 ++ 7 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/app/features/desk/DeskView.test.tsx b/src/app/features/desk/DeskView.test.tsx index 19be8aff..c93c5916 100644 --- a/src/app/features/desk/DeskView.test.tsx +++ b/src/app/features/desk/DeskView.test.tsx @@ -151,6 +151,34 @@ describe("a question's age", () => { }); }); +describe('counts when the ids are withheld', () => { + const withheld = (): ForkList => { + const entry = STATES.noAnswers.forks[0]; + return { + ...STATES.noAnswers, + forks: [ + { + ...entry, + card: { ...entry.card, deciders: [], decider_count: 3 }, + record: { ...entry.record, answerer_count: 2 }, + }, + ], + }; + }; + it('shows how many deciders and answerers there are, naming none', () => { + const html = renderToStaticMarkup( + + + + ); + expect(html).toContain('3 deciders · 2 answerers'); + }); + it('says the singular for one', () => { + const html = view('noAnswers', ScreenSize.Desktop); + expect(html).toContain('1 decider · 0 answerers'); + }); +}); + describe('DeskEntry', () => { afterEach(() => setDeskSource(() => undefined)); const entry = (mind: string) => diff --git a/src/app/features/desk/DeskView.tsx b/src/app/features/desk/DeskView.tsx index ceb42fd9..2c73890d 100644 --- a/src/app/features/desk/DeskView.tsx +++ b/src/app/features/desk/DeskView.tsx @@ -12,6 +12,8 @@ import * as css from './DeskView.css'; /** Slice 1 has no session: every viewer is signed out, and the note says why it cannot be used. */ export const SIGN_IN_NOTE = 'Answering opens with sign-in. Until then you can read the questions.'; +const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`; + const date = (iso: string) => iso.slice(0, 10); const OUTCOME: Record = { @@ -81,6 +83,9 @@ function Row({ row, now }: { row: DeskRow; now: number }) { {raisedAge(row.raisedAt, now) && (

{raisedAge(row.raisedAt, now)}

)} +

+ {`${plural(row.deciderCount, 'decider')} · ${plural(row.answererCount, 'answerer')}`} +

{row.context}

    {row.options.map((o) => ( diff --git a/src/app/features/desk/buildDesk.ts b/src/app/features/desk/buildDesk.ts index 4d65a437..0b18794c 100644 --- a/src/app/features/desk/buildDesk.ts +++ b/src/app/features/desk/buildDesk.ts @@ -30,6 +30,9 @@ export type DeskRow = depends: string[]; /** When the question was first admitted, as served; absent when the card carries none. */ raisedAt?: string; + /** Counts as served: the same in the decider and the withheld view, so they show either way. */ + deciderCount: number; + answererCount: number; /** In admission order, as served. */ answers: AnswerRow[]; }; @@ -86,6 +89,8 @@ export const buildDesk = ( recommended: card.options.find((o) => o.id === card.recommendation)?.text, depends: card.depends, raisedAt: card.raised_at ?? undefined, + deciderCount: card.decider_count, + answererCount: record.answerer_count, answers: record.answers.map((a) => answerRow(a, entry)), }); }); diff --git a/src/app/features/desk/fixtures.ts b/src/app/features/desk/fixtures.ts index d9b055ca..8f999f43 100644 --- a/src/app/features/desk/fixtures.ts +++ b/src/app/features/desk/fixtures.ts @@ -18,6 +18,7 @@ export const card = (label: string, over: Partial = {}): ForkCard => ( raised_in: null, raised_at: null, deciders: ['d1'], + decider_count: 1, status: 'open', ruling: null, ruled_from: [], @@ -61,6 +62,7 @@ export const entry = ( fork_id: c.fork_id, options_hash: c.options_hash, counted_answer_id: counted, + answerer_count: new Set(answers.map((a) => a.answerer)).size, answers, }, }; diff --git a/src/app/features/desk/forkContract.ts b/src/app/features/desk/forkContract.ts index 91b3653f..5bf10080 100644 --- a/src/app/features/desk/forkContract.ts +++ b/src/app/features/desk/forkContract.ts @@ -30,7 +30,13 @@ export type ForkCard = { * the client's: now minus `raised_at`. */ raised_at: string | null; + /** + * Who may answer. Empty when this reader is not a decider (the ids are withheld); otherwise it holds exactly + * `decider_count` ids. + */ deciders: string[]; + /** How many deciders there are, 1..64: the same number in both reader views. */ + decider_count: number; status: 'open' | 'closed'; /** The ruling id when a ruling closed the fork; nil when open, and nil on a closed card withdrawn with no ruling. */ ruling: string | null; @@ -64,7 +70,8 @@ export type DeskAnswer = { answered_at: string; received_at: string; claim_in_future: boolean; - answerer: string; + /** Who answered; nil when this reader is not a decider (withheld). */ + answerer: string | null; authority: string; request_id: string; }; @@ -75,6 +82,8 @@ export type ForkRecord = { options_hash: string; /** Derived by the receiver; the page renders it and never recomputes it. */ counted_answer_id: string | null; + /** Distinct answerers over every stored answer, refusals included, at least 0: the same number in both views. */ + answerer_count: number; /** In admission order. */ answers: DeskAnswer[]; }; diff --git a/src/preview-demo/deskForks.test.ts b/src/preview-demo/deskForks.test.ts index 56fd2573..001342f5 100644 --- a/src/preview-demo/deskForks.test.ts +++ b/src/preview-demo/deskForks.test.ts @@ -20,13 +20,21 @@ const KEYS = { 'raised_in', 'raised_at', 'deciders', + 'decider_count', 'status', 'ruling', 'ruled_from', 'order', 'options_hash', ], - record: ['schemaVersion', 'fork_id', 'options_hash', 'counted_answer_id', 'answers'], + record: [ + 'schemaVersion', + 'fork_id', + 'options_hash', + 'counted_answer_id', + 'answerer_count', + 'answers', + ], answer: [ 'schemaVersion', 'answer_id', diff --git a/src/preview-demo/deskForks.ts b/src/preview-demo/deskForks.ts index fe1bbfcb..91543cab 100644 --- a/src/preview-demo/deskForks.ts +++ b/src/preview-demo/deskForks.ts @@ -27,6 +27,7 @@ const card = (label: string, order: number, over: Partial): ForkCard = raised_in: null, raised_at: null, deciders: ['demo-decider'], + decider_count: 1, status: 'open', ruling: null, ruled_from: [], @@ -75,6 +76,7 @@ const entry = ( fork_id: c.fork_id, options_hash: c.options_hash, counted_answer_id: counted, + answerer_count: new Set(answers.map((a) => a.answerer)).size, answers, }, });