@startsimpli/integrations 0.2.93 → 0.2.95

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.93",
3
+ "version": "0.2.95",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -98,11 +98,11 @@
98
98
  "vitest": "^3.0.0",
99
99
  "react-native": "0.85.3",
100
100
  "react-native-safe-area-context": "~5.7.0",
101
- "@startsimpli/llm": "0.4.28",
102
- "@startsimpli/ui-native": "0.1.7",
101
+ "@startsimpli/ui": "0.4.167",
103
102
  "@startsimpli/auth": "0.4.47",
104
103
  "@startsimpli/utils": "0.4.15",
105
- "@startsimpli/ui": "0.4.167"
104
+ "@startsimpli/ui-native": "0.1.7",
105
+ "@startsimpli/llm": "0.4.28"
106
106
  },
107
107
  "scripts": {
108
108
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -0,0 +1,150 @@
1
+ /**
2
+ * bd startsim-23np6.12 (title first), .13 (chevron header, friendly not-found, detail pull-to-refresh) and
3
+ * .18 (an empty workspace is not a failed search).
4
+ */
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { act, allText, hostById, maybeById, press, render, texts } from '../../../../ui-native/test/render';
7
+ import { NoteDetailScreen } from '../components/NoteDetailScreen';
8
+ import { NotesListScreen } from '../components/NotesListScreen';
9
+ import { createFakeNativeCorpusApi } from '../corpus/fake';
10
+ import { createLibraryController } from '../screens/library/controller';
11
+ import { createFakeLibraryApi } from '../screens/library/fake-library';
12
+ import { LibraryDetailScreen } from '../screens/library/LibraryDetailScreen';
13
+ import { LibraryListScreen } from '../screens/library/LibraryListScreen';
14
+ import { createTrackerController } from '../tracker/controller';
15
+ import { TrackerDetailScreen } from '../tracker/TrackerDetailScreen';
16
+ import { TrackerListScreen } from '../tracker/TrackerListScreen';
17
+ import { createVoiceNotesController } from '../voice/controller';
18
+ import { createFakeVoiceApi } from '../voice/fake';
19
+
20
+ const settle = () => act(async () => { await new Promise((res) => setTimeout(res, 0)); });
21
+ const NOW = Date.parse('2026-11-05T00:00:00Z');
22
+
23
+ async function mountTodos(opts: Parameters<typeof createFakeNativeCorpusApi>[0] = {}) {
24
+ const api = createFakeNativeCorpusApi(opts);
25
+ const controller = createTrackerController({ api, now: () => NOW });
26
+ const r = render(<TrackerListScreen controller={controller} onOpen={vi.fn()} now={() => NOW} />);
27
+ await act(async () => { await controller.start(); });
28
+ await settle();
29
+ return { r, api, controller };
30
+ }
31
+
32
+ /** The first thing the screen draws, top to bottom: the title block, then the search and filter controls. */
33
+ const firstChildTestId = (r: ReturnType<typeof render>, root: string) => {
34
+ const kids = hostById(r, root).children as Array<{ props?: { testID?: string } }>;
35
+ return kids[0]?.props?.testID;
36
+ };
37
+
38
+ describe('to-dos empty states (bd .18)', () => {
39
+ it('a workspace with no to-dos says so: no "No to-dos match", no Clear filters', async () => {
40
+ const { r } = await mountTodos({ scenario: 'empty' });
41
+ expect(allText(r)).toContain('Nothing outstanding');
42
+ expect(allText(r)).not.toContain('No to-dos match');
43
+ expect(maybeById(r, 'tracker-list-empty-clear')).toHaveLength(0);
44
+ expect(maybeById(r, 'tracker-list-clear-filters')).toHaveLength(0);
45
+ });
46
+
47
+ it('the Closed view with nothing closed says so too', async () => {
48
+ const { r, controller } = await mountTodos({ scenario: 'empty' });
49
+ await act(async () => { await controller.setView('closed'); });
50
+ expect(allText(r)).toContain('Nothing closed yet');
51
+ expect(allText(r)).not.toContain('No to-dos match');
52
+ });
53
+
54
+ it('a search that finds nothing is still "No to-dos match", with a way to clear it', async () => {
55
+ const { r } = await mountTodos();
56
+ act(() => { hostById(r, 'tracker-list-search').props.onChangeText('zzzzqq'); });
57
+ act(() => { hostById(r, 'tracker-list-search').props.onSubmitEditing(); });
58
+ await settle();
59
+ expect(allText(r)).toContain('No to-dos match');
60
+ expect(maybeById(r, 'tracker-list-empty-clear')).toHaveLength(1);
61
+ });
62
+ });
63
+
64
+ describe('screen title comes first (bd .12)', () => {
65
+ it('Notes', async () => {
66
+ const controller = createVoiceNotesController({ api: createFakeVoiceApi(), pollMs: 60_000 });
67
+ const r = render(<NotesListScreen controller={controller} onOpen={vi.fn()} />);
68
+ await settle();
69
+ expect(firstChildTestId(r, 'notes-screen')).toBe('notes-header');
70
+ expect(texts(hostById(r, 'notes-header')).join(' ')).toContain('4 notes');
71
+ });
72
+
73
+ it('To-dos', async () => {
74
+ const { r } = await mountTodos();
75
+ expect(firstChildTestId(r, 'todos-screen')).toBe('todos-header');
76
+ expect(texts(hostById(r, 'todos-header')).join(' ')).toContain('to go');
77
+ });
78
+
79
+ it('Library', async () => {
80
+ const controller = createLibraryController(createFakeLibraryApi());
81
+ const r = render(<LibraryListScreen controller={controller} onOpen={vi.fn()} />);
82
+ await act(async () => { await controller.start(); });
83
+ expect(firstChildTestId(r, 'library-screen')).toBe('library-header');
84
+ expect(texts(hostById(r, 'library-header')).join(' ')).toContain('5 documents');
85
+ });
86
+ });
87
+
88
+ describe('detail screens (bd .13)', () => {
89
+ it('the note header uses the chevron, not a text Back button', async () => {
90
+ const controller = createVoiceNotesController({ api: createFakeVoiceApi(), pollMs: 60_000 });
91
+ const onBack = vi.fn();
92
+ const r = render(<NoteDetailScreen controller={controller} noteId="n1" onBack={onBack} />);
93
+ await settle();
94
+ const back = hostById(r, 'note-back');
95
+ expect(back.props.accessibilityLabel).toBe('Back');
96
+ expect(texts(back).join('')).toBe('‹');
97
+ press(back);
98
+ expect(onBack).toHaveBeenCalled();
99
+ });
100
+
101
+ it('a note that is gone keeps the chevron header and says so', async () => {
102
+ const controller = createVoiceNotesController({ api: createFakeVoiceApi(), pollMs: 60_000 });
103
+ const r = render(<NoteDetailScreen controller={controller} noteId="nope" onBack={vi.fn()} />);
104
+ await settle();
105
+ expect(texts(hostById(r, 'note-back')).join('')).toBe('‹');
106
+ expect(allText(r)).toContain('no longer available');
107
+ });
108
+
109
+ it('a missing document says it is gone, without a raw id', async () => {
110
+ const controller = createLibraryController(createFakeLibraryApi());
111
+ const r = render(<LibraryDetailScreen controller={controller} documentId="zz9" onBack={vi.fn()} />);
112
+ await act(async () => { await controller.start(); await controller.open('zz9'); });
113
+ expect(allText(r)).toContain('no longer available');
114
+ expect(allText(r)).not.toContain('zz9');
115
+ expect(allText(r)).not.toMatch(/\(zz9\)/);
116
+ });
117
+
118
+ it('pulling down on a note re-reads the list', async () => {
119
+ const api = createFakeVoiceApi();
120
+ const listPage = vi.spyOn(api, 'listPage');
121
+ const controller = createVoiceNotesController({ api, pollMs: 60_000 });
122
+ const r = render(<NoteDetailScreen controller={controller} noteId="n1" onBack={vi.fn()} />);
123
+ await settle();
124
+ const before = listPage.mock.calls.length;
125
+ await act(async () => { await hostById(r, 'note-detail').props.refreshControl.props.onRefresh(); });
126
+ expect(listPage.mock.calls.length).toBeGreaterThan(before);
127
+ });
128
+
129
+ it('pulling down on a document re-reads it from the server', async () => {
130
+ const api = createFakeLibraryApi();
131
+ const get = vi.spyOn(api.corpus, 'getDocument');
132
+ const controller = createLibraryController(api);
133
+ const r = render(<LibraryDetailScreen controller={controller} documentId="d4" onBack={vi.fn()} />);
134
+ await act(async () => { await controller.start(); await controller.open('d4'); });
135
+ const before = get.mock.calls.length;
136
+ await act(async () => { await hostById(r, 'library-detail-scroll').props.refreshControl.props.onRefresh(); });
137
+ expect(get.mock.calls.length).toBeGreaterThan(before);
138
+ });
139
+
140
+ it('pulling down on a to-do re-reads it', async () => {
141
+ const api = createFakeNativeCorpusApi();
142
+ const r = render(<TrackerDetailScreen api={api} id="c1" onBack={vi.fn()} now={() => NOW} />);
143
+ await settle();
144
+ const reads = () => api.tenant.requests.filter((q) => q.method === 'GET' && q.path.endsWith('/entities/c1')).length;
145
+ const before = reads();
146
+ expect(before).toBeGreaterThan(0);
147
+ await act(async () => { await hostById(r, 'todo-detail').props.refreshControl.props.onRefresh(); });
148
+ expect(reads()).toBeGreaterThan(before);
149
+ });
150
+ });
@@ -1,10 +1,11 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Alert as RNAlert, ScrollView, View } from 'react-native';
3
- import { Alert, Badge, Button, Chip, Separator, Spinner, Text, useTheme } from '@startsimpli/ui-native';
3
+ import { Alert, Badge, Button, Chip, Header, Separator, Spinner, Text, useTheme } from '@startsimpli/ui-native';
4
4
  import type { VoiceFocus, VoiceNote } from '../../corpus/voice';
5
5
  import type { VoiceNotesController } from '../voice/controller';
6
6
  import { DELETE_NOTE_TITLE, deleteNoteMessage, formatDuration, formatNoteDate, statusLabel, statusVariant } from '../voice/format';
7
7
  import { noteSections, noteLead } from '../voice/sections';
8
+ import { usePullRefresh } from './usePullRefresh';
8
9
  import { useVoiceNotes } from './useVoiceNotes';
9
10
 
10
11
  export interface NoteDetailScreenProps {
@@ -33,12 +34,15 @@ export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScree
33
34
  useEffect(() => { void controller.open(noteId); }, [controller, noteId]);
34
35
  const note: VoiceNote | undefined = state.notes?.find((n) => n.id === noteId) ?? (state.opened?.id === noteId ? state.opened : undefined);
35
36
  const gap = { gap: theme.spacing.sm } as const;
37
+ const refreshControl = usePullRefresh(() => Promise.all([controller.refresh(), controller.open(noteId, { fresh: true })]));
36
38
 
37
39
  if (!note) {
38
40
  return (
39
- <View style={{ padding: theme.spacing.lg, ...gap }}>
40
- <Button title="Back" variant="ghost" size="sm" onPress={onBack} testID="note-back" />
41
- {state.notes === null || state.opening ? <Spinner /> : <Text variant="muted">This note is no longer available.</Text>}
41
+ <View style={{ flex: 1 }}>
42
+ <Header testID="note" title="Note" onBack={onBack} />
43
+ <ScrollView contentContainerStyle={{ padding: theme.spacing.lg, ...gap }} refreshControl={refreshControl} testID="note-detail">
44
+ {state.notes === null || state.opening ? <Spinner /> : <Text variant="muted">This note is no longer available. It may have been deleted.</Text>}
45
+ </ScrollView>
42
46
  </View>
43
47
  );
44
48
  }
@@ -53,8 +57,9 @@ export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScree
53
57
  const meta = [formatNoteDate(note.occurredAt), formatDuration(note.durationMs)].filter(Boolean).join(' · ');
54
58
 
55
59
  return (
56
- <ScrollView contentContainerStyle={{ padding: theme.spacing.lg, ...gap }} testID="note-detail">
57
- <Button title="Back" variant="ghost" size="sm" onPress={onBack} testID="note-back" style={{ alignSelf: 'flex-start' }} />
60
+ <View style={{ flex: 1 }}>
61
+ <Header testID="note" title="Note" onBack={onBack} />
62
+ <ScrollView contentContainerStyle={{ padding: theme.spacing.lg, ...gap }} refreshControl={refreshControl} testID="note-detail">
58
63
  <Text variant="heading">{note.title}</Text>
59
64
  <View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }}>
