Desk: one verified count, rotation-safe row fold, fixtures for guest and settled
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m35s

The navigator's 'Desk · N open' counted cards the desk withdraws on an
options_hash mismatch. buildDesk now owns the count (open_count less the
withdrawn open cards) and the navigator reads it through the same
useUnverified check the page uses; before the check lands it shows no count.
A row's fold is derived from the screen size and a tap, so rotation cannot
leave it stale. Adds guest and settled-while-answered fixtures and tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-13 23:29:06 +00:00
commit b8741f9dcc
8 changed files with 144 additions and 37 deletions

View file

@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { Box, Icon, IconButton, Icons, Scroll, Text } from 'folds';
import { PhoneHit } from '../../styles/PhoneHit.css';
@ -6,7 +6,7 @@ import { Page, PageContent, PageContentCenter, PageHeader } from '../../componen
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
import { getHomePath } from '../../pages/pathUtils';
import { DeskView } from './DeskView';
import { unverifiedForks } from './optionsHash';
import { useUnverified } from './useUnverified';
import { deskFor } from './source';
const labelOf = (mind: string) => mind.charAt(0).toUpperCase() + mind.slice(1);
@ -19,14 +19,7 @@ export function Desk() {
const label = labelOf(mind);
const list = useMemo(() => deskFor(mind), [mind]);
// Until the recompute finishes nothing is flagged; a card that fails is withdrawn when it lands.
const [unverified, setUnverified] = useState<ReadonlySet<string>>(new Set());
useEffect(() => {
let live = true;
unverifiedForks(list?.forks ?? []).then((bad) => live && setUnverified(bad));
return () => {
live = false;
};
}, [list]);
const unverified = useUnverified(list);
return (
<Page>

View file

@ -3,11 +3,11 @@ import { Box, Icon, Icons, Text } from 'folds';
import { NavGutter, NavItem, NavItemContent, NavLink } from '../../components/nav';
import { NAV_ROOM_ICON_REST_OPACITY, NavLabel } from '../../components/nav/styles.css';
import { getDeskPath } from '../../pages/pathUtils';
import { buildDesk } from './buildDesk';
import { deskFor } from './source';
import { useUnverified } from './useUnverified';
/** A Mind's desk, pinned at the top of its navigator group: always there, with the open count when there is one. */
export function DeskEntry({ mind }: { mind: string }) {
const open = deskFor(mind)?.open_count ?? 0;
export function DeskLink({ mind, open }: { mind: string; open: number }) {
return (
<NavItem variant="Background" radii="400">
<NavLink to={getDeskPath(mind)}>
@ -29,3 +29,11 @@ export function DeskEntry({ mind }: { mind: string }) {
</NavItem>
);
}
/** A Mind's desk, pinned at the top of its navigator group: always there, with the open count when there is one. */
export function DeskEntry({ mind }: { mind: string }) {
const list = deskFor(mind);
const unverified = useUnverified(list);
// The same count the desk page shows; until the hash check lands there is no count to show.
return <DeskLink mind={mind} open={unverified ? buildDesk(list, unverified).counts.open : 0} />;
}

View file

@ -5,8 +5,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { ScreenSize, ScreenSizeProvider } from '../../hooks/useScreenSize';
import { SkyInkContextProvider } from '../../hooks/useTheme';
import { SCRIM_GROUND, SCRIM_INK } from '../scene/skyInk';
import { DeskEntry } from './DeskEntry';
import { DeskView, SIGN_IN_NOTE } from './DeskView';
import { DeskEntry, DeskLink } from './DeskEntry';
import { DeskView, SIGN_IN_NOTE, rowOpen } from './DeskView';
import { ForkList } from './forkContract';
import { STATES } from './fixtures';
import { setDeskSource } from './source';
@ -119,8 +119,8 @@ describe('DeskView', () => {
const html = view('noAnswers', ScreenSize.Desktop, 'void', new Set(['c:question:plain']));
expect(html).toContain('does not match the hash it was published with');
expect(html).not.toContain('First way');
expect(html).toContain('1 open.');
expect(html).not.toContain('Nothing is waiting');
expect(html).toContain('Nothing is waiting on you from Void.');
expect(html).not.toContain('1 open.');
});
it('never claims an empty desk while the list says forks are open, whatever rows it could show', () => {
setDeskSource(() => undefined);
@ -132,6 +132,29 @@ describe('DeskView', () => {
expect(html).toContain('3 open.');
expect(html).not.toContain('Nothing is waiting');
});
it('says every row is read-only for a signed-out viewer, in every state the fixtures hold', () => {
(['noAnswers', 'blocked', 'answered', 'settled'] as const).forEach((state) => {
const html = view(state, ScreenSize.Desktop);
const rows = html.match(/<textarea/g)?.length ?? 0;
expect(rows).toBeGreaterThan(0);
expect(html.match(/<textarea[^>]* disabled=""/g)).toHaveLength(rows);
expect(html.split(SIGN_IN_NOTE)).toHaveLength(rows + 1);
});
});
it('shows a guest answer with its text and never an answerer id', () => {
const html = view('guest', ScreenSize.Desktop);
expect(html).toContain('Answer Second way &quot;From outside the circle.&quot;');
expect(html).toContain('1 decider · 2 answerers');
expect(html).not.toContain('guest-1');
expect(html).not.toContain('acct-1');
});
it('lists a question settled while it had answers as a ruling only, with neither row nor answers nor open count', () => {
const html = view('settledWhileAnswered', ScreenSize.Desktop);
expect(html).toContain('Question late (ruling:late-1)');
expect(html).not.toContain('Context for late');
expect(html).not.toContain('Arrived after');
expect(html).toContain('Nothing is waiting on you from Void.');
});
it('shows no booth for a Mind without art rather than another face', () => {
expect(view('noAnswers', ScreenSize.Desktop, 'nobody')).not.toContain('data-pose');
});
@ -232,30 +255,50 @@ describe('counts when the ids are withheld', () => {
describe('DeskEntry', () => {
afterEach(() => setDeskSource(() => undefined));
const bare = (html: string) => html.replace(/<[^>]*>/g, '');
const entry = (mind: string) =>
renderToStaticMarkup(
<MemoryRouter>
<DeskEntry mind={mind} />
</MemoryRouter>
);
const link = (open: number) =>
renderToStaticMarkup(
<MemoryRouter>
<DeskLink mind="void" open={open} />
</MemoryRouter>
);
it('reads "Desk · N open" and links to that Mind\'s desk', () => {
setDeskSource(() => STATES.blocked);
const html = entry('void');
const html = link(2);
expect(html).toContain('Desk · 2 open');
expect(html).toContain('href="/desk/void"');
});
it('reads the count the list states, not a count of the forks it carries', () => {
setDeskSource(() => ({ ...STATES.empty, open_count: 5 }));
expect(entry('void')).toContain('Desk · 5 open');
it('is pinned even at zero open', () => {
expect(bare(link(0))).toBe('Desk');
expect(link(0)).toContain('href="/desk/void"');
});
it('is pinned even at zero open, when nothing is published, and when only settled forks exist', () => {
const bare = (html: string) => html.replace(/<[^>]*>/g, '');
const states = [STATES.empty, undefined, { ...STATES.settled, open_count: 0 }];
states.forEach((state) => {
it('is pinned when nothing is published, and when only settled forks exist', () => {
[undefined, { ...STATES.settled, open_count: 0 }].forEach((state) => {
setDeskSource(() => state);
const html = entry('void');
expect(bare(html)).toBe('Desk');
expect(html).toContain('href="/desk/void"');
expect(bare(entry('void'))).toBe('Desk');
expect(entry('void')).toContain('href="/desk/void"');
});
});
it('shows no count before the hash check has landed, so a card about to be withdrawn is never counted', () => {
setDeskSource(() => STATES.blocked);
expect(bare(entry('void'))).toBe('Desk');
});
});
describe('a row on a rotating screen', () => {
it('is open on a wide screen whatever was tapped, and folded on a phone until tapped', () => {
expect(rowOpen(false, false)).toBe(true);
expect(rowOpen(false, true)).toBe(true);
expect(rowOpen(true, false)).toBe(false);
expect(rowOpen(true, true)).toBe(true);
});
it('reads the screen it is on now, not the one it mounted on: wide to phone folds, phone to wide opens', () => {
const untapped = [false, true, false, true].map((phone) => rowOpen(phone, false));
expect(untapped).toEqual([true, false, true, false]);
});
});

View file

@ -50,10 +50,13 @@ function Answers({ answers }: { answers: AnswerRow[] }) {
);
}
/** Phones list titles and a tap opens one; wide screens show every row open. Derived, so rotating never leaves it stale. */
export const rowOpen = (phone: boolean, tapped: boolean) => !phone || tapped;
function Row({ row, now }: { row: DeskRow; now: number }) {
const phone = useScreenSizeContext() === ScreenSize.Mobile;
// Phones list titles; a tap opens one. Wide screens show every row open.
const [open, setOpen] = useState(!phone);
const [tapped, setTapped] = useState(false);
const open = rowOpen(phone, tapped);
if (row.kind === 'unverified') {
return (
<li className={css.Row}>
@ -72,7 +75,7 @@ function Row({ row, now }: { row: DeskRow; now: number }) {
type="button"
className={css.Fold}
aria-expanded={open}
onClick={() => setOpen(!open)}
onClick={() => setTapped(!tapped)}
>
{row.title}
</button>

View file

@ -52,9 +52,20 @@ describe('buildDesk', () => {
const odd = list([entry('a', { order: 2 }), entry('b', { order: 9 })]);
expect(buildDesk(odd).open.map((r) => r.forkId)).toEqual(['c:question:a', 'c:question:b']);
});
it("takes the open count from the list's open_count, not from the rows it could verify or carries", () => {
const d = buildDesk({ ...list([entry('only')]), open_count: 4 }, new Set(['c:question:only']));
expect(d.counts.open).toBe(4);
it("takes the open count from the list's open_count, so rows it could not carry still count", () => {
expect(buildDesk({ ...list([entry('only')]), open_count: 4 }).counts.open).toBe(4);
});
it('does not count an open card it withdraws as unverified: one filter owns the shown rows and the count', () => {
const l = list([entry('a'), entry('b')]);
const d = buildDesk(l, new Set(['c:question:a']));
expect(d.counts.open).toBe(1);
expect(d.open.filter((r) => r.kind === 'question')).toHaveLength(1);
expect(buildDesk(l, new Set(l.forks.map((f) => f.card.fork_id))).counts.open).toBe(0);
});
it('does not count a withdrawn id that names a closed card, and never goes below zero', () => {
const l = list([entry('a'), entry('shut', { status: 'closed', ruling: 'r:1' })]);
expect(buildDesk(l, new Set(['c:question:shut'])).counts.open).toBe(1);
expect(buildDesk({ ...l, open_count: 0 }, new Set(['c:question:a'])).counts.open).toBe(0);
});
it('marks the answer the record names as counted, and no other', () => {
const [row] = questions(buildDesk(STATES.answered));

View file

@ -44,7 +44,7 @@ export type Desk = {
open: DeskRow[];
/** Closed with a ruling id. A card closed with no ruling (withdrawn) is not listed. */
recorded: { forkId: string; title: string; rulingId: string }[];
/** The list's own open_count: the one count the navigator, the status line and the booth share. */
/** The list's open_count less the open cards withdrawn as unverified: the one count the navigator, the status line and the booth share. */
counts: { open: number };
};
@ -72,6 +72,7 @@ export const buildDesk = (
if (!list) return { published: false, open: [], recorded: [], counts: { open: 0 } };
const open: DeskRow[] = [];
const recorded: Desk['recorded'] = [];
let withdrawn = 0;
list.forks.forEach((entry) => {
const { card, record } = entry;
if (card.status === 'closed') {
@ -81,6 +82,7 @@ export const buildDesk = (
}
if (unverified.has(card.fork_id)) {
open.push({ kind: 'unverified', forkId: card.fork_id });
withdrawn += 1;
return;
}
open.push({
@ -101,6 +103,6 @@ export const buildDesk = (
published: true,
open,
recorded,
counts: { open: list.open_count },
counts: { open: Math.max(0, list.open_count - withdrawn) },
};
};

View file

@ -116,4 +116,30 @@ export const STATES = {
'n1'
),
]),
/** Answers from a Guest (weight 0, served all the same) beside a Member's; ids are never shown. */
guest: list([
entry(
'open',
{},
[
answer('open', 1, { choice: 'A', answerer: 'acct-1', authority: 'Member' }),
answer('open', 2, {
choice: 'B',
note: 'From outside the circle.',
answerer: 'guest-1',
authority: 'Guest',
}),
],
'n1'
),
]),
/** Closed with a ruling while answers were still arriving: the card settled, the answers stay on its record. */
settledWhileAnswered: list([
entry(
'late',
{ status: 'closed', ruling: 'ruling:late-1', ruled_from: ['n1'] },
[answer('late', 1), answer('late', 2, { note: 'Arrived after.', answerer: 'acct-2' })],
'n1'
),
]),
} satisfies Record<string, ForkList>;

View file

@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';
import { ForkList } from './forkContract';
import { unverifiedForks } from './optionsHash';
/**
* The fork ids of `list` whose options_hash fails the recompute: the one verified filter, shared by the desk page
* and the navigator's count. Undefined until the check has landed, so no caller reads a count that a card is
* about to be withdrawn from.
*/
export const useUnverified = (list: ForkList | undefined): ReadonlySet<string> | undefined => {
const [bad, setBad] = useState<ReadonlySet<string>>();
useEffect(() => {
let live = true;
setBad(undefined);
unverifiedForks(list?.forks ?? []).then((found) => live && setBad(found));
return () => {
live = false;
};
}, [list]);
return bad;
};