@startsimpli/integrations 0.2.158 → 0.2.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/__tests__/briefing-weekly.test.ts +80 -0
- package/src/__tests__/corpus-ask-items.test.ts +108 -0
- package/src/__tests__/corpus-planning.test.tsx +31 -0
- package/src/__tests__/home-brief.test.tsx +10 -0
- package/src/__tests__/home-needs-your-call.test.tsx +68 -0
- package/src/__tests__/measure/notes.ts +28 -0
- package/src/__tests__/measure/voice-notes.measure.test.ts +51 -0
- package/src/__tests__/needs-your-call.test.tsx +151 -0
- package/src/__tests__/question-evidence.test.ts +82 -0
- package/src/__tests__/question-inbox.test.ts +51 -0
- package/src/__tests__/question-voice.test.ts +18 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/AskPage.tsx +12 -2
- package/src/components/pages/PlanningPage.tsx +14 -4
- package/src/components/pages/home/BriefCard.tsx +31 -12
- package/src/components/pages/home/CompactItemRow.tsx +12 -2
- package/src/components/pages/home/DueAcrossProjects.tsx +4 -2
- package/src/components/pages/home/HomeBriefPage.tsx +32 -3
- package/src/components/pages/questions/NeedsYourCall.tsx +128 -0
- package/src/components/pages/questions/QuestionRow.tsx +78 -0
- package/src/components/pages/questions/index.ts +3 -0
- package/src/components/pages/questions/types.ts +36 -0
- package/src/corpus/ask-items-intent.ts +75 -0
- package/src/corpus/ask-items.ts +100 -0
- package/src/corpus/ask.ts +48 -5
- package/src/corpus/briefing/generate-weekly.ts +89 -0
- package/src/corpus/briefing/index.ts +5 -1
- package/src/corpus/briefing/respond.ts +11 -3
- package/src/corpus/briefing/types.ts +2 -0
- package/src/corpus/briefing/weekly.ts +155 -0
- package/src/corpus/index.ts +3 -0
- package/src/corpus/llm.ts +3 -2
- package/src/corpus/questions/evidence.ts +65 -0
- package/src/corpus/questions/inbox.ts +108 -0
- package/src/corpus/questions/index.ts +6 -1
- package/src/corpus/questions/items.ts +21 -0
- package/src/corpus/questions/learn.ts +16 -0
- package/src/corpus/questions/sync.ts +7 -3
- package/src/corpus/questions/types.ts +5 -1
- package/src/corpus/questions/voice.ts +23 -4
- package/src/corpus/types.ts +4 -0
- package/src/corpus/voice.ts +5 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
// @vitest-environment node
|
|
3
|
+
/** Resolving from the corpus before asking (bd startsim-tmrvi.2): other items, Linear, calendar. */
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { guessOf, unknownGuess } from '../corpus/extraction-fields';
|
|
7
|
+
import { listOpenQuestions, syncOpenQuestions } from '../corpus/questions';
|
|
8
|
+
import { decideFromCorpus } from '../corpus/questions/evidence';
|
|
9
|
+
import type { ItemView } from '../corpus/questions/types';
|
|
10
|
+
import { tenant } from './helpers/question-tenant';
|
|
11
|
+
|
|
12
|
+
const view = (id: string, title: string, over: Partial<ItemView> = {}): ItemView => ({
|
|
13
|
+
id, title, status: 'open', dueAt: null, focusId: '', ownerName: '', ownerSub: '', openKind: '', openText: '', ...over,
|
|
14
|
+
});
|
|
15
|
+
const me = view('me', 'Newsletter draft for November launch');
|
|
16
|
+
|
|
17
|
+
describe('decideFromCorpus', () => {
|
|
18
|
+
it('settles a project when two similar to-dos from other places already live there', () => {
|
|
19
|
+
const items = [me, view('a', 'Newsletter draft November', { focusId: 'mkt' }), view('b', 'Launch newsletter outline', { focusId: 'mkt', linearKey: 'MKT-4' })];
|
|
20
|
+
const hit = decideFromCorpus({ kind: 'project', item: me, assumed: { value: 'mkt' } }, { items, events: [] });
|
|
21
|
+
expect(hit).toMatchObject({ agrees: true, source: 'linear' });
|
|
22
|
+
expect(hit?.evidence).toContain('MKT-4');
|
|
23
|
+
});
|
|
24
|
+
it('asks when one similar item lives elsewhere, or there is only one', () => {
|
|
25
|
+
const a = view('a', 'Newsletter draft November', { focusId: 'mkt' });
|
|
26
|
+
const b = view('b', 'Launch newsletter outline', { focusId: 'ops' });
|
|
27
|
+
expect(decideFromCorpus({ kind: 'project', item: me, assumed: { value: 'mkt' } }, { items: [me, a, b], events: [] })).toBeNull();
|
|
28
|
+
expect(decideFromCorpus({ kind: 'project', item: me, assumed: { value: 'mkt' } }, { items: [me, a], events: [] })).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
it('one shared word is not similar', () => {
|
|
31
|
+
const items = [me, view('a', 'Newsletter budget', { focusId: 'mkt' }), view('b', 'Newsletter vendors', { focusId: 'mkt' })];
|
|
32
|
+
expect(decideFromCorpus({ kind: 'project', item: me, assumed: { value: 'mkt' } }, { items, events: [] })).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
it('settles a due date from a calendar event that day, never a different day', () => {
|
|
35
|
+
const ev = [{ title: 'Newsletter send', date: '2026-11-20' }];
|
|
36
|
+
expect(decideFromCorpus({ kind: 'due_date', item: me, assumed: { value: '2026-11-20' } }, { items: [me], events: ev })).toMatchObject({ source: 'calendar' });
|
|
37
|
+
expect(decideFromCorpus({ kind: 'due_date', item: me, assumed: { value: '2026-11-21' } }, { items: [me], events: ev })).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
it('settles a due date from a similar Linear issue due that day', () => {
|
|
40
|
+
const lin = view('l', 'Newsletter draft November copy', { linearKey: 'MKT-9', dueAt: '2026-11-18' });
|
|
41
|
+
expect(decideFromCorpus({ kind: 'due_date', item: me, assumed: { value: '2026-11-18' } }, { items: [me, lin], events: [] })).toMatchObject({ source: 'linear' });
|
|
42
|
+
expect(decideFromCorpus({ kind: 'due_date', item: me, assumed: { value: '2026-11-19' } }, { items: [me, lin], events: [] })).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const item = (id: string, data: Record<string, unknown>) => ({
|
|
47
|
+
id, entity_type: 'commitment', external_id: `commit:${id}`, name: String(data.title),
|
|
48
|
+
data: { status: 'open', mentions: [{ document_id: 'note1', quote: 'q' }], ...data },
|
|
49
|
+
});
|
|
50
|
+
describe('sync uses corpus evidence', () => {
|
|
51
|
+
it('does not ask, and records the evidence found', async () => {
|
|
52
|
+
const fields = { due: unknownGuess('x'), project: guessOf('mkt', 0.4, 'assumed', 'r', { question: 'Which project?' }), owner: unknownGuess('x'), priority: unknownGuess('x'), estimate: unknownGuess('x') };
|
|
53
|
+
const t = tenant([
|
|
54
|
+
item('a', { title: 'Newsletter draft November', external_focus_id: 'mkt' }),
|
|
55
|
+
item('b', { title: 'Launch newsletter outline', external_focus_id: 'mkt' }),
|
|
56
|
+
item('c', { title: 'Newsletter draft for November launch', external_focus_id: 'mkt' }),
|
|
57
|
+
{ id: 'note1', entity_type: 'source_document', external_id: 'voice:n1', name: 'n', data: { source: 'voice', title: 'n', voice_items: JSON.stringify([{ section: 's', title: 'Newsletter draft for November launch', fields }]) } },
|
|
58
|
+
]);
|
|
59
|
+
const deps = { http: t.http, scope: { orgId: 'o' } as never, ownerSub: 'me', now: () => Date.parse('2026-11-04T15:00:00Z'), timeZone: 'UTC' };
|
|
60
|
+
const counts = await syncOpenQuestions(deps);
|
|
61
|
+
expect(counts).toMatchObject({ opened: 0, decidedByContext: 1 });
|
|
62
|
+
const all = await listOpenQuestions(deps, { status: 'all' });
|
|
63
|
+
expect(all[0]).toMatchObject({ resolution: 'context' });
|
|
64
|
+
expect(all[0]?.answer?.label).toMatch(/^found: 2 similar/);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
import { habitHints } from '../corpus/questions/learn';
|
|
69
|
+
import { renderVoicePrompt } from '../corpus/llm';
|
|
70
|
+
|
|
71
|
+
describe('habits as extraction hints', () => {
|
|
72
|
+
const pref = (key: string, value: string, count = 2, conflicts = 0) => ({ kind: 'project_word' as const, key, value, count, conflicts });
|
|
73
|
+
it('hints only confident habits for projects that still exist', () => {
|
|
74
|
+
const lines = habitHints([pref('newsletter', 'f-mkt'), pref('invoice', 'f-ops', 1), pref('rota', 'gone')], [{ id: 'f-mkt', title: 'Marketing' }, { id: 'f-ops', title: 'Operations' }]);
|
|
75
|
+
expect(lines).toEqual(['- to-dos about newsletter usually go to f-mkt (Marketing)']);
|
|
76
|
+
});
|
|
77
|
+
it('shows them to the model as a hint, and not at all when there are none', () => {
|
|
78
|
+
const base = { transcript: 'hi', focuses: [{ id: 'f-mkt', title: 'Marketing' }] };
|
|
79
|
+
expect(renderVoicePrompt({ ...base, habits: ['- to-dos about newsletter usually go to f-mkt (Marketing)'] })).toContain('HABITS');
|
|
80
|
+
expect(renderVoicePrompt(base)).not.toContain('HABITS');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { applyAnswerToItem, assumedLabel, chipsFor, formatAnswerValue, readTypedAnswer } from '../corpus/questions';
|
|
4
|
+
import type { OpenQuestion } from '../corpus/questions';
|
|
5
|
+
|
|
6
|
+
const base: OpenQuestion = {
|
|
7
|
+
id: 'q', itemId: 'i1', kind: 'project', question: 'Which project?', status: 'open', candidates: [], score: 1, ownerSub: 'u', createdAt: '', updatedAt: '',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('question inbox helpers', () => {
|
|
11
|
+
it('puts the assumed value first, names ids, and never repeats a value', () => {
|
|
12
|
+
const q = { ...base, assumed: { value: 'f1', confidence: 0.4, reason: 'said so' }, candidates: [{ value: 'f1', confidence: 1, reason: '' }, { value: 'f2', confidence: 0.2, reason: '' }] };
|
|
13
|
+
const chips = chipsFor(q, { labels: { f1: 'Launch', f2: 'Ops' } });
|
|
14
|
+
expect(chips.map((c) => [c.label, c.assumed])).toEqual([['Launch', true], ['Ops', false]]);
|
|
15
|
+
expect(assumedLabel(q, { labels: { f1: 'Launch' } })).toBe('Launch');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('caps the chips', () => {
|
|
19
|
+
const q = { ...base, candidates: ['a', 'b', 'c', 'd', 'e'].map((value) => ({ value, confidence: 0.1, reason: '' })) };
|
|
20
|
+
expect(chipsFor(q)).toHaveLength(4);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('formats a date and an empty date', () => {
|
|
24
|
+
expect(formatAnswerValue({ kind: 'due_date' }, '2026-11-13')).toMatch(/Nov/);
|
|
25
|
+
expect(formatAnswerValue({ kind: 'due_date' }, '')).toBe('No date');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('turns typed words into an answer, a skip, or a question back', () => {
|
|
29
|
+
const due = { ...base, kind: 'due_date' as const };
|
|
30
|
+
const ctx = { now: Date.parse('2026-11-06T17:00:00Z'), timeZone: 'UTC' };
|
|
31
|
+
expect(readTypedAnswer(due, 'tomorrow', ctx)).toEqual({ kind: 'answer', answer: { value: '2026-11-07' } });
|
|
32
|
+
expect(readTypedAnswer(due, 'skip', ctx)).toEqual({ kind: 'skip' });
|
|
33
|
+
expect(readTypedAnswer(due, 'purple', ctx).kind).toBe('unclear');
|
|
34
|
+
expect(readTypedAnswer({ ...base, assumed: { value: 'f1', confidence: 0.5, reason: '' } }, 'yes', ctx)).toEqual({ kind: 'answer', answer: { value: 'f1' } });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('applies an answer only to its own to-do', () => {
|
|
38
|
+
const items = [{ id: 'i1', dueAt: '2026-11-13' }, { id: 'i2', dueAt: '2026-11-13' }];
|
|
39
|
+
const out = items.map((i) => applyAnswerToItem(i, { kind: 'due_date', itemId: 'i1' }, { value: '' }));
|
|
40
|
+
expect(out).toEqual([{ id: 'i1', dueAt: null }, { id: 'i2', dueAt: '2026-11-13' }]);
|
|
41
|
+
expect(applyAnswerToItem({ id: 'i1', focusId: 'a' }, { kind: 'project', itemId: 'i1' }, { value: 'b' }).focusId).toBe('b');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('server-supplied options', () => {
|
|
46
|
+
it('names chips from the options a listing carries, and offers them when there are no candidates', () => {
|
|
47
|
+
const q: OpenQuestion = { ...base, kind: 'team', options: [{ value: 't1', label: 'Platform' }, { value: 't2', label: 'Growth' }] };
|
|
48
|
+
expect(chipsFor(q).map((c) => c.label)).toEqual(['Platform', 'Growth']);
|
|
49
|
+
expect(formatAnswerValue(q, 't2')).toBe('Growth');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -148,6 +148,24 @@ describe('answerQuestionByVoice', () => {
|
|
|
148
148
|
expect(await listOpenQuestions(deps)).toHaveLength(1);
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
+
it('undo puts a project back and reopens the question', async () => {
|
|
152
|
+
const rows = [
|
|
153
|
+
item('deck', { title: 'Finish the deck', external_focus_id: 'f-mkt' }),
|
|
154
|
+
note([{ section: 's', title: 'Finish the deck', fields: fields({
|
|
155
|
+
project: guessOf('f-mkt', 0.5, 'assumed', 'by topic', { question: 'Which project is the deck for?' }),
|
|
156
|
+
}) }]),
|
|
157
|
+
];
|
|
158
|
+
const { t, deps } = setup(rows, { options: async (q) => (q.kind === 'project' ? [{ value: 'f-mkt', label: 'Marketing' }, { value: 'f-eng', label: 'Engineering' }] : []) });
|
|
159
|
+
await syncOpenQuestions(deps);
|
|
160
|
+
await say(deps, 'engineering');
|
|
161
|
+
expect(t.rows.get('deck')!.data.external_focus_id).toBe('f-eng');
|
|
162
|
+
const out = await say(deps, 'undo that');
|
|
163
|
+
expect(out.kind).toBe('undone');
|
|
164
|
+
expect(t.rows.get('deck')!.data.external_focus_id).toBe('f-mkt');
|
|
165
|
+
expect(deps.fileItem).toHaveBeenLastCalledWith('deck', 'f-mkt');
|
|
166
|
+
expect(await listOpenQuestions(deps)).toHaveLength(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
151
169
|
it('says plainly when an answer cannot be undone by voice', async () => {
|
|
152
170
|
const { deps } = setup([held('bench', "Order dad's bench")]);
|
|
153
171
|
await syncOpenQuestions(deps);
|
package/src/components/index.ts
CHANGED
|
@@ -72,4 +72,5 @@ export * from './pages/VoiceNotesPage';
|
|
|
72
72
|
export { VoiceRecordButton, VOICE_MIME_CANDIDATES } from './pages/VoiceRecordButton';
|
|
73
73
|
export type { VoiceRecordButtonProps, VoiceRecordClassNames } from './pages/VoiceRecordButton';
|
|
74
74
|
export * from './pages/home';
|
|
75
|
+
export * from './pages/questions';
|
|
75
76
|
export * from './pages/task-tracker/OwnerPicker';
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import * as React from 'react';
|
|
33
33
|
|
|
34
|
+
import { itemIdOf } from '../../corpus/ask-items';
|
|
34
35
|
import { Markdown, stripMarkdown } from '../Markdown';
|
|
35
36
|
import {
|
|
36
37
|
UNCITED_NOTICE, askFailureMessage as failureMessage, droppedNotice, freshnessNotice,
|
|
@@ -50,6 +51,8 @@ export interface AskPageProps {
|
|
|
50
51
|
scope: CorpusScope;
|
|
51
52
|
/** Click-through from a citation to the record, normally the Library route. */
|
|
52
53
|
onOpenDocument?: (documentId: string) => void;
|
|
54
|
+
/** Click-through from a cited TRACKED ITEM (an `item:` record) to the item, by its external id. */
|
|
55
|
+
onOpenItem?: (itemId: string) => void;
|
|
53
56
|
/** Prefill, e.g. from a `?q=` param. */
|
|
54
57
|
initialQuestion?: string;
|
|
55
58
|
initialMode?: AskMode;
|
|
@@ -102,6 +105,7 @@ export function AskPage({
|
|
|
102
105
|
api,
|
|
103
106
|
scope,
|
|
104
107
|
onOpenDocument,
|
|
108
|
+
onOpenItem,
|
|
105
109
|
initialQuestion = '',
|
|
106
110
|
initialMode = 'ask',
|
|
107
111
|
listProjects,
|
|
@@ -230,6 +234,7 @@ export function AskPage({
|
|
|
230
234
|
result={result}
|
|
231
235
|
classNames={cn}
|
|
232
236
|
onOpenDocument={onOpenDocument}
|
|
237
|
+
onOpenItem={onOpenItem}
|
|
233
238
|
canSave={canSave}
|
|
234
239
|
saveState={saveState}
|
|
235
240
|
onSave={async () => {
|
|
@@ -257,11 +262,12 @@ export function AskPage({
|
|
|
257
262
|
// ---------------------------------------------------------------------------
|
|
258
263
|
|
|
259
264
|
function AnswerPanel({
|
|
260
|
-
result, classNames: cn, onOpenDocument, canSave, saveState, onSave,
|
|
265
|
+
result, classNames: cn, onOpenDocument, onOpenItem, canSave, saveState, onSave,
|
|
261
266
|
}: {
|
|
262
267
|
result: AskResult;
|
|
263
268
|
classNames: Record<AskSlot, string>;
|
|
264
269
|
onOpenDocument?: (documentId: string) => void;
|
|
270
|
+
onOpenItem?: (itemId: string) => void;
|
|
265
271
|
canSave: boolean;
|
|
266
272
|
saveState: 'idle' | 'saving' | 'saved';
|
|
267
273
|
onSave: () => void;
|
|
@@ -327,7 +333,11 @@ function AnswerPanel({
|
|
|
327
333
|
<button
|
|
328
334
|
type="button"
|
|
329
335
|
className="text-sm font-medium text-blue-700 underline"
|
|
330
|
-
onClick={() =>
|
|
336
|
+
onClick={() => {
|
|
337
|
+
const itemId = itemIdOf(citation.documentId);
|
|
338
|
+
if (itemId) onOpenItem?.(itemId);
|
|
339
|
+
else onOpenDocument?.(citation.documentId);
|
|
340
|
+
}}
|
|
331
341
|
>
|
|
332
342
|
{citation.document.title}
|
|
333
343
|
</button>
|
|
@@ -158,6 +158,7 @@ export function PlanningPage({
|
|
|
158
158
|
const [applied, setApplied] = React.useState<string[]>([]);
|
|
159
159
|
const [members, setMembers] = React.useState<Array<{ sub: string; email: string; name?: string }>>([]);
|
|
160
160
|
const [showDone, setShowDone] = React.useState(false);
|
|
161
|
+
const triedClosed = React.useRef<Record<string, boolean>>({});
|
|
161
162
|
const [owner, setOwner] = React.useState('');
|
|
162
163
|
const [loadingFocuses, setLoadingFocuses] = React.useState(true);
|
|
163
164
|
const [loadingItems, setLoadingItems] = React.useState(false);
|
|
@@ -211,7 +212,7 @@ export function PlanningPage({
|
|
|
211
212
|
// -- items ---------------------------------------------------------------
|
|
212
213
|
|
|
213
214
|
const itemQuery = React.useMemo<CommitmentQuery>(() => ({
|
|
214
|
-
status: showDone ? 'done' : (['open', 'in_progress', 'blocked'] as CommitmentStatus[]),
|
|
215
|
+
status: showDone ? (['done', 'dropped'] as CommitmentStatus[]) : (['open', 'in_progress', 'blocked'] as CommitmentStatus[]),
|
|
215
216
|
...(owner.trim() ? { owner: owner.trim() } : {}),
|
|
216
217
|
...(selected ? { focus: selected } : {}),
|
|
217
218
|
// Each row names its project, and filing is an edge the entity row lacks.
|
|
@@ -234,6 +235,15 @@ export function PlanningPage({
|
|
|
234
235
|
return () => { live = false; };
|
|
235
236
|
}, [itemQuery, scope.orgId, epoch]);
|
|
236
237
|
|
|
238
|
+
// A project whose work is all finished (an imported tracker's history) would open on
|
|
239
|
+
// "Nothing is filed under this focus yet". Show the closed items once instead.
|
|
240
|
+
React.useEffect(() => {
|
|
241
|
+
if (!selected || loadingItems || showDone || items.length > 0) return;
|
|
242
|
+
if (triedClosed.current[selected]) return;
|
|
243
|
+
triedClosed.current[selected] = true;
|
|
244
|
+
setShowDone(true);
|
|
245
|
+
}, [selected, loadingItems, showDone, items.length]);
|
|
246
|
+
|
|
237
247
|
React.useEffect(() => {
|
|
238
248
|
let live = true;
|
|
239
249
|
if (!api.listMembers) return undefined;
|
|
@@ -254,7 +264,7 @@ export function PlanningPage({
|
|
|
254
264
|
const visible = React.useMemo(() => {
|
|
255
265
|
const wanted = showDone
|
|
256
266
|
? (item: Commitment) => item.status === 'done' || item.status === 'dropped'
|
|
257
|
-
: (item: Commitment) => item.status === 'open' || item.status === 'blocked';
|
|
267
|
+
: (item: Commitment) => item.status === 'open' || item.status === 'in_progress' || item.status === 'blocked';
|
|
258
268
|
const byOwner = owner.trim().toLowerCase();
|
|
259
269
|
return items
|
|
260
270
|
.filter(wanted)
|
|
@@ -373,7 +383,7 @@ export function PlanningPage({
|
|
|
373
383
|
<div className={cn.root}>
|
|
374
384
|
<section className={cn.section} aria-label="Focus">
|
|
375
385
|
<div className="flex flex-wrap items-center gap-2">
|
|
376
|
-
<button type="button" className={cn.secondaryButton} onClick={() => setSelected(null)}>
|
|
386
|
+
<button type="button" className={cn.secondaryButton} onClick={() => { setSelected(null); setShowDone(false); }}>
|
|
377
387
|
← All focuses
|
|
378
388
|
</button>
|
|
379
389
|
{warningChip}
|
|
@@ -383,7 +393,7 @@ export function PlanningPage({
|
|
|
383
393
|
standing={standings[selectedFocus.id] ?? null}
|
|
384
394
|
selected
|
|
385
395
|
classNames={cn}
|
|
386
|
-
onSelect={() => setSelected(null)}
|
|
396
|
+
onSelect={() => { setSelected(null); setShowDone(false); }}
|
|
387
397
|
/>
|
|
388
398
|
<FocusProgressHistory focus={selectedFocus} api={api} />
|
|
389
399
|
{error ? <p className={cn.error} role="alert">{error}</p> : null}
|
|
@@ -11,19 +11,35 @@ import * as React from 'react';
|
|
|
11
11
|
|
|
12
12
|
import type { BriefingResult } from '../../../corpus/briefing';
|
|
13
13
|
|
|
14
|
+
/** What the card shows: the daily briefing's result or the weekly summary's. */
|
|
15
|
+
export type BriefCardResult = Pick<BriefingResult, 'text' | 'audioUrl'> & { audioReason?: string; remaining?: number };
|
|
16
|
+
|
|
14
17
|
export interface BriefCardApi {
|
|
15
18
|
/** POST /corpus/briefing: cached per person per day on the server. */
|
|
16
|
-
fetch(): Promise<
|
|
19
|
+
fetch(): Promise<BriefCardResult>;
|
|
17
20
|
/** An object URL (or any playable URL) for the briefing's audio, fetched with the caller's credentials. */
|
|
18
|
-
loadAudio?(result:
|
|
21
|
+
loadAudio?(result: BriefCardResult): Promise<string | null>;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
type State =
|
|
24
|
+
type State =
|
|
25
|
+
| { phase: 'idle' }
|
|
26
|
+
| { phase: 'loading' }
|
|
27
|
+
| { phase: 'error'; message: string }
|
|
28
|
+
| { phase: 'ready'; result: BriefCardResult };
|
|
29
|
+
|
|
30
|
+
export interface BriefCardProps {
|
|
31
|
+
api: BriefCardApi;
|
|
32
|
+
onAsk?: () => void;
|
|
33
|
+
/** Heading, default "Today’s brief". */
|
|
34
|
+
title?: string;
|
|
35
|
+
/** Wait for a tap instead of loading on mount (the weekly summary: it costs a voice the first time). */
|
|
36
|
+
onDemand?: boolean;
|
|
37
|
+
}
|
|
22
38
|
|
|
23
|
-
export function BriefCard({ api, onAsk
|
|
39
|
+
export function BriefCard({ api, onAsk, title = 'Today’s brief', onDemand = false }: BriefCardProps) {
|
|
24
40
|
const apiRef = React.useRef(api);
|
|
25
41
|
apiRef.current = api;
|
|
26
|
-
const [state, setState] = React.useState<State>({ phase: 'loading' });
|
|
42
|
+
const [state, setState] = React.useState<State>(onDemand ? { phase: 'idle' } : { phase: 'loading' });
|
|
27
43
|
const [playing, setPlaying] = React.useState(false);
|
|
28
44
|
const [audioError, setAudioError] = React.useState('');
|
|
29
45
|
const audio = React.useRef<HTMLAudioElement | null>(null);
|
|
@@ -33,16 +49,16 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
33
49
|
try { setState({ phase: 'ready', result: await apiRef.current.fetch() }); }
|
|
34
50
|
catch (err) { setState({ phase: 'error', message: (err as Error)?.message || 'The brief could not be loaded.' }); }
|
|
35
51
|
}, []);
|
|
36
|
-
React.useEffect(() => { void load(); }, [load]);
|
|
52
|
+
React.useEffect(() => { if (!onDemand) void load(); }, [load, onDemand]);
|
|
37
53
|
React.useEffect(() => () => { audio.current?.pause(); }, []);
|
|
38
54
|
|
|
39
|
-
const play = async (result:
|
|
55
|
+
const play = async (result: BriefCardResult) => {
|
|
40
56
|
setAudioError('');
|
|
41
57
|
if (playing) { audio.current?.pause(); setPlaying(false); return; }
|
|
42
58
|
try {
|
|
43
59
|
if (!audio.current) {
|
|
44
60
|
const url = await apiRef.current.loadAudio?.(result);
|
|
45
|
-
if (!url) { setAudioError(result.audioReason || 'There is no audio for
|
|
61
|
+
if (!url) { setAudioError(result.audioReason || 'There is no audio for this one.'); return; }
|
|
46
62
|
const el = new Audio(url);
|
|
47
63
|
el.onended = () => setPlaying(false);
|
|
48
64
|
el.onpause = () => setPlaying(false);
|
|
@@ -54,9 +70,9 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
54
70
|
};
|
|
55
71
|
|
|
56
72
|
return (
|
|
57
|
-
<section aria-label=
|
|
73
|
+
<section aria-label={title} className="rounded-lg border border-gray-200 bg-white p-4 shadow-sm" data-testid="brief-card">
|
|
58
74
|
<div className="flex items-center gap-2">
|
|
59
|
-
<h2 className="text-sm font-semibold uppercase tracking-wide text-gray-500">
|
|
75
|
+
<h2 className="text-sm font-semibold uppercase tracking-wide text-gray-500">{title}</h2>
|
|
60
76
|
<div className="ml-auto flex items-center gap-2">
|
|
61
77
|
{state.phase === 'ready' && apiRef.current.loadAudio ? (
|
|
62
78
|
<button type="button" className="rounded-md bg-gray-900 px-3 py-1.5 text-sm font-medium text-white" onClick={() => void play(state.result)}>
|
|
@@ -66,7 +82,10 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
66
82
|
{onAsk ? <button type="button" className="rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-800" onClick={onAsk}>Ask</button> : null}
|
|
67
83
|
</div>
|
|
68
84
|
</div>
|
|
69
|
-
{state.phase === '
|
|
85
|
+
{state.phase === 'idle' ? (
|
|
86
|
+
<p className="mt-3"><button type="button" className="rounded-md bg-gray-900 px-3 py-1.5 text-sm font-medium text-white" onClick={() => void load()}>Show {title.toLowerCase()}</button></p>
|
|
87
|
+
) : null}
|
|
88
|
+
{state.phase === 'loading' ? <p className="mt-3 text-sm text-gray-500">Putting it together…</p> : null}
|
|
70
89
|
{state.phase === 'error' ? (
|
|
71
90
|
<p className="mt-3 text-sm text-red-600" role="alert">
|
|
72
91
|
{state.message} <button type="button" className="underline" onClick={() => void load()}>Try again</button>
|
|
@@ -75,7 +94,7 @@ export function BriefCard({ api, onAsk }: { api: BriefCardApi; onAsk?: () => voi
|
|
|
75
94
|
{state.phase === 'ready' ? (
|
|
76
95
|
<>
|
|
77
96
|
<p className="mt-3 whitespace-pre-line text-base leading-relaxed text-gray-900" data-testid="brief-text">{state.result.text}</p>
|
|
78
|
-
{state.result.remaining > 0 ? <p className="mt-2 text-xs text-gray-500">{state.result.remaining} more not read out.</p> : null}
|
|
97
|
+
{(state.result.remaining ?? 0) > 0 ? <p className="mt-2 text-xs text-gray-500">{state.result.remaining} more not read out.</p> : null}
|
|
79
98
|
</>
|
|
80
99
|
) : null}
|
|
81
100
|
{audioError ? <p className="mt-2 text-xs text-amber-800" role="status">{audioError}</p> : null}
|
|
@@ -33,11 +33,13 @@ export interface CompactItemRowProps {
|
|
|
33
33
|
actions?: React.ReactNode;
|
|
34
34
|
/** Show the status word for items that are not plainly open. Default true. */
|
|
35
35
|
showStatus?: boolean;
|
|
36
|
+
/** The due date is Tandem's guess, not confirmed: drawn lighter, never as a warning. */
|
|
37
|
+
guessedDue?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
const CHIP = 'inline-flex max-w-[14rem] items-center truncate rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-xs text-gray-700';
|
|
39
41
|
|
|
40
|
-
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true }: CompactItemRowProps) {
|
|
42
|
+
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true, guessedDue }: CompactItemRowProps) {
|
|
41
43
|
const late = days !== null && days < 0 && item.status !== 'done';
|
|
42
44
|
const label = dueLabel(days, due);
|
|
43
45
|
return (
|
|
@@ -56,7 +58,15 @@ export function CompactItemRow({ item, days, due, project, trackerName, onOpen,
|
|
|
56
58
|
{project ? <span className={CHIP} title={project}>{project}</span> : null}
|
|
57
59
|
{showStatus && item.status !== 'open' && item.status !== 'done' ? <span className={CHIP} title={item.statusReason || undefined}>{item.status.replace('_', ' ')}</span> : null}
|
|
58
60
|
{item.sync ? <ExternalLinkChip sync={item.sync} trackerName={trackerName} className={CHIP} /> : null}
|
|
59
|
-
{label ?
|
|
61
|
+
{label ? (
|
|
62
|
+
<span
|
|
63
|
+
className={`w-16 text-right text-xs ${guessedDue ? 'italic text-gray-500' : late ? 'font-semibold text-red-700' : 'text-gray-500'}`}
|
|
64
|
+
title={guessedDue ? 'Tandem’s guess: confirm it under Needs your call' : undefined}
|
|
65
|
+
data-guess={guessedDue ? 'true' : undefined}
|
|
66
|
+
>
|
|
67
|
+
{guessedDue ? `~${label}` : label}
|
|
68
|
+
</span>
|
|
69
|
+
) : null}
|
|
60
70
|
{actions}
|
|
61
71
|
</div>
|
|
62
72
|
</li>
|
|
@@ -13,7 +13,7 @@ import { CompactItemRow } from './CompactItemRow';
|
|
|
13
13
|
const TONE: Record<string, string> = { overdue: 'text-red-700', today: 'text-gray-900', week: 'text-gray-900', later: 'text-gray-500' };
|
|
14
14
|
|
|
15
15
|
export function DueAcrossProjects({
|
|
16
|
-
due, projectNames = {}, perGroup = 6, trackerName, onOpen, onSeeAll,
|
|
16
|
+
due, projectNames = {}, perGroup = 6, trackerName, onOpen, onSeeAll, guessed,
|
|
17
17
|
}: {
|
|
18
18
|
due: DueGroups;
|
|
19
19
|
projectNames?: Record<string, string>;
|
|
@@ -22,6 +22,8 @@ export function DueAcrossProjects({
|
|
|
22
22
|
onOpen?: (item: Commitment) => void;
|
|
23
23
|
/** "Open the Tracker" — shown when there is more than the home lists. */
|
|
24
24
|
onSeeAll?: () => void;
|
|
25
|
+
/** Items whose date is still Tandem's guess: shown quietly. */
|
|
26
|
+
guessed?: ReadonlySet<string>;
|
|
25
27
|
}) {
|
|
26
28
|
const [open, setOpen] = React.useState<Record<string, boolean>>({});
|
|
27
29
|
if (due.total === 0) {
|
|
@@ -50,7 +52,7 @@ export function DueAcrossProjects({
|
|
|
50
52
|
key={entry.item.externalId}
|
|
51
53
|
item={entry.item} days={entry.days} due={entry.due}
|
|
52
54
|
project={entry.item.focusId ? projectNames[entry.item.focusId] : undefined}
|
|
53
|
-
trackerName={trackerName} onOpen={onOpen}
|
|
55
|
+
trackerName={trackerName} onOpen={onOpen} guessedDue={guessed?.has(entry.item.id)}
|
|
54
56
|
/>
|
|
55
57
|
))}
|
|
56
58
|
</ul>
|
|
@@ -17,6 +17,9 @@ import { isTask } from '../../../corpus/tracker-groups';
|
|
|
17
17
|
import { actionsByNote } from '../../../corpus/note-actions';
|
|
18
18
|
import { failureMessage } from '../../../corpus/work-item-logic';
|
|
19
19
|
import type { Commitment, CommitmentApi, CorpusApi, Focus, PlanningApi } from '../../../corpus/types';
|
|
20
|
+
import { applyAnswerToItem, type OpenQuestion, type QuestionAnswer } from '../../../corpus/questions';
|
|
21
|
+
import { NeedsYourCall } from '../questions/NeedsYourCall';
|
|
22
|
+
import type { NeedsYourCallApi } from '../questions/types';
|
|
20
23
|
import { BriefCard, type BriefCardApi } from './BriefCard';
|
|
21
24
|
import { DueAcrossProjects } from './DueAcrossProjects';
|
|
22
25
|
import { RecentNotes, type RecentNote } from './RecentNotes';
|
|
@@ -26,6 +29,8 @@ const DAY = 86_400_000;
|
|
|
26
29
|
|
|
27
30
|
export interface HomeBriefPageProps {
|
|
28
31
|
brief: BriefCardApi;
|
|
32
|
+
/** The weekly summary, shown on demand under the daily brief. Absent = no weekly card. */
|
|
33
|
+
weekly?: BriefCardApi;
|
|
29
34
|
corpus: CorpusApi & CommitmentApi;
|
|
30
35
|
/** Names the project chips. Absent = no chips. */
|
|
31
36
|
listFocuses?: PlanningApi['listFocuses'];
|
|
@@ -38,6 +43,8 @@ export interface HomeBriefPageProps {
|
|
|
38
43
|
onOpenItem?: (item: Commitment) => void;
|
|
39
44
|
/** How many recent notes to list. Default 6. */
|
|
40
45
|
noteCount?: number;
|
|
46
|
+
/** Tandem's open questions ("Needs your call"). Absent = no such section. */
|
|
47
|
+
questions?: NeedsYourCallApi;
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
interface Data { open: Commitment[]; recent: Commitment[]; notes: RecentNote[]; names: Record<string, string> }
|
|
@@ -52,7 +59,7 @@ function Section({ title, children }: { title: string; children: React.ReactNode
|
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export function HomeBriefPage({
|
|
55
|
-
brief, corpus, listFocuses, timeZone, now, trackerName, onAsk, onOpenTracker, onOpenNote, onOpenItem, noteCount = 6,
|
|
62
|
+
brief, weekly, corpus, listFocuses, timeZone, now, trackerName, onAsk, onOpenTracker, onOpenNote, onOpenItem, noteCount = 6, questions,
|
|
56
63
|
}: HomeBriefPageProps) {
|
|
57
64
|
// Frozen once: a clock that changes every render re-fires the load effect.
|
|
58
65
|
const [mountedAt] = React.useState(() => Date.now());
|
|
@@ -91,15 +98,37 @@ export function HomeBriefPage({
|
|
|
91
98
|
return () => { live = false; };
|
|
92
99
|
}, [clock, noteCount, corpus]);
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
// An answer shows on its to-do the moment it is tapped; a failed save drops it again.
|
|
102
|
+
const [applied, setApplied] = React.useState<Record<string, { q: OpenQuestion; answer: QuestionAnswer }>>({});
|
|
103
|
+
const [guessed, setGuessed] = React.useState<ReadonlySet<string>>(new Set());
|
|
104
|
+
const due = React.useMemo(() => {
|
|
105
|
+
if (!data) return null;
|
|
106
|
+
const answers = Object.values(applied);
|
|
107
|
+
const open = answers.length ? data.open.map((item) => answers.reduce((cur, { q, answer }) => applyAnswerToItem(cur, q, answer), item)) : data.open;
|
|
108
|
+
return groupDue(open.filter(isTask), { now: clock, timeZone });
|
|
109
|
+
}, [data, applied, clock, timeZone]);
|
|
110
|
+
const titles = React.useMemo(() => new Map((data ? [...data.open, ...data.recent] : []).map((i) => [i.id, i.title])), [data]);
|
|
111
|
+
const onOpenQuestions = React.useCallback((open: OpenQuestion[]) => {
|
|
112
|
+
setGuessed(new Set(open.filter((q) => q.kind === 'due_date' && q.assumed?.value).map((q) => q.itemId)));
|
|
113
|
+
}, []);
|
|
95
114
|
|
|
96
115
|
return (
|
|
97
116
|
<div className="space-y-8">
|
|
98
117
|
<BriefCard api={brief} onAsk={onAsk} />
|
|
118
|
+
{weekly ? <BriefCard api={weekly} title="Your week" onDemand /> : null}
|
|
99
119
|
{error ? <p className="text-sm text-red-600" role="alert">{error}</p> : null}
|
|
120
|
+
{questions ? (
|
|
121
|
+
<NeedsYourCall
|
|
122
|
+
api={questions} itemTitle={(id) => titles.get(id)} projectNames={data?.names} timeZone={timeZone} now={now}
|
|
123
|
+
onOpenQuestions={onOpenQuestions}
|
|
124
|
+
onApplied={(q, answer) => setApplied((a) => ({ ...a, [q.id]: { q, answer } }))}
|
|
125
|
+
onReverted={(q) => setApplied(({ [q.id]: _gone, ...rest }) => rest)}
|
|
126
|
+
onOpenItem={onOpenItem ? (id) => { const item = data?.open.find((i) => i.id === id) ?? data?.recent.find((i) => i.id === id); if (item) onOpenItem(item); } : undefined}
|
|
127
|
+
/>
|
|
128
|
+
) : null}
|
|
100
129
|
<Section title="Due across projects">
|
|
101
130
|
{due && data ? (
|
|
102
|
-
<DueAcrossProjects due={due} projectNames={data.names} trackerName={trackerName} onOpen={onOpenItem} onSeeAll={onOpenTracker} />
|
|
131
|
+
<DueAcrossProjects due={due} projectNames={data.names} guessed={guessed} trackerName={trackerName} onOpen={onOpenItem} onSeeAll={onOpenTracker} />
|
|
103
132
|
) : error ? null : <p className="text-sm text-gray-500">Loading…</p>}
|
|
104
133
|
</Section>
|
|
105
134
|
<Section title="Recent notes">
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEEDS YOUR CALL — Tandem's open clarifying questions on Home (bd startsim-tmrvi.7).
|
|
3
|
+
*
|
|
4
|
+
* Best first, a few at a time. A tap on a chip answers: the row leaves at once and
|
|
5
|
+
* the to-do it was about shows the new value (`onApplied`), then the answer is saved
|
|
6
|
+
* by the host's `api`; if that fails the row comes back where it was and the
|
|
7
|
+
* to-do is put back (`onReverted`). Writes happen in the click handlers, never in an effect.
|
|
8
|
+
* Nothing is kept past this component: the list is the caller's own, so it is
|
|
9
|
+
* re-read for whoever is signed in, never shared or cached across people.
|
|
10
|
+
*/
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
|
|
13
|
+
import { failureMessage } from '../../../corpus/work-item-logic';
|
|
14
|
+
import type { AnswerOption, OpenQuestion, QuestionAnswer } from '../../../corpus/questions';
|
|
15
|
+
import { QuestionRow } from './QuestionRow';
|
|
16
|
+
import type { NeedsYourCallProps } from './types';
|
|
17
|
+
|
|
18
|
+
type Phase = { name: 'loading' } | { name: 'error'; message: string } | { name: 'ready' };
|
|
19
|
+
|
|
20
|
+
const byScore = (a: OpenQuestion, b: OpenQuestion) => b.score - a.score;
|
|
21
|
+
|
|
22
|
+
export function NeedsYourCall({
|
|
23
|
+
api, itemTitle, projectNames, options, timeZone, now, pageSize = 5, onApplied, onReverted, onOpenQuestions, onOpenItem,
|
|
24
|
+
}: NeedsYourCallProps) {
|
|
25
|
+
const apiRef = React.useRef(api);
|
|
26
|
+
apiRef.current = api;
|
|
27
|
+
const [mountedAt] = React.useState(() => Date.now());
|
|
28
|
+
const [phase, setPhase] = React.useState<Phase>({ name: 'loading' });
|
|
29
|
+
const [questions, setQuestions] = React.useState<OpenQuestion[]>([]);
|
|
30
|
+
const [shown, setShown] = React.useState(pageSize);
|
|
31
|
+
const [notice, setNotice] = React.useState<{ tone: 'ok' | 'bad'; text: string } | null>(null);
|
|
32
|
+
const [extra, setExtra] = React.useState<Record<string, AnswerOption[]>>({});
|
|
33
|
+
const asked = React.useRef(new Set<string>());
|
|
34
|
+
const optionsRef = React.useRef(options);
|
|
35
|
+
optionsRef.current = options;
|
|
36
|
+
const onOpenRef = React.useRef(onOpenQuestions);
|
|
37
|
+
onOpenRef.current = onOpenQuestions;
|
|
38
|
+
|
|
39
|
+
const load = React.useCallback(async () => {
|
|
40
|
+
setPhase({ name: 'loading' });
|
|
41
|
+
setQuestions([]);
|
|
42
|
+
setExtra({});
|
|
43
|
+
asked.current = new Set();
|
|
44
|
+
try {
|
|
45
|
+
setQuestions((await apiRef.current.list()).filter((q) => q.status === 'open').sort(byScore));
|
|
46
|
+
setPhase({ name: 'ready' });
|
|
47
|
+
} catch (err) {
|
|
48
|
+
setPhase({ name: 'error', message: failureMessage(err) });
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
React.useEffect(() => { void load(); }, [load, api]);
|
|
52
|
+
React.useEffect(() => { onOpenRef.current?.(questions); }, [questions]);
|
|
53
|
+
|
|
54
|
+
// Choices for team / owner questions the host can name; read once per question.
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
const read = optionsRef.current;
|
|
57
|
+
if (!read) return;
|
|
58
|
+
for (const q of questions.slice(0, shown)) {
|
|
59
|
+
if (q.kind === 'due_date' || asked.current.has(q.id)) continue;
|
|
60
|
+
asked.current.add(q.id);
|
|
61
|
+
read(q).then((list) => setExtra((e) => ({ ...e, [q.id]: list }))).catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
}, [questions, shown]);
|
|
64
|
+
|
|
65
|
+
const settle = async (q: OpenQuestion, save: () => Promise<void>, revert: boolean) => {
|
|
66
|
+
const at = questions.findIndex((x) => x.id === q.id);
|
|
67
|
+
setQuestions((list) => list.filter((x) => x.id !== q.id));
|
|
68
|
+
setNotice(null);
|
|
69
|
+
try {
|
|
70
|
+
await save();
|
|
71
|
+
setNotice({ tone: 'ok', text: 'Saved.' });
|
|
72
|
+
} catch {
|
|
73
|
+
if (revert) onReverted?.(q);
|
|
74
|
+
setQuestions((list) => {
|
|
75
|
+
if (list.some((x) => x.id === q.id)) return list;
|
|
76
|
+
const next = [...list];
|
|
77
|
+
next.splice(Math.min(at < 0 ? next.length : at, next.length), 0, q);
|
|
78
|
+
return next;
|
|
79
|
+
});
|
|
80
|
+
setNotice({ tone: 'bad', text: 'That did not save. It is back in your list; try again.' });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const answer = (q: OpenQuestion, a: QuestionAnswer) => {
|
|
85
|
+
onApplied?.(q, a);
|
|
86
|
+
void settle(q, () => apiRef.current.answer(q, a), true);
|
|
87
|
+
};
|
|
88
|
+
const skip = (q: OpenQuestion) => { void settle(q, () => apiRef.current.skip(q), false); };
|
|
89
|
+
|
|
90
|
+
const labelsFor = (q: OpenQuestion) => ({
|
|
91
|
+
labels: projectNames, timeZone, options: extra[q.id] ?? q.options,
|
|
92
|
+
});
|
|
93
|
+
const visible = questions.slice(0, shown);
|
|
94
|
+
const clock = now ?? mountedAt;
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<section aria-labelledby="needs-your-call-title" className="space-y-3" data-testid="needs-your-call">
|
|
98
|
+
<h2 id="needs-your-call-title" className="flex items-baseline gap-2 text-lg font-semibold text-gray-900">
|
|
99
|
+
Needs your call
|
|
100
|
+
{phase.name === 'ready' && questions.length ? <span className="text-xs font-normal text-gray-500">{questions.length}</span> : null}
|
|
101
|
+
</h2>
|
|
102
|
+
<p className="sr-only" role="status" aria-live="polite">{notice?.tone === 'ok' ? notice.text : ''}</p>
|
|
103
|
+
{notice?.tone === 'bad' ? <p className="text-sm text-gray-700" role="alert">{notice.text}</p> : null}
|
|
104
|
+
{phase.name === 'loading' ? <p className="text-sm text-gray-500">Loading…</p> : null}
|
|
105
|
+
{phase.name === 'error' ? (
|
|
106
|
+
<p className="text-sm text-gray-600">
|
|
107
|
+
{phase.message} <button type="button" className="text-blue-700 underline" onClick={() => void load()}>Try again</button>
|
|
108
|
+
</p>
|
|
109
|
+
) : null}
|
|
110
|
+
{phase.name === 'ready' && questions.length === 0 ? <p className="text-sm text-gray-500">Nothing needs your call.</p> : null}
|
|
111
|
+
{phase.name === 'ready' && visible.length ? (
|
|
112
|
+
<ul>
|
|
113
|
+
{visible.map((q) => (
|
|
114
|
+
<QuestionRow
|
|
115
|
+
key={q.id} question={q} title={itemTitle?.(q.itemId) || 'A to-do'} chipContext={labelsFor(q)} now={clock}
|
|
116
|
+
onAnswer={answer} onSkip={skip} onOpenItem={onOpenItem}
|
|
117
|
+
/>
|
|
118
|
+
))}
|
|
119
|
+
</ul>
|
|
120
|
+
) : null}
|
|
121
|
+
{phase.name === 'ready' && questions.length > visible.length ? (
|
|
122
|
+
<button type="button" className="text-sm text-blue-700 underline" onClick={() => setShown(shown + pageSize)}>
|
|
123
|
+
Show {Math.min(pageSize, questions.length - visible.length)} more
|
|
124
|
+
</button>
|
|
125
|
+
) : null}
|
|
126
|
+
</section>
|
|
127
|
+
);
|
|
128
|
+
}
|