60
65
  <Badge label={statusLabel(note.status)} variant={statusVariant(note.status)} />
@@ -104,5 +109,6 @@ export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScree
104
109
 
105
110
  {controller.canRemove ? <Button title="Delete" variant="destructive" size="sm" onPress={confirmDelete} testID="note-delete" /> : null}
106
111
  </ScrollView>
112
+ </View>
107
113
  );
108
114
  }
@@ -1,6 +1,6 @@
1
1
  import { useState } from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
- import { Alert, Badge, DataList, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
3
+ import { Alert, Badge, DataList, Header, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
4
4
  import { UNFILED_PROJECT } from '../../corpus/filing';
5
5
  import type { VoiceNote, VoiceNoteOrder } from '../../corpus/voice';
6
6
  import type { VoiceNotesController } from '../voice/controller';
@@ -37,7 +37,11 @@ export function NotesListScreen({ controller, onOpen }: NotesListScreenProps) {
37
37
  const ignored = state.ignoredFilters.map((k) => IGNORED_NAMES[k] ?? k);
38
38
  const count = state.count;
39
39
 
40
+ const notices = ignored.length > 0 || (state.error !== null && notes !== null);
41
+
40
42
  return (
43
+ <View style={{ flex: 1 }} testID="notes-screen">
44
+ <Header testID="notes-header" title="Notes" subtitle={count !== null && canQuery ? `${count} note${count === 1 ? '' : 's'}` : undefined} />
41
45
  <DataList<VoiceNote>
42
46
  testID="notes-list"
43
47
  data={notes ?? []}
@@ -70,18 +74,17 @@ export function NotesListScreen({ controller, onOpen }: NotesListScreenProps) {
70
74
  emptyTitle="No notes yet"
71
75
  emptyDescription="Record one from the GO tab."
72
76
  noResultsTitle="No notes match"
73
- ListHeaderComponent={
77
+ ListHeaderComponent={notices ? (
74
78
  <View style={{ gap: theme.spacing.sm, paddingBottom: theme.spacing.sm }}>
75
- <Text variant="heading">Notes</Text>
76
- {count !== null && canQuery ? <Text variant="caption">{`${count} note${count === 1 ? '' : 's'}`}</Text> : null}
77
79
  {ignored.length ? (
78
80
  <Alert>{`This workspace does not ${ignored.join(', ')} yet, so the list below is not narrowed by ${ignored.length > 1 ? 'those' : 'that'}.`}</Alert>
79
81
  ) : null}
80
82
  {state.error && notes !== null ? <Alert variant="destructive">{state.error}</Alert> : null}
81
83
  </View>
82
- }
84
+ ) : undefined}
83
85
  renderItem={({ item }) => <NoteRow note={item} onPress={() => onOpen(item)} />}
84
86
  />
87
+ </View>
85
88
  );
86
89
  }
87
90
 
@@ -0,0 +1,19 @@
1
+ import { useCallback, useRef, useState, type ReactElement } from 'react';
2
+ import { RefreshControl, type RefreshControlProps } from 'react-native';
3
+ import { useTheme } from '@startsimpli/ui-native';
4
+
5
+ /**
6
+ * Pull-to-refresh for a plain ScrollView (detail screens): the spinner stays up while `reload` runs
7
+ * and always comes down, even when the reload throws. Pass the result as `refreshControl`.
8
+ */
9
+ export function usePullRefresh(reload: () => Promise<unknown> | void): ReactElement<RefreshControlProps> {
10
+ const theme = useTheme();
11
+ const [refreshing, setRefreshing] = useState(false);
12
+ const latest = useRef(reload);
13
+ latest.current = reload;
14
+ const onRefresh = useCallback(async () => {
15
+ setRefreshing(true);
16
+ try { await latest.current(); } catch { /* the controller shows its own error */ } finally { setRefreshing(false); }
17
+ }, []);
18
+ return <RefreshControl refreshing={refreshing} onRefresh={onRefresh} tintColor={theme.colors.mutedForeground} />;
19
+ }
@@ -1,11 +1,12 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { createFakeNativeCorpusApi } from '../fake';
3
3
  import { createFakeVoiceApi } from '../../voice/fake';
4
- import { readFakeScenario, withScenario } from '../fake-scenarios';
4
+ import { REFRESH_ROW_TITLE, readFakeScenario, withScenario } from '../fake-scenarios';
5
5
 
6
6
  describe('fake scenarios', () => {
7
7
  it('reads -tgFakeState; anything unknown is the normal data', () => {
8
8
  expect(readFakeScenario((k) => (k === 'tgFakeState' ? 'empty' : undefined))).toBe('empty');
9
+ expect(readFakeScenario((k) => (k === 'tgFakeState' ? 'refresh' : undefined))).toBe('refresh');
9
10
  expect(readFakeScenario(() => 'bogus')).toBe('normal');
10
11
  expect(readFakeScenario(() => undefined)).toBe('normal');
11
12
  });
@@ -29,6 +30,22 @@ describe('fake scenarios', () => {
29
30
  expect(settled).toBe('pending');
30
31
  });
31
32
 
33
+ it('refresh: normal data, but a list read a second time also returns one new row', async () => {
34
+ const voice = createFakeVoiceApi({ scenario: 'refresh' });
35
+ const first = await voice.listPage!({}, 1);
36
+ const second = await voice.listPage!({}, 1);
37
+ expect(first.notes.map((n) => n.title)).not.toContain(REFRESH_ROW_TITLE);
38
+ expect(second.notes[0].title).toBe(REFRESH_ROW_TITLE);
39
+ expect(second.count).toBe(first.count + 1);
40
+ const api = createFakeNativeCorpusApi({ scenario: 'refresh' });
41
+ const query = { type: 'source_document' };
42
+ const a = (await api.entities.list(query)).items;
43
+ const b = (await api.entities.list(query)).items;
44
+ expect(a.map((d) => d.name)).not.toContain(REFRESH_ROW_TITLE);
45
+ expect(b[0].name).toBe(REFRESH_ROW_TITLE);
46
+ expect(b).toHaveLength(a.length + 1);
47
+ });
48
+
32
49
  it('long: titles and summaries are long enough to wrap and truncate', async () => {
33
50
  const notes = await createFakeVoiceApi({ scenario: 'long' }).list();
34
51
  expect(notes.every((n) => n.title.length > 80)).toBe(true);
@@ -1,17 +1,22 @@
1
1
  /**
2
2
  * Fake-data scenarios for simulator checks and tests: the same in-memory fakes, but empty, failing, never
3
3
  * answering, or full of long text, so the empty / error / loading / long-text states of every screen can be
4
- * looked at and tested. Chosen with `-tgFakeState empty|error|loading|long`; anything else is the normal data.
4
+ * looked at and tested. Chosen with `-tgFakeState empty|error|loading|long|refresh`; anything else is the normal data.
5
+ * `refresh`: the data is normal, but every list read after the first of the same query also returns one new row
6
+ * ({@link REFRESH_ROW_TITLE}), so a test can pull to refresh and see that the screen re-read the server.
5
7
  */
6
- export type FakeScenario = 'normal' | 'empty' | 'error' | 'loading' | 'long';
8
+ export type FakeScenario = 'normal' | 'empty' | 'error' | 'loading' | 'long' | 'refresh';
7
9
 
8
- const SCENARIOS: FakeScenario[] = ['empty', 'error', 'loading', 'long'];
10
+ const SCENARIOS: FakeScenario[] = ['empty', 'error', 'loading', 'long', 'refresh'];
9
11
 
10
12
  export function readFakeScenario(get: (key: string) => unknown): FakeScenario {
11
13
  const v = String(get('tgFakeState') ?? '');
12
14
  return (SCENARIOS as string[]).includes(v) ? (v as FakeScenario) : 'normal';
13
15
  }
14
16
 
17
+ /** The row a `refresh` scenario adds to every list that is read a second time. */
18
+ export const REFRESH_ROW_TITLE = 'Added while you were away';
19
+
15
20
  const LONG_TAIL = ' - and then a much longer description that keeps going so the row has to wrap or truncate instead of fitting on one line';
16
21
 
17
22
  /** `error` rejects and `loading` never settles every function on the api; other scenarios pass it through. */
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import type { TenantEntity, TenantRelationship } from '../../corpus/entities';
12
12
  import { MAX_PAGE_SIZE } from '../../corpus/entity-query';
13
+ import { REFRESH_ROW_TITLE } from './fake-scenarios';
13
14
  import type { AuthorizedHttp } from '../voice/http';
14
15
 
15
16
  type Params = Record<string, unknown>;
@@ -21,6 +22,8 @@ export interface FakeTenantOptions {
21
22
  /** Filter names this "tenant" does not understand: reported ignored, never applied. */
22
23
  unsupported?: string[];
23
24
  onRequest?: (method: string, path: string, params: Params) => void;
25
+ /** Each entity list read a second time (same query) also returns one new row, so a refresh is visible. */
26
+ newRowOnReread?: boolean;
24
27
  }
25
28
 
26
29
  const NOT_FILTERS = new Set(['page', 'page_size', 'format']);
@@ -238,6 +241,19 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
238
241
  return { ...pageOf(rows, params, pageSize), applied_filters: applied, ignored_filters: ignored };
239
242
  }
240
243
 
244
+ const reads = new Map<string, number>();
245
+ /** `newRowOnReread`: a list query seen before gets a fresh first row, once per read. */
246
+ function reread<R extends { count: number; results: TenantEntity[] }>(params: Params, page: R): R {
247
+ if (!options.newRowOnReread || 'id' in params || 'id__in' in params || 'external_id' in params || 'external_id__in' in params) return page;
248
+ const key = JSON.stringify(params);
249
+ const seen = (reads.get(key) ?? 0) + 1;
250
+ reads.set(key, seen);
251
+ const first = page.results[0];
252
+ if (seen < 2 || !first) return page;
253
+ const added = { ...first, id: `${first.id}-fresh`, name: REFRESH_ROW_TITLE, data: { ...dataOf(first), title: REFRESH_ROW_TITLE } };
254
+ return { ...page, count: page.count + 1, results: [added, ...page.results] };
255
+ }
256
+
241
257
  const http: AuthorizedHttp = {
242
258
  async get<T>(path: string, init?: { params?: Params }): Promise<T> {
243
259
  const params = init?.params ?? {};
@@ -246,7 +262,7 @@ export function createFakeTenantHttp(options: FakeTenantOptions = {}): FakeTenan
246
262
  const p = path.replace(/^\/+|\/+$/g, '');
247
263
  if (p === 'api/v1/relationships') return edges(params) as T;
248
264
  if (p === 'api/v1/entities/facets') return facets(params) as T;
249
- if (p === 'api/v1/entities') return list(params) as T;
265
+ if (p === 'api/v1/entities') return reread(params, list(params)) as T;
250
266
  const detail = /^api\/v1\/entities\/(.+)$/.exec(p);
251
267
  if (detail) {
252
268
  const found = entities.find((e) => String(e.id) === decodeURIComponent(detail[1]));
@@ -27,6 +27,7 @@ export function createFakeNativeCorpusApi(options: FakeTenantOptions & { scenari
27
27
  const tenant = createFakeTenantHttp({
28
28
  entities: scenario === 'empty' ? [] : scenario === 'long' ? sampleTenantEntities().map(lengthen) : sampleTenantEntities(),
29
29
  relationships: scenario === 'empty' ? [] : sampleTenantRelationships(),
30
+ ...(scenario === 'refresh' ? { newRowOnReread: true } : {}),
30
31
  ...tenantOptions,
31
32
  });
32
33
  const base = createNativeCorpusApi({ http: withScenario(tenant.http, scenario), scope: { orgId: 'tandem' } });
@@ -118,13 +118,14 @@ describe('library controller: open a document', () => {
118
118
  expect(requests.some((r) => r.path === 'api/v1/entities/d5')).toBe(true);
119
119
  });
120
120
 
121
- it('names the id when it is gone', async () => {
121
+ it('says it is gone in words, never the raw id', async () => {
122
122
  const { controller } = setup();
123
123
  await controller.start();
124
124
  await controller.open('nope');
125
125
  const sel = controller.getState().selected!;
126
126
  expect(sel.document).toBeNull();
127
- expect(sel.error).toContain('nope');
127
+ expect(sel.error).toContain('no longer available');
128
+ expect(sel.error).not.toContain('nope');
128
129
  });
129
130
 
130
131
  it('close() clears it', async () => {
@@ -125,9 +125,10 @@ describe('LibraryDetailScreen', () => {
125
125
  expect(controller.getState().filings.d5).toEqual([]);
126
126
  });
127
127
 
128
- it('a record that is gone says which one, with a way back', async () => {
128
+ it('a record that is gone says so in words (no raw id), with a way back', async () => {
129
129
  const { r, onBack } = await mountDetail('nope');
130
- expect(allText(r)).toContain('nope');
130
+ expect(allText(r)).toContain('no longer available');
131
+ expect(allText(r)).not.toContain('nope');
131
132
  press(hostById(r, 'library-detail-back'));
132
133
  expect(onBack).toHaveBeenCalled();
133
134
  });
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
2
2
  import { ScrollView, View } from 'react-native';
3
3
  import { Alert, Badge, Header, Markdown, Select, Separator, Spinner, Text, useTheme } from '@startsimpli/ui-native';
4
4
  import { formatDate, fullTextOf, summaryOf } from '../../../components/documentText';
5
+ import { usePullRefresh } from '../../components/usePullRefresh';
5
6
  import { useControllerState as useStore } from '../../components/useControllerState';
6
7
  import type { LibraryController } from './controller';
7
8
 
@@ -19,14 +20,15 @@ export function LibraryDetailScreen({ controller, documentId, onBack }: LibraryD
19
20
  useEffect(() => { void controller.start(); void controller.open(documentId); }, [controller, documentId]);
20
21
  const open = s.selected?.id === documentId ? s.selected : null;
21
22
  const document = open?.document ?? null;
23
+ const refreshControl = usePullRefresh(() => Promise.all([controller.refresh(), controller.open(documentId, { fresh: true })]));
22
24
 
23
25
  if (!document) {
24
26
  return (
25
27
  <View style={{ flex: 1 }}>
26
28
  <Header testID="library-detail" title="Document" onBack={onBack} />
27
- <View style={{ padding: theme.spacing.lg, gap: theme.spacing.md }}>
29
+ <ScrollView testID="library-detail-scroll" refreshControl={refreshControl} contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md }}>
28
30
  {open?.error ? <Alert variant="destructive">{open.error}</Alert> : <Spinner />}
29
- </View>
31
+ </ScrollView>
30
32
  </View>
31
33
  );
32
34
  }
@@ -40,7 +42,7 @@ export function LibraryDetailScreen({ controller, documentId, onBack }: LibraryD
40
42
  return (
41
43
  <View style={{ flex: 1 }}>
42
44
  <Header testID="library-detail" title={document.title} subtitle={document.sourceLabel || document.source} onBack={onBack} />
43
- <ScrollView contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.lg }} keyboardShouldPersistTaps="handled">
45
+ <ScrollView testID="library-detail-scroll" refreshControl={refreshControl} contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.lg }} keyboardShouldPersistTaps="handled">
44
46
  <View style={gap}>
45
47
  <Text variant="heading">{document.title}</Text>
46
48
  <View style={{ flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: theme.spacing.sm }}>
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
- import { Alert, Badge, DataList, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
3
+ import { Alert, Badge, DataList, Header, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
4
4
  import { documentPreview } from '../../../corpus/view-text';
5
5
  import { formatDate } from '../../../components/documentText';
6
6
  import type { SourceDocument } from '../../../corpus/types';
@@ -31,6 +31,8 @@ export function LibraryListScreen({ controller, onOpen }: LibraryListScreenProps
31
31
  const count = s.list.count;
32
32
 
33
33
  return (
34
+ <View style={{ flex: 1 }} testID="library-screen">
35
+ <Header testID="library-header" title="Library" subtitle={count !== null ? `${count} document${count === 1 ? '' : 's'}` : undefined} />
34
36
  <DataList<SourceDocument>
35
37
  testID="library-list"
36
38
  data={s.list.items}
@@ -58,17 +60,14 @@ export function LibraryListScreen({ controller, onOpen }: LibraryListScreenProps
58
60
  emptyTitle="No documents yet"
59
61
  emptyDescription="Notes, meetings and files you connect appear here."
60
62
  noResultsTitle="Nothing matches"
61
- ListHeaderComponent={
62
- <View style={{ gap: theme.spacing.sm, paddingBottom: theme.spacing.sm }}>
63
- <Text variant="heading">Library</Text>
64
- {count !== null ? <Text variant="caption">{`${count} document${count === 1 ? '' : 's'}`}</Text> : null}
65
- {ignored.length ? (
66
- <Alert>{`This workspace does not filter by ${ignored.join(', ')} yet, so the list below is not narrowed by ${ignored.length > 1 ? 'those' : 'that'}.`}</Alert>
67
- ) : null}
63
+ ListHeaderComponent={ignored.length ? (
64
+ <View style={{ paddingBottom: theme.spacing.sm }}>
65
+ <Alert>{`This workspace does not filter by ${ignored.join(', ')} yet, so the list below is not narrowed by ${ignored.length > 1 ? 'those' : 'that'}.`}</Alert>
68
66
  </View>
69
- }
67
+ ) : undefined}
70
68
  renderItem={({ item }) => <DocumentRow document={item} filings={s.filings[item.id]} onPress={() => onOpen(item.id)} />}
71
69
  />
70
+ </View>
72
71
  );
73
72
  }
74
73
 
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import { ABOUT_FOCUS, type DocumentFiling } from '../../../corpus/filing';
9
9
  import type { DocumentQuery, SourceDocument } from '../../../corpus/types';
10
- import { openFailureMessage } from '../../../corpus/view-text';
11
10
  import type { NativeCorpusApi } from '../../corpus/api';
12
11
  import type { PagedList, PagedListState } from '../../corpus/paged';
13
12
  import type { Store } from '../../components/useControllerState';
@@ -47,13 +46,20 @@ export interface LibraryController extends Store<LibraryState> {
47
46
  clearFilters(): Promise<void>;
48
47
  refresh(): Promise<void>;
49
48
  loadMore(): Promise<void>;
50
- open(id: string): Promise<void>;
49
+ /** Show one document. `fresh` re-reads it from the server even when the list already holds it (pull to refresh). */
50
+ open(id: string, options?: { fresh?: boolean }): Promise<void>;
51
51
  close(): void;
52
52
  /** Move a document to another project (`null` = unfiled). */
53
53
  fileUnder(documentId: string, projectId: string | null): Promise<void>;
54
54
  }
55
55
 
56
56
  export const EMPTY_FILTERS: LibraryFilters = { search: '', source: null, subtype: null, project: null, order: 'recent' };
57
+ /** What the detail screen says when a document cannot be opened: words, never the raw id. */
58
+ function documentOpenFailure(e: unknown): string {
59
+ if ((e as { status?: number } | null)?.status === 404) return 'This document is no longer available. It may have been removed, or it may not be one you can see.';
60
+ const reason = e instanceof Error ? e.message : '';
61
+ return reason || 'This document could not be opened.';
62
+ }
57
63
  const UNREADABLE_PROJECT = 'A project you cannot open';
58
64
 
59
65
  const humanize = (value: string) => {
@@ -153,10 +159,11 @@ export function createLibraryController(api: NativeCorpusApi, options: { pageSiz
153
159
  async refresh() { await paged.refresh(); await afterList(); },
154
160
  async loadMore() { await paged.loadMore(); await afterList(); },
155
161
 
156
- async open(id) {
157
- const onPage = paged.getState().items.find((d) => d.id === id);
162
+ async open(id, { fresh = false } = {}) {
163
+ const onPage = fresh ? undefined : paged.getState().items.find((d) => d.id === id);
158
164
  if (onPage) { store.set({ selected: { id, document: onPage, loading: false, error: null } }); void loadFilings([id]); return; }
159
- store.set({ selected: { id, document: null, loading: true, error: null } });
165
+ const shown = fresh ? store.getState().selected : null;
166
+ store.set({ selected: shown?.id === id ? { ...shown, loading: true, error: null } : { id, document: null, loading: true, error: null } });
160
167
  try {
161
168
  const document = await api.corpus.getDocument(id);
162
169
  if (store.getState().selected?.id !== id) return;
@@ -164,7 +171,7 @@ export function createLibraryController(api: NativeCorpusApi, options: { pageSiz
164
171
  await loadFilings([id]);
165
172
  } catch (e) {
166
173
  if (store.getState().selected?.id !== id) return;
167
- store.set({ selected: { id, document: null, loading: false, error: openFailureMessage(e, id) } });
174
+ store.set({ selected: { id, document: null, loading: false, error: documentOpenFailure(e) } });
168
175
  }
169
176
  },
170
177
  close() { store.set({ selected: null }); },
@@ -2,6 +2,7 @@ import { useEffect, useMemo } from 'react';
2
2
  import { ScrollView, View } from 'react-native';
3
3
  import { Alert, Button, Card, CardContent, Header, Spinner, StatusChip, Text, useTheme } from '@startsimpli/ui-native';
4
4
  import type { NativeCorpusApi } from '../corpus/api';
5
+ import { usePullRefresh } from '../components/usePullRefresh';
5
6
  import { useControllerState } from '../components/useControllerState';
6
7
  import { createTrackerDetailController } from './detail';
7
8
  import { formatDue, isOverdueAt, priorityText } from './format';
@@ -24,14 +25,15 @@ export function TrackerDetailScreen({ api, id, onBack, onOpenNote, onChanged, no
24
25
  useEffect(() => { void controller.load(); }, [controller]);
25
26
  const s = useControllerState(controller);
26
27
  const item = s.item;
28
+ const refreshControl = usePullRefresh(() => controller.load());
27
29
 
28
30
  if (!item) {
29
31
  return (
30
32
  <View style={{ flex: 1 }}>
31
33
  <Header title="To-do" onBack={onBack} testID="todo-header" />
32
- <View style={{ padding: theme.spacing.lg }}>
34
+ <ScrollView testID="todo-detail" refreshControl={refreshControl} contentContainerStyle={{ padding: theme.spacing.lg }}>
33
35
  {s.loading ? <Spinner /> : <Alert variant="destructive">{s.error ?? 'This to-do is no longer available.'}</Alert>}
34
- </View>
36
+ </ScrollView>
35
37
  </View>
36
38
  );
37
39
  }
@@ -48,7 +50,7 @@ export function TrackerDetailScreen({ api, id, onBack, onOpenNote, onChanged, no
48
50
  return (
49
51
  <View style={{ flex: 1 }}>
50
52
  <Header title="To-do" onBack={onBack} testID="todo-header" />
51
- <ScrollView testID="todo-detail" contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md }}>
53
+ <ScrollView testID="todo-detail" refreshControl={refreshControl} contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md }}>
52
54
  <Text variant="heading">{item.title}</Text>
53
55
  <View style={{ flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm }}>
54
56
  <StatusChip status={item.status} />
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { View } from 'react-native';
3
- import { DataList, ListRow, StatusChip, SwipeRow, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
3
+ import { DataList, Header, ListRow, StatusChip, SwipeRow, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
4
4
  import { UNFILED_PROJECT } from '../../corpus/filing';
5
5
  import type { Commitment } from '../../corpus/types';
6
6
  import { useControllerState } from '../components/useControllerState';
@@ -14,6 +14,14 @@ export interface TrackerListScreenProps {
14
14
  now?: () => number;
15
15
  }
16
16
 
17
+ /** What an empty list says per view. Reached only when no project or search narrows it (those read "No to-dos match"). */
18
+ const EMPTY: Record<TrackerView, { title: string; description: string }> = {
19
+ open: { title: 'Nothing outstanding', description: 'To-dos from your notes and meetings show up here.' },
20
+ overdue: { title: 'Nothing overdue', description: 'To-dos past their due date show up here.' },
21
+ recent: { title: 'Nothing changed this week', description: 'To-dos that moved in the last 7 days show up here.' },
22
+ closed: { title: 'Nothing closed yet', description: 'Finished to-dos show up here.' },
23
+ };
24
+
17
25
  /**
18
26
  * To-dos: server-driven. View (Outstanding / Overdue / Changed this week /
19
27
  * Closed), project and search are all query parameters; swipe a row to mark it
@@ -28,7 +36,7 @@ export function TrackerListScreen({ controller, onOpen, now = Date.now }: Tracke
28
36
  const titleOf = (focusId: string | null) => state.projects.find((p) => p.id === focusId)?.title;
29
37
  const closed = state.filters.view === 'closed';
30
38
  const filters: FilterGroup[] = [
31
- { key: 'view', label: 'Show', options: TRACKER_VIEWS, value: state.filters.view },
39
+ { key: 'view', label: 'Show', view: true, options: TRACKER_VIEWS, value: state.filters.view },
32
40
  { key: 'project', label: 'Project', display: 'select', options: [{ value: UNFILED_PROJECT, label: 'Unfiled' }, ...state.projects.map((p) => ({ value: p.id, label: p.title }))], value: state.filters.focusId },
33
41
  ];
34
42
  const isFiltered = state.filters.focusId !== null || state.filters.search.trim() !== '';
@@ -49,7 +57,11 @@ export function TrackerListScreen({ controller, onOpen, now = Date.now }: Tracke
49
57
  </SwipeRow>
50
58
  );
51
59
 
60
+ const subtitle = state.count !== null ? `${state.count} ${closed ? 'closed' : 'to go'}${isFiltered ? ' (filtered)' : ''}` : undefined;
61
+
52
62
  return (
63
+ <View style={{ flex: 1 }} testID="todos-screen">
64
+ <Header testID="todos-header" title="To-dos" subtitle={subtitle} />
53
65
  <DataList<TrackerRow>
54
66
  testID="tracker-list"
55
67
  data={state.rows}
@@ -71,16 +83,15 @@ export function TrackerListScreen({ controller, onOpen, now = Date.now }: Tracke
71
83
  else void controller.setFocus(value);
72
84
  }}
73
85
  onClearFilters={() => { setText(''); void controller.clearFilters(); }}
74
- emptyTitle={closed ? 'Nothing closed yet' : 'Nothing outstanding'}
75
- emptyDescription={closed ? 'Finished to-dos show up here.' : 'To-dos from your notes and meetings show up here.'}
86
+ emptyTitle={EMPTY[state.filters.view].title}
87
+ emptyDescription={EMPTY[state.filters.view].description}
76
88
  noResultsTitle="No to-dos match"
77
- ListHeaderComponent={
78
- <View style={{ gap: theme.spacing.xs, paddingBottom: theme.spacing.sm }}>
79
- <Text variant="heading">To-dos</Text>
80
- {state.count !== null ? <Text variant="caption">{state.count} {closed ? 'closed' : 'to go'}{isFiltered ? ' (filtered)' : ''}</Text> : null}
81
- {state.ignoredFilters.length ? <Text variant="caption" style={{ color: theme.colors.destructive }}>This workspace did not apply: {state.ignoredFilters.join(', ')}. The list is not filtered by it.</Text> : null}
89
+ ListHeaderComponent={state.ignoredFilters.length ? (
90
+ <View style={{ paddingBottom: theme.spacing.sm }}>
91
+ <Text variant="caption" style={{ color: theme.colors.destructive }}>This workspace did not apply: {state.ignoredFilters.join(', ')}. The list is not filtered by it.</Text>
82
92
  </View>
83
- }
93
+ ) : undefined}
84
94
  />
95
+ </View>
85
96
  );
86
97
  }
@@ -52,7 +52,7 @@ export interface VoiceNotesController {
52
52
  /** Append the next page (no-op when there is none or one is already loading). */
53
53
  loadMore(): Promise<void>;
54
54
  /** Make a note available to a detail screen even when it is not on a loaded page. */
55
- open(noteId: string): Promise<void>;
55
+ open(noteId: string, options?: { fresh?: boolean }): Promise<void>;
56
56
  file(noteId: string, focusId: string | null): Promise<void>;
57
57
  fileSection(noteId: string, sectionIndex: number, focusId: string | null): Promise<void>;
58
58
  retry(noteId: string): Promise<void>;
@@ -220,11 +220,11 @@ export function createVoiceNotesController(options: VoiceNotesControllerOptions)
220
220
  }
221
221
  },
222
222
 
223
- async open(noteId) {
223
+ async open(noteId, { fresh = false } = {}) {
224
224
  openRequest = noteId;
225
225
  const loaded = state.notes?.find((n) => n.id === noteId);
226
226
  if (loaded) { set({ opened: null, opening: false }); return; }
227
- if (state.opened?.id === noteId || !api.listPage) return;
227
+ if ((state.opened?.id === noteId && !fresh) || !api.listPage) return;
228
228
  set({ opening: true });
229
229
  try {
230
230
  const page = await api.listPage({ ids: [noteId] }, 1);
@@ -3,7 +3,7 @@
3
3
  * network or a tenant. Notes include every state (processing, ready, failed)
4
4
  * and both shapes (with sections, without).
5
5
  */
6
- import { longText, withScenario, type FakeScenario } from '../corpus/fake-scenarios';
6
+ import { REFRESH_ROW_TITLE, longText, withScenario, type FakeScenario } from '../corpus/fake-scenarios';
7
7
  import type { VoiceFocus, VoiceNote, VoiceNotesApi } from '../../corpus/voice';
8
8
 
9
9
  export function sampleVoiceNotes(now = new Date('2026-11-03T15:00:00Z')): VoiceNote[] {
@@ -72,6 +72,15 @@ function createInMemoryVoiceApi(options: FakeVoiceApiOptions): VoiceNotesApi {
72
72
  return seen > polls ? finish(n) : n;
73
73
  });
74
74
  };
75
+ const listed = new Map<string, number>();
76
+ /** `refresh` scenario: a query listed before gets one new note on top, so a pull to refresh is visible. */
77
+ const withNewest = (query: unknown, rows: VoiceNote[]): VoiceNote[] => {
78
+ if (options.scenario !== 'refresh' || !rows.length) return rows;
79
+ const key = JSON.stringify(query);
80
+ const seen = (listed.get(key) ?? 0) + 1;
81
+ listed.set(key, seen);
82
+ return seen < 2 ? rows : [{ ...rows[0], id: `${rows[0].id}-fresh`, title: REFRESH_ROW_TITLE }, ...rows];
83
+ };
75
84
  const at = (n: VoiceNote) => (n.occurredAt ? Date.parse(n.occurredAt) : 0);
76
85
  return {
77
86
  async submit() { throw new Error('The fake api does not record.'); },
@@ -91,6 +100,7 @@ function createInMemoryVoiceApi(options: FakeVoiceApiOptions): VoiceNotesApi {
91
100
  const order = unsupported.has('order') ? 'recent' : query.order ?? 'recent';
92
101
  const hits = (n: VoiceNote) => hay(n).split(term).length - 1;
93
102
  rows = [...rows].sort((a, b) => (order === 'oldest' ? at(a) - at(b) : order === 'relevance' && term ? hits(b) - hits(a) || at(b) - at(a) : at(b) - at(a)));
103
+ if (page === 1 && !query.ids?.length) rows = withNewest(query, rows);
94
104
  const start = (page - 1) * pageSize;
95
105
  return {
96
106
  notes: rows.slice(start, start + pageSize).map((n) => ({ ...n })),