desk: read-only Mind desk slice 1 (typed projections, buildDesk, deskMood, DeskView, navigator entry, demo forks)
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
66c4c6373b
commit
4fef4face7
20 changed files with 1166 additions and 2 deletions
45
src/app/features/desk/Desk.tsx
Normal file
45
src/app/features/desk/Desk.tsx
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import React from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { Box, Icon, IconButton, Icons, Scroll, Text } from 'folds';
|
||||
import { Page, PageContent, PageContentCenter, PageHeader } from '../../components/page';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
import { getHomePath } from '../../pages/pathUtils';
|
||||
import { DeskView } from './DeskView';
|
||||
import { deskFor } from './source';
|
||||
|
||||
const labelOf = (mind: string) => mind.charAt(0).toUpperCase() + mind.slice(1);
|
||||
|
||||
/** The route's page: one Mind's desk under the navigator. */
|
||||
export function Desk() {
|
||||
const { mind = '' } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const phone = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
const label = labelOf(mind);
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader balance>
|
||||
<Box grow="Yes" alignItems="Center" gap="200">
|
||||
<Box grow="Yes" basis="No">
|
||||
{phone && (
|
||||
<IconButton aria-label="Back to rooms" onClick={() => navigate(getHomePath())}>
|
||||
<Icon src={Icons.ArrowLeft} />
|
||||
</IconButton>
|
||||
)}
|
||||
</Box>
|
||||
<Text size="H3" truncate>{`${label}'s desk`}</Text>
|
||||
<Box grow="Yes" basis="No" />
|
||||
</Box>
|
||||
</PageHeader>
|
||||
<Box style={{ position: 'relative' }} grow="Yes">
|
||||
<Scroll hideTrack visibility="Hover">
|
||||
<PageContent>
|
||||
<PageContentCenter>
|
||||
<DeskView mind={mind} label={label} projection={deskFor(mind)} now={Date.now()} />
|
||||
</PageContentCenter>
|
||||
</PageContent>
|
||||
</Scroll>
|
||||
</Box>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
17
src/app/features/desk/DeskEntry.tsx
Normal file
17
src/app/features/desk/DeskEntry.tsx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Text } from 'folds';
|
||||
import { getDeskPath } from '../../pages/pathUtils';
|
||||
import { countOpen } from './buildDesk';
|
||||
import { deskFor } from './source';
|
||||
|
||||
/** The way into a Mind's desk, set in its navigator group header; nothing at all when nothing is open. */
|
||||
export function DeskEntry({ mind }: { mind: string }) {
|
||||
const open = countOpen(deskFor(mind));
|
||||
if (open === 0) return null;
|
||||
return (
|
||||
<Text as={Link} to={getDeskPath(mind)} size="T200" priority="300">
|
||||
{`Desk · ${open} open`}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
99
src/app/features/desk/DeskView.css.ts
Normal file
99
src/app/features/desk/DeskView.css.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { globalStyle, style } from '@vanilla-extract/css';
|
||||
import { color, config, toRem } from 'folds';
|
||||
import { MOBILE_BREAKPOINT } from '../../hooks/useScreenSize';
|
||||
|
||||
const PHONE = `screen and (max-width: ${MOBILE_BREAKPOINT}px)`;
|
||||
|
||||
/** Rows and booth side by side on wide screens. */
|
||||
export const Layout = style({
|
||||
display: 'flex',
|
||||
gap: config.space.S500,
|
||||
alignItems: 'flex-start',
|
||||
'@media': { [PHONE]: { display: 'block', paddingBottom: toRem(120) } },
|
||||
});
|
||||
|
||||
export const Rows = style({ flex: 1, minWidth: 0, margin: 0, padding: 0, listStyle: 'none' });
|
||||
|
||||
/** A hairline splits rows; it is the only chrome. */
|
||||
export const Row = style({
|
||||
padding: `${config.space.S300} 0`,
|
||||
borderTop: `1px solid ${color.Background.ContainerLine}`,
|
||||
});
|
||||
|
||||
export const Title = style({
|
||||
margin: 0,
|
||||
font: 'inherit',
|
||||
fontWeight: 600,
|
||||
});
|
||||
|
||||
/** The fold button reads as the title itself, not as a control. */
|
||||
export const Fold = style({
|
||||
all: 'unset',
|
||||
cursor: 'pointer',
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
minHeight: 44,
|
||||
boxSizing: 'border-box',
|
||||
});
|
||||
|
||||
export const Quiet = style({ opacity: config.opacity.P300, margin: `${config.space.S100} 0` });
|
||||
export const Body = style({ whiteSpace: 'pre-wrap', margin: `${config.space.S200} 0` });
|
||||
export const Options = style({ margin: 0, padding: 0, listStyle: 'none' });
|
||||
export const Option = style({ padding: `${config.space.S100} 0` });
|
||||
|
||||
export const Note = style({
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
boxSizing: 'border-box',
|
||||
minHeight: 44,
|
||||
margin: `${config.space.S200} 0`,
|
||||
font: 'inherit',
|
||||
color: 'inherit',
|
||||
background: 'none',
|
||||
border: `1px solid ${color.Background.ContainerLine}`,
|
||||
opacity: config.opacity.Disabled,
|
||||
});
|
||||
|
||||
/** Sticky beside the rows on wide screens; a small fixed corner image on phones. */
|
||||
export const Booth = style({
|
||||
position: 'sticky',
|
||||
top: config.space.S400,
|
||||
width: toRem(168),
|
||||
flexShrink: 0,
|
||||
'@media': {
|
||||
[PHONE]: {
|
||||
position: 'fixed',
|
||||
top: 'auto',
|
||||
right: config.space.S200,
|
||||
bottom: config.space.S200,
|
||||
width: toRem(88),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// PoseAvatar's button is laid out for message gutters; the booth takes it back into flow.
|
||||
globalStyle(`${Booth} > button`, {
|
||||
position: 'static',
|
||||
float: 'none',
|
||||
display: 'block',
|
||||
width: '100%',
|
||||
height: 'auto',
|
||||
margin: 0,
|
||||
maskImage: 'none',
|
||||
WebkitMaskImage: 'none',
|
||||
cursor: 'default',
|
||||
});
|
||||
|
||||
export const BoothLine = style({
|
||||
'@media': {
|
||||
// Still read out by the live region; only the picture shows in the corner.
|
||||
[PHONE]: {
|
||||
position: 'absolute',
|
||||
width: 1,
|
||||
height: 1,
|
||||
overflow: 'hidden',
|
||||
clip: 'rect(0 0 0 0)',
|
||||
whiteSpace: 'nowrap',
|
||||
},
|
||||
},
|
||||
});
|
||||
110
src/app/features/desk/DeskView.test.tsx
Normal file
110
src/app/features/desk/DeskView.test.tsx
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
import React from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { ScreenSize, ScreenSizeProvider } from '../../hooks/useScreenSize';
|
||||
import { DeskEntry } from './DeskEntry';
|
||||
import { DeskView, SIGN_IN_NOTE } from './DeskView';
|
||||
import { NOW, STATES } from './fixtures';
|
||||
import { setDeskSource } from './source';
|
||||
|
||||
const view = (state: keyof typeof STATES, size: ScreenSize, mind = 'void') =>
|
||||
renderToStaticMarkup(
|
||||
<ScreenSizeProvider value={size}>
|
||||
<DeskView mind={mind} label="Void" projection={STATES[state]} now={NOW} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
|
||||
describe('DeskView', () => {
|
||||
it('folds a row behind its title on a phone, with the fold button saying so', () => {
|
||||
const html = view('noAnswers', ScreenSize.Mobile);
|
||||
expect(html).toContain('aria-expanded="false"');
|
||||
expect(html).toContain('Question plain');
|
||||
expect(html).not.toContain('Context for plain');
|
||||
expect(html).not.toContain('First way');
|
||||
});
|
||||
it('shows the row open, with no fold button, on a wide screen', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html).not.toContain('aria-expanded');
|
||||
expect(html).toContain('Context for plain');
|
||||
expect(html).toContain('First way');
|
||||
});
|
||||
it('states the recommendation in words, on that option only', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html.match(/\(recommended\)/g)).toHaveLength(1);
|
||||
expect(html).toContain('B Second way (recommended)');
|
||||
});
|
||||
it('shows the depends line with the dependency status', () => {
|
||||
expect(view('blocked', ScreenSize.Desktop)).toContain(
|
||||
'Waits on: "Needs the first one settled" (open)'
|
||||
);
|
||||
});
|
||||
it('keeps the note disabled and says why in a sentence the field points at', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html).toMatch(/<textarea[^>]* disabled=""/);
|
||||
expect(html).toContain(SIGN_IN_NOTE);
|
||||
expect(SIGN_IN_NOTE).toMatch(/sign-in/);
|
||||
expect(html).toMatch(/aria-describedby="note-[^"]+-why"/);
|
||||
});
|
||||
it('says No answers yet on a row without answers', () => {
|
||||
expect(view('noAnswers', ScreenSize.Desktop)).toContain('No answers yet.');
|
||||
});
|
||||
it('shows how long a long-open question has waited', () => {
|
||||
expect(view('longOpen', ScreenSize.Desktop)).toContain('Open for 21 days');
|
||||
});
|
||||
it('lists settled questions as recorded rulings with the ruling id', () => {
|
||||
const html = view('settled', ScreenSize.Desktop);
|
||||
expect(html).toContain('Recorded as rulings');
|
||||
expect(html).toContain('Question done (ruling:done-1)');
|
||||
expect(html).not.toContain('Question shut');
|
||||
});
|
||||
it('says it may be out of date when stale, and says nothing of the kind when fresh', () => {
|
||||
expect(view('stale', ScreenSize.Desktop)).toContain('may be out of date');
|
||||
expect(view('noAnswers', ScreenSize.Desktop)).not.toContain('out of date');
|
||||
});
|
||||
it('says nothing is waiting when empty, and that nothing is published when it never arrived', () => {
|
||||
expect(view('empty', ScreenSize.Desktop)).toContain('Nothing is waiting on you from Void.');
|
||||
expect(view('unpublished', ScreenSize.Desktop)).toContain(
|
||||
'Void's questions have not been published yet.'
|
||||
);
|
||||
});
|
||||
it('shows hidden and erased rows as withheld stubs', () => {
|
||||
expect(view('hidden', ScreenSize.Desktop)).toContain('hidden by Kiko');
|
||||
expect(view('erased', ScreenSize.Desktop)).toContain('erased account');
|
||||
});
|
||||
it('seats the Mind in the booth with the pose for the desk mood', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html).toContain('data-pose="thinking"');
|
||||
expect(html).toContain('Just one fork on the desk.');
|
||||
});
|
||||
it('shows no booth for a Mind without art rather than another face', () => {
|
||||
expect(view('noAnswers', ScreenSize.Desktop, 'nobody')).not.toContain('data-pose');
|
||||
});
|
||||
it('shows no booth before anything is published', () => {
|
||||
expect(view('unpublished', ScreenSize.Desktop)).not.toContain('data-pose');
|
||||
});
|
||||
});
|
||||
|
||||
describe('DeskEntry', () => {
|
||||
afterEach(() => setDeskSource(() => undefined));
|
||||
const entry = (mind: string) =>
|
||||
renderToStaticMarkup(
|
||||
<MemoryRouter>
|
||||
<DeskEntry mind={mind} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
it('reads "Desk · N open" and links to that Mind\'s desk', () => {
|
||||
setDeskSource(() => STATES.blocked);
|
||||
const html = entry('void');
|
||||
expect(html).toContain('Desk · 2 open');
|
||||
expect(html).toContain('href="/desk/void"');
|
||||
});
|
||||
it('is absent at zero open, when nothing is published, and when only settled forks exist', () => {
|
||||
setDeskSource(() => STATES.empty);
|
||||
expect(entry('void')).toBe('');
|
||||
setDeskSource(() => undefined);
|
||||
expect(entry('void')).toBe('');
|
||||
setDeskSource(() => ({ ...STATES.settled, questions: STATES.settled.questions.slice(0, 2) }));
|
||||
expect(entry('void')).toBe('');
|
||||
});
|
||||
});
|
||||
161
src/app/features/desk/DeskView.tsx
Normal file
161
src/app/features/desk/DeskView.tsx
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Text } from 'folds';
|
||||
import { PoseAvatar } from '../../components/message/pose/PoseAvatar';
|
||||
import { MINDS } from '../../components/message/pose/poses';
|
||||
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
|
||||
import { AnswerRow, Desk, DeskRow, buildDesk } from './buildDesk';
|
||||
import { DeskProjection } from './feedback';
|
||||
import { deskMood } from './deskMood';
|
||||
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 date = (iso: string) => iso.slice(0, 10);
|
||||
|
||||
const age = (row: Extract<DeskRow, { kind: 'question' }>) => {
|
||||
if (row.longOpen) return `Open for ${row.ageDays} days`;
|
||||
if (row.ageDays === 0) return 'Asked today';
|
||||
return row.ageDays === 1 ? 'Asked 1 day ago' : `Asked ${row.ageDays} days ago`;
|
||||
};
|
||||
|
||||
function Answers({ answers }: { answers: AnswerRow[] }) {
|
||||
if (answers.length === 0) return <p className={css.Quiet}>No answers yet.</p>;
|
||||
return (
|
||||
<ul className={css.Options}>
|
||||
{answers.map((a) => (
|
||||
<li key={a.recordId} className={css.Option}>
|
||||
{`${a.who}, ${a.kind.toLowerCase()}: `}
|
||||
{a.withheld ?? [a.choice, a.text && `"${a.text}"`].filter(Boolean).join(' ')}
|
||||
{` (${date(a.at)})`}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ row }: { row: DeskRow }) {
|
||||
const phone = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
// Phones list titles; a tap opens one. Wide screens show every row open.
|
||||
const [open, setOpen] = useState(!phone);
|
||||
if (row.kind === 'hidden') {
|
||||
return (
|
||||
<li className={css.Row}>
|
||||
<p className={css.Quiet}>
|
||||
{`A question here is hidden by ${row.hidden.by}, ${date(row.hidden.at)}, ${
|
||||
row.hidden.reason
|
||||
}.`}
|
||||
</p>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
const noteId = `note-${row.forkId}`;
|
||||
return (
|
||||
<li className={css.Row}>
|
||||
<h3 className={css.Title}>
|
||||
{phone ? (
|
||||
<button
|
||||
type="button"
|
||||
className={css.Fold}
|
||||
aria-expanded={open}
|
||||
onClick={() => setOpen(!open)}
|
||||
>
|
||||
{row.title}
|
||||
</button>
|
||||
) : (
|
||||
row.title
|
||||
)}
|
||||
</h3>
|
||||
<p className={css.Quiet}>{age(row)}</p>
|
||||
{open && (
|
||||
<>
|
||||
<p className={css.Body}>{row.body}</p>
|
||||
<ul className={css.Options}>
|
||||
{row.options.map((o) => (
|
||||
<li key={o.id} className={css.Option}>
|
||||
{`${o.id} ${o.text}`}
|
||||
{o.recommended && ' (recommended)'}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{row.depends.map((d) => (
|
||||
<p key={d.text} className={css.Quiet}>
|
||||
{`Waits on: "${d.text}"${d.status ? ` (${d.status})` : ''}`}
|
||||
</p>
|
||||
))}
|
||||
<span id={`${noteId}-label`}>Your note</span>
|
||||
<textarea
|
||||
className={css.Note}
|
||||
disabled
|
||||
aria-labelledby={`${noteId}-label`}
|
||||
aria-describedby={`${noteId}-why`}
|
||||
/>
|
||||
<p id={`${noteId}-why`} className={css.Quiet}>
|
||||
{SIGN_IN_NOTE}
|
||||
</p>
|
||||
<Answers answers={row.answers} />
|
||||
</>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
function Status({ desk, label }: { desk: Desk; label: string }) {
|
||||
if (!desk.published) return <p>{`${label}'s questions have not been published yet.`}</p>;
|
||||
return (
|
||||
<p role="status">
|
||||
{desk.counts.open === 0
|
||||
? `Nothing is waiting on you from ${label}. `
|
||||
: `${desk.counts.open} open. `}
|
||||
{`Synced ${desk.syncedAt && date(desk.syncedAt)}.`}
|
||||
{desk.stale && ' This may be out of date.'}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
type DeskViewProps = {
|
||||
/** The Mind's key, as the navigator groups it. */
|
||||
mind: string;
|
||||
label: string;
|
||||
projection?: DeskProjection;
|
||||
now: number;
|
||||
};
|
||||
|
||||
/** One Mind's desk, read-only: a stream of rows, the recorded rulings, and the booth Persona. */
|
||||
export function DeskView({ mind, label, projection, now }: DeskViewProps) {
|
||||
const desk = buildDesk(projection, now);
|
||||
const mood = deskMood(desk.counts.open, desk.counts.answered);
|
||||
return (
|
||||
<section aria-label={`${label}'s desk`}>
|
||||
<Status desk={desk} label={label} />
|
||||
<div className={css.Layout}>
|
||||
<ol className={css.Rows}>
|
||||
{desk.open.map((row) => (
|
||||
<Row key={row.forkId} row={row} />
|
||||
))}
|
||||
</ol>
|
||||
{/* Only Minds with art in the catalogue get a booth; none gets another Mind's face. */}
|
||||
{desk.published && MINDS.includes(mind) && (
|
||||
<div className={css.Booth}>
|
||||
<PoseAvatar mind={mind} pose={mood.pose} userId={mind} onClick={() => undefined} />
|
||||
<Text className={css.BoothLine} size="T200" aria-live="polite">
|
||||
{mood.line}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{desk.recorded.length > 0 && (
|
||||
<>
|
||||
<h3 className={css.Title}>Recorded as rulings</h3>
|
||||
<ul className={css.Options}>
|
||||
{desk.recorded.map((r) => (
|
||||
<li key={r.forkId} className={css.Option}>
|
||||
{`${r.title} (${r.rulingId})`}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
127
src/app/features/desk/buildDesk.test.ts
Normal file
127
src/app/features/desk/buildDesk.test.ts
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { LONG_OPEN_DAYS, buildDesk, countOpen } from './buildDesk';
|
||||
import { NOW, STATES } from './fixtures';
|
||||
|
||||
const questions = (d: ReturnType<typeof buildDesk>) =>
|
||||
d.open.flatMap((r) => (r.kind === 'question' ? [r] : []));
|
||||
|
||||
describe('buildDesk', () => {
|
||||
it('says "not published" for a projection that never arrived, never "no questions"', () => {
|
||||
expect(buildDesk(undefined, NOW).published).toBe(false);
|
||||
expect(buildDesk(STATES.unpublished, NOW)).toMatchObject({
|
||||
published: false,
|
||||
open: [],
|
||||
counts: { open: 0, answered: 0 },
|
||||
});
|
||||
});
|
||||
it('is published and empty, with its sync time, when nothing is open', () => {
|
||||
const d = buildDesk(STATES.empty, NOW);
|
||||
expect(d).toMatchObject({ published: true, open: [], counts: { open: 0 } });
|
||||
expect(d.syncedAt).toBeDefined();
|
||||
});
|
||||
it('is stale only past thirty minutes since sync', () => {
|
||||
expect(buildDesk(STATES.noAnswers, NOW).stale).toBe(false);
|
||||
expect(buildDesk(STATES.stale, NOW).stale).toBe(true);
|
||||
});
|
||||
it('shows no answers as an empty list on an open row', () => {
|
||||
expect(questions(buildDesk(STATES.noAnswers, NOW))[0].answers).toEqual([]);
|
||||
});
|
||||
it('flags a question open past fourteen days and keeps it listed', () => {
|
||||
const [row] = questions(buildDesk(STATES.longOpen, NOW));
|
||||
expect(row).toMatchObject({ ageDays: 21, longOpen: true });
|
||||
expect(LONG_OPEN_DAYS).toBe(14);
|
||||
expect(questions(buildDesk(STATES.noAnswers, NOW))[0].longOpen).toBe(false);
|
||||
});
|
||||
it('puts the long-open line past fourteen days exactly: day 14 is not long, day 15 is', () => {
|
||||
const at = (days: number) => {
|
||||
const p = structuredClone(STATES.noAnswers);
|
||||
(p.questions[0] as { askedAt: string }).askedAt = new Date(
|
||||
NOW - days * 86400000
|
||||
).toISOString();
|
||||
return questions(buildDesk(p, NOW))[0].longOpen;
|
||||
};
|
||||
expect([at(14), at(15)]).toEqual([false, true]);
|
||||
});
|
||||
it('resolves the recommendation to its option, marks only that option, and never preselects', () => {
|
||||
const [row] = questions(buildDesk(STATES.noAnswers, NOW));
|
||||
expect(row.recommended).toBe('Second way');
|
||||
expect(row.options.filter((o) => o.recommended).map((o) => o.id)).toEqual(['B']);
|
||||
});
|
||||
it('leaves the recommendation unresolved when it names no option', () => {
|
||||
const p = structuredClone(STATES.noAnswers);
|
||||
(p.questions[0] as { recommendation?: string }).recommendation = 'Z';
|
||||
const [row] = questions(buildDesk(p, NOW));
|
||||
expect(row.recommended).toBeUndefined();
|
||||
expect(row.options.some((o) => o.recommended)).toBe(false);
|
||||
});
|
||||
it('carries the status of a cited dependency, and none for one that cites no question', () => {
|
||||
const rows = questions(buildDesk(STATES.blocked, NOW));
|
||||
expect(rows.find((r) => r.forkId.endsWith('second'))?.depends).toEqual([
|
||||
{ text: 'Needs the first one settled', status: 'open' },
|
||||
]);
|
||||
expect(rows.find((r) => r.forkId.endsWith('first'))?.depends).toEqual([]);
|
||||
});
|
||||
it('lists a settled question under recorded rulings with its ruling id, not as open; drops a closed one', () => {
|
||||
const d = buildDesk(STATES.settled, NOW);
|
||||
expect(d.recorded).toEqual([
|
||||
{ forkId: 'c:question:done', title: 'Question done', rulingId: 'ruling:done-1' },
|
||||
]);
|
||||
expect(d.open.map((r) => r.forkId)).toEqual(['c:question:live']);
|
||||
});
|
||||
it('orders open rows oldest first', () => {
|
||||
const p = structuredClone(STATES.blocked);
|
||||
(p.questions[0] as { askedAt: string }).askedAt = new Date(NOW).toISOString();
|
||||
expect(buildDesk(p, NOW).open.map((r) => r.forkId)).toEqual([
|
||||
'c:question:second',
|
||||
'c:question:first',
|
||||
]);
|
||||
});
|
||||
it('folds earlier answers by one account under its latest and shows choice as option text', () => {
|
||||
const [row] = questions(buildDesk(STATES.answered, NOW));
|
||||
expect(row.answers).toHaveLength(2);
|
||||
const first = row.answers.find((a) => a.recordId === 'plain.a2');
|
||||
expect(first).toMatchObject({ choice: 'Third way', text: 'On reflection, third.' });
|
||||
expect(row.answers.some((a) => a.recordId === 'plain.a1')).toBe(false);
|
||||
});
|
||||
it('lists answers oldest first and tallies nothing', () => {
|
||||
const [row] = questions(buildDesk(STATES.answered, NOW));
|
||||
const times = row.answers.map((a) => a.at);
|
||||
expect([...times].sort()).toEqual(times);
|
||||
expect(Object.keys(buildDesk(STATES.answered, NOW).counts).sort()).toEqual([
|
||||
'answered',
|
||||
'open',
|
||||
]);
|
||||
});
|
||||
it('withholds a hidden answer and a hidden question, naming who hid them', () => {
|
||||
const d = buildDesk(STATES.hidden, NOW);
|
||||
expect(d.open.find((r) => r.kind === 'hidden')).toMatchObject({
|
||||
hidden: { by: 'Kiko', reason: 'PrivateMatter' },
|
||||
});
|
||||
const [row] = questions(d);
|
||||
expect(row.answers[0]).toMatchObject({ choice: undefined, text: undefined });
|
||||
expect(row.answers[0].withheld).toMatch(/^Hidden by Kiko, 2026-11-\d\d, Spam$/);
|
||||
});
|
||||
it('does not count a hidden question as open', () => {
|
||||
expect(buildDesk(STATES.hidden, NOW).counts.open).toBe(1);
|
||||
expect(countOpen(STATES.hidden)).toBe(1);
|
||||
});
|
||||
it('shows an erased author as "erased account" with no name or content, keeping kind and time', () => {
|
||||
const [row] = questions(buildDesk(STATES.erased, NOW));
|
||||
expect(row.answers[0]).toMatchObject({
|
||||
who: 'erased account',
|
||||
kind: 'Member',
|
||||
choice: undefined,
|
||||
text: undefined,
|
||||
});
|
||||
expect(row.answers[0].withheld).toBeDefined();
|
||||
expect(row.answers[0].at).toBeDefined();
|
||||
});
|
||||
it('counts answered only for the viewer, so a signed-out desk has none', () => {
|
||||
expect(buildDesk(STATES.answered, NOW).counts.answered).toBe(0);
|
||||
expect(buildDesk(STATES.answered, NOW, 'acct-1').counts.answered).toBe(1);
|
||||
expect(buildDesk(STATES.answered, NOW, 'acct-9').counts.answered).toBe(0);
|
||||
});
|
||||
it('does not count the viewer as answered when their only answer was hidden', () => {
|
||||
expect(buildDesk(STATES.hidden, NOW, 'acct-1').counts.answered).toBe(0);
|
||||
});
|
||||
});
|
||||
153
src/app/features/desk/buildDesk.ts
Normal file
153
src/app/features/desk/buildDesk.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import {
|
||||
Answer,
|
||||
DeskProjection,
|
||||
Hidden,
|
||||
Question,
|
||||
QuestionStatus,
|
||||
isHiddenQuestion,
|
||||
} from './feedback';
|
||||
|
||||
/** Past two heartbeats the projection may be out of date (provisional, doc section 8). */
|
||||
export const STALE_MS = 30 * 60 * 1000;
|
||||
/** Past this a question shows how long it has waited; it is never demoted or hidden (provisional). */
|
||||
export const LONG_OPEN_DAYS = 14;
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
export type AnswerRow = {
|
||||
recordId: string;
|
||||
/** Never a handle: the name at answer time, or the words for an account that has none. */
|
||||
who: string;
|
||||
kind: Answer['kind'];
|
||||
/** The option's text for a choice. */
|
||||
choice?: string;
|
||||
text?: string;
|
||||
at: string;
|
||||
/** Why the content is not shown: hidden by the Mind, or the author's account was erased. */
|
||||
withheld?: string;
|
||||
};
|
||||
|
||||
export type DeskRow =
|
||||
| { kind: 'hidden'; forkId: string; hidden: Hidden }
|
||||
| {
|
||||
kind: 'question';
|
||||
forkId: string;
|
||||
title: string;
|
||||
body: string;
|
||||
options: { id: string; text: string; recommended: boolean }[];
|
||||
/** The recommendation resolved to its option's text; absent if it names no option. */
|
||||
recommended?: string;
|
||||
depends: { text: string; status?: QuestionStatus['state'] }[];
|
||||
ageDays: number;
|
||||
longOpen: boolean;
|
||||
answers: AnswerRow[];
|
||||
};
|
||||
|
||||
export type Desk = {
|
||||
/** False until the projection first arrives: "not published yet", never "no questions". */
|
||||
published: boolean;
|
||||
syncedAt?: string;
|
||||
stale: boolean;
|
||||
/** Oldest first. */
|
||||
open: DeskRow[];
|
||||
/** Settled questions with the Mind's ruling id. Closed (withdrawn) questions are not listed. */
|
||||
recorded: { forkId: string; title: string; rulingId: string }[];
|
||||
/** Derived for the booth mood. The page tallies nothing about answers. */
|
||||
counts: { open: number; answered: number };
|
||||
};
|
||||
|
||||
const ageDays = (iso: string, now: number) =>
|
||||
Math.max(0, Math.floor((now - Date.parse(iso)) / DAY_MS));
|
||||
|
||||
const answerRow = (a: Answer, q: Question): AnswerRow => {
|
||||
let withheld: string | undefined;
|
||||
if (a.hidden)
|
||||
withheld = `Hidden by ${a.hidden.by}, ${a.hidden.at.slice(0, 10)}, ${a.hidden.reason}`;
|
||||
else if (a.erased) withheld = 'Author erased their account';
|
||||
const choice = withheld ? undefined : a.answer?.choice;
|
||||
return {
|
||||
recordId: a.recordId,
|
||||
who: a.erased ? 'erased account' : a.displayName ?? 'an account',
|
||||
kind: a.kind,
|
||||
choice:
|
||||
choice === undefined ? undefined : q.options.find((o) => o.id === choice)?.text ?? choice,
|
||||
text: withheld ? undefined : a.answer?.text,
|
||||
at: a.answered_at,
|
||||
withheld,
|
||||
};
|
||||
};
|
||||
|
||||
/** Earlier answers by the same account fold under their latest; the page never counts them. */
|
||||
const standing = (answers: Answer[]): Answer[] => {
|
||||
const latest = new Map<string, Answer>();
|
||||
answers.forEach((a) => {
|
||||
const key = a.answerer ?? a.recordId;
|
||||
const held = latest.get(key);
|
||||
if (!held || held.answered_at <= a.answered_at) latest.set(key, a);
|
||||
});
|
||||
return [...latest.values()].sort((a, b) => a.answered_at.localeCompare(b.answered_at));
|
||||
};
|
||||
|
||||
/** Open questions the page would list: the one rule the navigator's count and the desk share. */
|
||||
export const countOpen = (p?: DeskProjection): number =>
|
||||
p?.questions.filter((q) => !isHiddenQuestion(q) && q.status.state === 'open').length ?? 0;
|
||||
|
||||
export const buildDesk = (p: DeskProjection | undefined, now: number, viewerId?: string): Desk => {
|
||||
if (!p?.syncedAt) {
|
||||
return {
|
||||
published: false,
|
||||
stale: false,
|
||||
open: [],
|
||||
recorded: [],
|
||||
counts: { open: 0, answered: 0 },
|
||||
};
|
||||
}
|
||||
const known = new Map<string, Question>();
|
||||
p.questions.forEach((q) => !isHiddenQuestion(q) && known.set(q.fork_id, q));
|
||||
|
||||
const open: DeskRow[] = [];
|
||||
const recorded: Desk['recorded'] = [];
|
||||
let answered = 0;
|
||||
[...p.questions]
|
||||
.sort((a, b) => {
|
||||
const at = (q: typeof a) => (isHiddenQuestion(q) ? '' : q.askedAt);
|
||||
return at(a).localeCompare(at(b));
|
||||
})
|
||||
.forEach((q) => {
|
||||
if (isHiddenQuestion(q)) {
|
||||
open.push({ kind: 'hidden', forkId: q.fork_id, hidden: q.hidden });
|
||||
return;
|
||||
}
|
||||
if (q.status.state === 'answered') {
|
||||
recorded.push({ forkId: q.fork_id, title: q.title, rulingId: q.status.rulingId });
|
||||
return;
|
||||
}
|
||||
if (q.status.state !== 'open') return;
|
||||
const mine = standing(p.answers.filter((a) => a.fork_id === q.fork_id));
|
||||
if (viewerId && mine.some((a) => a.answerer === viewerId && !a.hidden)) answered += 1;
|
||||
const days = ageDays(q.askedAt, now);
|
||||
open.push({
|
||||
kind: 'question',
|
||||
forkId: q.fork_id,
|
||||
title: q.title,
|
||||
body: q.body,
|
||||
options: q.options.map((o) => ({ ...o, recommended: o.id === q.recommendation })),
|
||||
recommended: q.options.find((o) => o.id === q.recommendation)?.text,
|
||||
depends: q.dependsOn.map((d) => ({
|
||||
text: d.text,
|
||||
status: d.questionId ? known.get(d.questionId)?.status.state : undefined,
|
||||
})),
|
||||
ageDays: days,
|
||||
longOpen: days > LONG_OPEN_DAYS,
|
||||
answers: mine.map((a) => answerRow(a, q)),
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
published: true,
|
||||
syncedAt: p.syncedAt,
|
||||
stale: now - Date.parse(p.syncedAt) > STALE_MS,
|
||||
open,
|
||||
recorded,
|
||||
counts: { open: countOpen(p), answered },
|
||||
};
|
||||
};
|
||||
59
src/app/features/desk/deskMood.test.ts
Normal file
59
src/app/features/desk/deskMood.test.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { MINDS, resolvePose } from '../../components/message/pose/poses';
|
||||
import { MOOD_POSE, deskMood } from './deskMood';
|
||||
|
||||
describe('deskMood', () => {
|
||||
it('is neutral with the desk clear when nothing is open', () => {
|
||||
expect(deskMood(0, 0)).toEqual({
|
||||
mood: 'neutral',
|
||||
pose: 'neutral',
|
||||
line: "Desk's clear. I'll wave when something lands.",
|
||||
});
|
||||
});
|
||||
it('is triumph when every open fork is answered', () => {
|
||||
expect(deskMood(3, 3).mood).toBe('triumph');
|
||||
expect(deskMood(1, 1).mood).toBe('triumph');
|
||||
});
|
||||
it('is thinking when none is answered, and says whether it is one fork or several', () => {
|
||||
expect(deskMood(1, 0)).toMatchObject({ mood: 'thinking', line: 'Just one fork on the desk.' });
|
||||
expect(deskMood(4, 0)).toMatchObject({
|
||||
mood: 'thinking',
|
||||
line: '4 forks on the desk. No rush.',
|
||||
});
|
||||
});
|
||||
it('is determined partway, counting what is left', () => {
|
||||
expect(deskMood(5, 2)).toMatchObject({ mood: 'determined', line: '3 to go.' });
|
||||
});
|
||||
it('is happy when the pick is the recommendation', () => {
|
||||
expect(deskMood(2, 0, { type: 'picked', choice: 'B', recommended: 'B' }).mood).toBe('happy');
|
||||
});
|
||||
it('is surprised, and asks for a line on why, when the pick differs', () => {
|
||||
expect(deskMood(2, 0, { type: 'picked', choice: 'A', recommended: 'B' })).toMatchObject({
|
||||
mood: 'surprised',
|
||||
line: expect.stringContaining('A line in the note on why helps'),
|
||||
});
|
||||
});
|
||||
it('is surprised, not happy, when there is no recommendation to match', () => {
|
||||
expect(deskMood(2, 0, { type: 'picked', choice: 'A' }).mood).toBe('surprised');
|
||||
});
|
||||
it('is note when a pick is cleared, saying the note can carry the answer', () => {
|
||||
expect(deskMood(2, 1, { type: 'cleared' })).toMatchObject({
|
||||
mood: 'note',
|
||||
line: expect.stringContaining('note can carry the answer on its own'),
|
||||
});
|
||||
});
|
||||
it('is concerned when a send failed, even with everything answered', () => {
|
||||
expect(deskMood(2, 2, { type: 'sendFailed' }).mood).toBe('concerned');
|
||||
});
|
||||
it('is surprised when a new fork arrives, even on a clear desk', () => {
|
||||
expect(deskMood(0, 0, { type: 'newFork' })).toMatchObject({
|
||||
mood: 'surprised',
|
||||
line: 'New fork on the desk!',
|
||||
});
|
||||
});
|
||||
it('maps every mood to a label every Mind in the catalogue can show', () => {
|
||||
Object.values(MOOD_POSE).forEach((pose) =>
|
||||
MINDS.forEach((mind) => expect(resolvePose(mind, pose)).toBe(pose))
|
||||
);
|
||||
});
|
||||
});
|
||||
75
src/app/features/desk/deskMood.ts
Normal file
75
src/app/features/desk/deskMood.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* The booth Persona's reactions, from the original Fork Desk's mood() and choose() rules. A pure function of
|
||||
* what is on the desk and the last thing that happened; it is the desk's character, so each rule is tested.
|
||||
*/
|
||||
|
||||
/** The original's nine moods. */
|
||||
export type Mood =
|
||||
| 'idle'
|
||||
| 'neutral'
|
||||
| 'thinking'
|
||||
| 'happy'
|
||||
| 'surprised'
|
||||
| 'note'
|
||||
| 'determined'
|
||||
| 'triumph'
|
||||
| 'concerned';
|
||||
|
||||
/** What last happened; `none` means nothing since the page opened or the last event wore off. */
|
||||
export type DeskEvent =
|
||||
| { type: 'none' }
|
||||
| { type: 'picked'; choice: string; recommended?: string }
|
||||
| { type: 'cleared' }
|
||||
| { type: 'sendFailed' }
|
||||
| { type: 'newFork' };
|
||||
|
||||
/**
|
||||
* Each mood on the shared cast-art labels (neutral, happy, amused, thinking, annoyed, surprised) that every
|
||||
* Mind has, so the booth never asks a Mind for art it lacks.
|
||||
*/
|
||||
export const MOOD_POSE: Record<Mood, string> = {
|
||||
idle: 'neutral',
|
||||
neutral: 'neutral',
|
||||
thinking: 'thinking',
|
||||
happy: 'happy',
|
||||
surprised: 'surprised',
|
||||
note: 'thinking',
|
||||
determined: 'thinking',
|
||||
triumph: 'happy',
|
||||
concerned: 'surprised',
|
||||
};
|
||||
|
||||
export type DeskMood = { mood: Mood; pose: string; line: string };
|
||||
|
||||
const say = (mood: Mood, line: string): DeskMood => ({ mood, pose: MOOD_POSE[mood], line });
|
||||
|
||||
export const deskMood = (
|
||||
open: number,
|
||||
answered: number,
|
||||
event: DeskEvent = { type: 'none' }
|
||||
): DeskMood => {
|
||||
switch (event.type) {
|
||||
case 'sendFailed':
|
||||
return say('concerned', "That one didn't save. Give it another try in a moment?");
|
||||
case 'newFork':
|
||||
return say('surprised', 'New fork on the desk!');
|
||||
case 'cleared':
|
||||
return say('note', 'Pick cleared. Your note can carry the answer on its own.');
|
||||
case 'picked':
|
||||
return event.recommended !== undefined && event.choice === event.recommended
|
||||
? say('happy', "That's the one I'd have picked too.")
|
||||
: say('surprised', 'Off-script. A line in the note on why helps the next brief.');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (open === 0) return say('neutral', "Desk's clear. I'll wave when something lands.");
|
||||
if (answered >= open)
|
||||
return say('triumph', 'All answered! I will carry these back and admit them.');
|
||||
if (answered === 0) {
|
||||
return say(
|
||||
'thinking',
|
||||
open === 1 ? 'Just one fork on the desk.' : `${open} forks on the desk. No rush.`
|
||||
);
|
||||
}
|
||||
return say('determined', `${open - answered} to go.`);
|
||||
};
|
||||
70
src/app/features/desk/feedback.ts
Normal file
70
src/app/features/desk/feedback.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* The desk's typed view of the feedback projections in docs/mind-feedback-pages.md (sections 5 and 12):
|
||||
* org.gamecult.feedback.question.v0 and org.gamecult.feedback.answer.v0. Bifrost serves them; the page
|
||||
* reads them and stores nothing. `answerer`, `kind` and `weightPermille` are the receiver's stamp from the
|
||||
* verified session; the client never supplies them, so nothing here has a write shape.
|
||||
*/
|
||||
|
||||
export type Hidden = { by: string; at: string; reason: string };
|
||||
|
||||
/** The status is derived in the owning Mind; the page shows it and never writes it. */
|
||||
export type QuestionStatus =
|
||||
| { state: 'open' }
|
||||
| { state: 'answered'; rulingId: string }
|
||||
| { state: 'closed' };
|
||||
|
||||
export type Question = {
|
||||
/** `<campaign>:question:<label>`. */
|
||||
fork_id: string;
|
||||
owner: string;
|
||||
title: string;
|
||||
body: string;
|
||||
/** `id` is the option's label. */
|
||||
options: { id: string; text: string }[];
|
||||
/** An option label. Never preselected. */
|
||||
recommendation?: string;
|
||||
/** `questionId` only where the line cites one question verbatim. */
|
||||
dependsOn: { text: string; questionId?: string }[];
|
||||
/** An ISO instant: the question's receipt `committed_at`. */
|
||||
askedAt: string;
|
||||
status: QuestionStatus;
|
||||
/**
|
||||
* Publisher's sha256 over canonical JSON of what is shown (id, title, body, options, recommendation,
|
||||
* depends). Slice 1 carries it and does not recompute it: the canonicalization has no golden vector
|
||||
* pinned across Rust and TS yet, and a recompute against an unpinned form would prove nothing.
|
||||
*/
|
||||
options_hash: string;
|
||||
};
|
||||
|
||||
/** A hidden question keeps a stub; title, body, options and answers are withheld. */
|
||||
export type HiddenQuestion = { fork_id: string; hidden: Hidden };
|
||||
|
||||
export type Answer = {
|
||||
/** `<question-label>.a<N>`. */
|
||||
recordId: string;
|
||||
fork_id: string;
|
||||
options_hash: string;
|
||||
/** Bifrost account id; absent once the account is erased. Receiver-set. */
|
||||
answerer?: string;
|
||||
/** Name and kind as they were at the moment of the answer; the name is gone once erased. Receiver-set. */
|
||||
displayName?: string;
|
||||
kind: 'Guest' | 'User' | 'Patron' | 'Member' | 'Mind';
|
||||
weightPermille: number;
|
||||
/** An option label, free text, or both. Absent while hidden or erased. */
|
||||
answer?: { choice?: string; text?: string };
|
||||
/** ISO instant the receiver accepted it. */
|
||||
answered_at: string;
|
||||
hidden?: Hidden;
|
||||
erased?: boolean;
|
||||
};
|
||||
|
||||
/** What the page holds for one Mind's desk. `syncedAt` is absent until the projection first arrives. */
|
||||
export type DeskProjection = {
|
||||
mind: string;
|
||||
syncedAt?: string;
|
||||
questions: (Question | HiddenQuestion)[];
|
||||
answers: Answer[];
|
||||
};
|
||||
|
||||
export const isHiddenQuestion = (q: Question | HiddenQuestion): q is HiddenQuestion =>
|
||||
'hidden' in q;
|
||||
100
src/app/features/desk/fixtures.ts
Normal file
100
src/app/features/desk/fixtures.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import { Answer, DeskProjection, Question } from './feedback';
|
||||
|
||||
/** The clock every fixture is written against. */
|
||||
export const NOW = Date.parse('2026-11-10T12:00:00Z');
|
||||
const ago = (ms: number) => new Date(NOW - ms).toISOString();
|
||||
const MIN = 60 * 1000;
|
||||
const DAY = 24 * 60 * MIN;
|
||||
|
||||
const q = (label: string, over: Partial<Question> = {}): Question => ({
|
||||
fork_id: `c:question:${label}`,
|
||||
owner: 'mind',
|
||||
title: `Question ${label}`,
|
||||
body: `Context for ${label}.`,
|
||||
options: [
|
||||
{ id: 'A', text: 'First way' },
|
||||
{ id: 'B', text: 'Second way' },
|
||||
{ id: 'C', text: 'Third way' },
|
||||
],
|
||||
recommendation: 'B',
|
||||
dependsOn: [],
|
||||
askedAt: ago(DAY),
|
||||
status: { state: 'open' },
|
||||
options_hash: `hash-${label}`,
|
||||
...over,
|
||||
});
|
||||
|
||||
const a = (label: string, n: number, over: Partial<Answer> = {}): Answer => ({
|
||||
recordId: `${label}.a${n}`,
|
||||
fork_id: `c:question:${label}`,
|
||||
options_hash: `hash-${label}`,
|
||||
answerer: `acct-${n}`,
|
||||
displayName: `Person ${n}`,
|
||||
kind: 'Member',
|
||||
weightPermille: 1000,
|
||||
answer: { choice: 'A' },
|
||||
answered_at: ago(DAY / 2),
|
||||
...over,
|
||||
});
|
||||
|
||||
const desk = (
|
||||
questions: DeskProjection['questions'],
|
||||
answers: Answer[] = [],
|
||||
syncedAt = ago(2 * MIN)
|
||||
) => ({
|
||||
mind: 'mind',
|
||||
syncedAt,
|
||||
questions,
|
||||
answers,
|
||||
});
|
||||
|
||||
/** One projection per state of doc section 8, plus the hidden and erased rows. */
|
||||
export const STATES = {
|
||||
/** The projection never arrived. */
|
||||
unpublished: { mind: 'mind', questions: [], answers: [] } as DeskProjection,
|
||||
empty: desk([]),
|
||||
noAnswers: desk([q('plain')]),
|
||||
stale: desk([q('plain')], [], ago(45 * MIN)),
|
||||
longOpen: desk([q('old', { askedAt: ago(21 * DAY) })]),
|
||||
blocked: desk([
|
||||
q('first'),
|
||||
q('second', {
|
||||
dependsOn: [{ text: 'Needs the first one settled', questionId: 'c:question:first' }],
|
||||
}),
|
||||
]),
|
||||
settled: desk([
|
||||
q('done', { status: { state: 'answered', rulingId: 'ruling:done-1' } }),
|
||||
q('shut', { status: { state: 'closed' } }),
|
||||
q('live'),
|
||||
]),
|
||||
answered: desk(
|
||||
[q('plain')],
|
||||
[
|
||||
a('plain', 1, { answered_at: ago(DAY / 2) }),
|
||||
a('plain', 2, {
|
||||
answerer: 'acct-1',
|
||||
answer: { choice: 'C', text: 'On reflection, third.' },
|
||||
answered_at: ago(DAY / 4),
|
||||
}),
|
||||
a('plain', 3, { kind: 'Mind', answer: { text: 'Either, if measured first.' } }),
|
||||
]
|
||||
),
|
||||
hidden: desk(
|
||||
[
|
||||
q('plain'),
|
||||
{ fork_id: 'c:question:gone', hidden: { by: 'Kiko', at: ago(DAY), reason: 'PrivateMatter' } },
|
||||
],
|
||||
[a('plain', 1, { hidden: { by: 'Kiko', at: ago(DAY / 3), reason: 'Spam' }, answer: undefined })]
|
||||
),
|
||||
erased: desk(
|
||||
[q('plain')],
|
||||
[
|
||||
a('plain', 1, {
|
||||
erased: true,
|
||||
answerer: undefined,
|
||||
displayName: undefined,
|
||||
answer: undefined,
|
||||
}),
|
||||
]
|
||||
),
|
||||
} satisfies Record<string, DeskProjection>;
|
||||
3
src/app/features/desk/index.ts
Normal file
3
src/app/features/desk/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export { Desk } from './Desk';
|
||||
export { DeskEntry } from './DeskEntry';
|
||||
export { setDeskSource } from './source';
|
||||
13
src/app/features/desk/source.ts
Normal file
13
src/app/features/desk/source.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { DeskProjection } from './feedback';
|
||||
|
||||
type DeskSource = (mind: string) => DeskProjection | undefined;
|
||||
|
||||
// Slice 1 reads no network. The preview demo installs seeded forks here; slice 2 replaces this with
|
||||
// Bifrost's projection reader, which is why the page asks a function and not a fixture.
|
||||
let source: DeskSource = () => undefined;
|
||||
|
||||
export const setDeskSource = (next: DeskSource) => {
|
||||
source = next;
|
||||
};
|
||||
|
||||
export const deskFor = (mind: string): DeskProjection | undefined => source(mind);
|
||||
|
|
@ -42,6 +42,7 @@ import { EstateGroup, EstateRoom, EstateTier, splitGroups } from './buildEstate'
|
|||
import { activateEstateRoom, awaitMyJoin } from './joinEstateRoom';
|
||||
import { useEstate, useEstateRootId } from './useEstate';
|
||||
import * as css from './EstateNavigator.css';
|
||||
import { DeskEntry } from '../desk';
|
||||
import { SkyStateControl } from '../scene/SkyStateControl';
|
||||
|
||||
/** How long a tap waits for the client store to hold the room it just joined. */
|
||||
|
|
@ -135,9 +136,11 @@ type CollapsibleProps = {
|
|||
categoryId: string;
|
||||
label: string;
|
||||
rooms: EstateRoom[];
|
||||
/** Sits in the header beside the label, so a collapsed section still shows it. */
|
||||
trailing?: ReactNode;
|
||||
children: ReactNode;
|
||||
};
|
||||
function Collapsible({ categoryId, label, rooms, children }: CollapsibleProps) {
|
||||
function Collapsible({ categoryId, label, rooms, trailing, children }: CollapsibleProps) {
|
||||
const mobile = useScreenSizeContext() === ScreenSize.Mobile;
|
||||
const selectedRoomId = useSelectedRoom();
|
||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||
|
|
@ -161,6 +164,7 @@ function Collapsible({ categoryId, label, rooms, children }: CollapsibleProps) {
|
|||
<RoomNavCategoryButton closed={closed} onClick={handleClick}>
|
||||
{label}
|
||||
</RoomNavCategoryButton>
|
||||
{trailing}
|
||||
</NavCategoryHeader>
|
||||
{!closed && children}
|
||||
</NavCategory>
|
||||
|
|
@ -169,7 +173,12 @@ function Collapsible({ categoryId, label, rooms, children }: CollapsibleProps) {
|
|||
|
||||
function GroupSection({ tierId, group }: { tierId: string; group: EstateGroup }) {
|
||||
return (
|
||||
<Collapsible categoryId={`${tierId}|${group.mind}`} label={group.label} rooms={group.rooms}>
|
||||
<Collapsible
|
||||
categoryId={`${tierId}|${group.mind}`}
|
||||
label={group.label}
|
||||
rooms={group.rooms}
|
||||
trailing={<DeskEntry mind={group.mind} />}
|
||||
>
|
||||
{group.rooms.map((r) => (
|
||||
<EstateRow key={r.roomId} room={r} />
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import { ClientConfig } from '../hooks/useClientConfig';
|
|||
import { AuthLayout, Login, Register, ResetPassword } from './auth';
|
||||
import {
|
||||
DIRECT_PATH,
|
||||
DESK_PATH,
|
||||
EXPLORE_PATH,
|
||||
HOME_PATH,
|
||||
LOGIN_PATH,
|
||||
|
|
@ -48,6 +49,7 @@ import { Notifications, Inbox, Invites } from './client/inbox';
|
|||
import { setAfterLoginRedirectPath } from './afterLoginRedirectPath';
|
||||
import { Room } from '../features/room';
|
||||
import { Lobby } from '../features/lobby';
|
||||
import { Desk } from '../features/desk';
|
||||
import { WelcomePage } from './client/WelcomePage';
|
||||
import { EstatePageNav } from './client/EstatePageNav';
|
||||
import { PageRoot } from '../components/page';
|
||||
|
|
@ -246,6 +248,15 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
|||
<Route path={_FEATURED_PATH} element={<FeaturedRooms />} />
|
||||
<Route path={_SERVER_PATH} element={<PublicRooms />} />
|
||||
</Route>
|
||||
<Route
|
||||
path={DESK_PATH}
|
||||
element={
|
||||
// The navigator shows beside the desk on wide screens; a phone shows the desk alone.
|
||||
<PageRoot nav={<EstatePageNav path={HOME_PATH} />}>
|
||||
<Desk />
|
||||
</PageRoot>
|
||||
}
|
||||
/>
|
||||
<Route path={CREATE_PATH} element={<Create />} />
|
||||
<Route
|
||||
path={INBOX_PATH}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import {
|
|||
SPACE_ROOM_PATH,
|
||||
SPACE_SEARCH_PATH,
|
||||
CREATE_PATH,
|
||||
DESK_PATH,
|
||||
} from './paths';
|
||||
import { trimLeadingSlash, trimTrailingSlash } from '../utils/common';
|
||||
import { HashRouterConfig } from '../hooks/useClientConfig';
|
||||
|
|
@ -153,6 +154,9 @@ export const getExploreServerPath = (server: string): string => {
|
|||
return generatePath(EXPLORE_SERVER_PATH, params);
|
||||
};
|
||||
|
||||
export const getDeskPath = (mind: string): string =>
|
||||
generatePath(DESK_PATH, { mind: encodeURIComponent(mind) });
|
||||
|
||||
export const getCreatePath = (): string => CREATE_PATH;
|
||||
|
||||
export const getInboxPath = (): string => INBOX_PATH;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ export type ExploreServerPathSearchParams = {
|
|||
};
|
||||
export const EXPLORE_SERVER_PATH = `/explore/${_SERVER_PATH}`;
|
||||
|
||||
/** One Mind's desk: its open questions, read-only until sign-in reaches chat. */
|
||||
export const DESK_PATH = '/desk/:mind/';
|
||||
|
||||
export const CREATE_PATH = '/create';
|
||||
|
||||
export const _NOTIFICATIONS_PATH = 'notifications/';
|
||||
|
|
|
|||
30
src/preview-demo/deskForks.test.ts
Normal file
30
src/preview-demo/deskForks.test.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { buildDesk, countOpen } from '../app/features/desk/buildDesk';
|
||||
import { deskFor, setDeskSource } from '../app/features/desk/source';
|
||||
import { demoDesk } from './deskForks';
|
||||
|
||||
describe('the demo desks', () => {
|
||||
it('seed the Minds whose groups the demo has, with open forks and a settled one', () => {
|
||||
const nibu = demoDesk('nibu');
|
||||
expect(countOpen(nibu)).toBe(2);
|
||||
expect(buildDesk(nibu, Date.now()).recorded).toHaveLength(1);
|
||||
expect(countOpen(demoDesk('eureka'))).toBe(1);
|
||||
});
|
||||
it('leave other Minds unpublished, so their group shows no desk entry', () => {
|
||||
expect(demoDesk('kiko')).toBeUndefined();
|
||||
});
|
||||
it('are what the page reads once installed as the source', () => {
|
||||
setDeskSource(demoDesk);
|
||||
expect(deskFor('nibu')?.mind).toBe('nibu');
|
||||
setDeskSource(() => undefined);
|
||||
});
|
||||
it('resolve every dependency they cite, so no seeded row waits on a ghost', () => {
|
||||
const nibu = demoDesk('nibu');
|
||||
const ids = new Set(nibu?.questions.map((q) => q.fork_id));
|
||||
nibu?.questions.forEach(
|
||||
(q) =>
|
||||
'dependsOn' in q &&
|
||||
q.dependsOn.forEach((d) => d.questionId && expect(ids.has(d.questionId)).toBe(true))
|
||||
);
|
||||
});
|
||||
});
|
||||
72
src/preview-demo/deskForks.ts
Normal file
72
src/preview-demo/deskForks.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// Seeded forks for the preview's Mind desks. Invented here, public-safe: no real question, person or
|
||||
// decision. Written against the clock at the time of the call so ages and sync time stay plausible.
|
||||
import { DeskProjection, Question } from '../app/features/desk/feedback';
|
||||
|
||||
const DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
const fork = (mind: string, label: string, daysAgo: number, over: Partial<Question>): Question => ({
|
||||
fork_id: `demo:question:${label}`,
|
||||
owner: mind,
|
||||
title: label,
|
||||
body: '',
|
||||
options: [],
|
||||
dependsOn: [],
|
||||
askedAt: new Date(Date.now() - daysAgo * DAY).toISOString(),
|
||||
status: { state: 'open' },
|
||||
options_hash: `demo-${label}`,
|
||||
...over,
|
||||
});
|
||||
|
||||
const SEEDS: Record<string, (now: number) => DeskProjection> = {
|
||||
nibu: (now) => ({
|
||||
mind: 'nibu',
|
||||
syncedAt: new Date(now - 4 * 60 * 1000).toISOString(),
|
||||
questions: [
|
||||
fork('nibu', 'sky-label', 3, {
|
||||
title: 'Where should the sky label sit on a phone?',
|
||||
body: 'The label can ride the horizon or sit in the header. The horizon is prettier; the header never moves.',
|
||||
options: [
|
||||
{ id: 'horizon', text: 'On the horizon, over the ridge' },
|
||||
{ id: 'header', text: 'In the header, fixed' },
|
||||
],
|
||||
recommendation: 'header',
|
||||
}),
|
||||
fork('nibu', 'dusk-ink', 18, {
|
||||
title: 'Should the dusk ink follow the sky or the theme?',
|
||||
body: 'Names in dusk are readable either way; following the sky is livelier, following the theme is steadier.',
|
||||
options: [
|
||||
{ id: 'sky', text: 'Follow the sky' },
|
||||
{ id: 'theme', text: 'Follow the theme' },
|
||||
{ id: 'both', text: 'Sky by day, theme by night' },
|
||||
],
|
||||
recommendation: 'sky',
|
||||
dependsOn: [{ text: 'Where the sky label sits', questionId: 'demo:question:sky-label' }],
|
||||
}),
|
||||
fork('nibu', 'ridge-low-tier', 40, {
|
||||
title: 'Keep the ridge scene at the low tier?',
|
||||
status: { state: 'answered', rulingId: 'demo:ruling:ridge-low-tier' },
|
||||
}),
|
||||
],
|
||||
answers: [],
|
||||
}),
|
||||
eureka: (now) => ({
|
||||
mind: 'eureka',
|
||||
syncedAt: new Date(now - 2 * 60 * 1000).toISOString(),
|
||||
questions: [
|
||||
fork('eureka', 'settled-window', 1, {
|
||||
title: 'How long should a Mind keep a settled question on its desk?',
|
||||
body: 'Settled questions are listed as rulings. A shorter window keeps the desk light; a longer one keeps context near.',
|
||||
options: [
|
||||
{ id: '30d', text: 'Thirty days' },
|
||||
{ id: '90d', text: 'Ninety days' },
|
||||
{ id: 'always', text: 'Keep them all' },
|
||||
],
|
||||
recommendation: '30d',
|
||||
}),
|
||||
],
|
||||
answers: [],
|
||||
}),
|
||||
};
|
||||
|
||||
/** The demo's desk for a Mind, or nothing: a Mind without seeds has not published yet. */
|
||||
export const demoDesk = (mind: string): DeskProjection | undefined => SEEDS[mind]?.(Date.now());
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
// other origin is refused, so no real homeserver can be contacted while this is on.
|
||||
import { DEMO_ORIGIN } from './fixtures';
|
||||
import { createDemoServer, DemoServer } from './server';
|
||||
import { demoDesk } from './deskForks';
|
||||
import { setDeskSource } from '../app/features/desk/source';
|
||||
|
||||
export type Route = 'own' | 'demo' | 'refuse';
|
||||
|
||||
|
|
@ -80,6 +82,7 @@ export const guardedFetch =
|
|||
|
||||
export const installDemo = (win: Window & typeof globalThis = window) => {
|
||||
const server = createDemoServer();
|
||||
setDeskSource(demoDesk);
|
||||
const { origin } = win.location;
|
||||
const realFetch = win.fetch.bind(win);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue