@marktiderman/genesis-ui-native 3.5.1 → 3.7.0
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/README.md +115 -7
- package/dist/{chunk-ONH2PCGH.js → chunk-3KFUS7O6.js} +9 -15
- package/dist/chunk-3KFUS7O6.js.map +1 -0
- package/dist/{chunk-LBVD7XXL.js → chunk-7NDKIIOT.js} +627 -20
- package/dist/chunk-7NDKIIOT.js.map +1 -0
- package/dist/chunk-CAI7LGN6.js +39 -0
- package/dist/chunk-CAI7LGN6.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-GBNIBHSU.js} +198 -168
- package/dist/chunk-GBNIBHSU.js.map +1 -0
- package/dist/chunk-IXC3LO2K.js +410 -0
- package/dist/chunk-IXC3LO2K.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-KH2RVAI5.js} +174 -93
- package/dist/chunk-KH2RVAI5.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-O4BMDV7I.js} +110 -17
- package/dist/chunk-O4BMDV7I.js.map +1 -0
- package/dist/chunk-RTYO24SC.js +105 -0
- package/dist/chunk-RTYO24SC.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-YWDDDYDI.js} +4 -3
- package/dist/chunk-YWDDDYDI.js.map +1 -0
- package/dist/components/index.d.ts +382 -10
- package/dist/components/index.js +6 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +231 -30
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +90 -2
- package/dist/hooks/index.js +3 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +7 -1
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
- package/dist/index.d.ts +8 -5
- package/dist/index.js +9 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +6 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-DEJJQhDx.d.ts} +55 -1
- package/package.json +101 -4
- package/src/__tests__/doctor-rules.test.ts +87 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/button-haptic.test.tsx +52 -0
- package/src/components/__tests__/composer-bar.test.tsx +79 -0
- package/src/components/__tests__/gallery-card.test.tsx +59 -0
- package/src/components/__tests__/gallery-grid.test.tsx +160 -0
- package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
- package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
- package/src/components/__tests__/lightbox.test.tsx +141 -0
- package/src/components/__tests__/live-indicator.test.tsx +72 -0
- package/src/components/__tests__/rating.test.tsx +82 -0
- package/src/components/__tests__/thread-list.test.tsx +219 -0
- package/src/components/button.tsx +18 -1
- package/src/components/composer-bar.tsx +276 -0
- package/src/components/drawer.tsx +15 -9
- package/src/components/gallery-card.tsx +109 -0
- package/src/components/gallery-grid.tsx +285 -0
- package/src/components/gallery-layout.ts +2 -0
- package/src/components/gallery-types.ts +2 -0
- package/src/components/index.ts +44 -0
- package/src/components/lightbox-zoom.tsx +282 -0
- package/src/components/lightbox.tsx +342 -0
- package/src/components/live-indicator.tsx +139 -0
- package/src/components/rating.tsx +128 -0
- package/src/components/skeleton.tsx +9 -4
- package/src/components/thread-list.tsx +457 -0
- package/src/components/toast.tsx +7 -4
- package/src/data/NativeConflictSheet.tsx +181 -0
- package/src/data/NativeResourceForm.tsx +15 -1
- package/src/data/index.ts +2 -0
- package/src/data/resource-view/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
- package/src/hooks/__tests__/use-haptics.test.tsx +146 -0
- package/src/hooks/__tests__/use-motion.test.tsx +106 -0
- package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-haptics.ts +64 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-press-feedback.ts +87 -0
- package/src/hooks/use-thread-jump.ts +110 -0
- package/src/icon-names.ts +6 -0
- package/src/icons/lucide.ts +12 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
- package/src/layouts/__tests__/thread-page.test.tsx +114 -14
- package/src/layouts/inbox-page.tsx +6 -55
- package/src/layouts/index.ts +2 -0
- package/src/layouts/thread-page.tsx +326 -262
- package/src/native-modules.tsx +20 -2
- package/dist/chunk-6KWEAGRD.js.map +0 -1
- package/dist/chunk-7PCWEY6R.js +0 -27
- package/dist/chunk-7PCWEY6R.js.map +0 -1
- package/dist/chunk-ABVSSJNT.js.map +0 -1
- package/dist/chunk-D5RKSPMH.js.map +0 -1
- package/dist/chunk-GHYUNNNU.js.map +0 -1
- package/dist/chunk-LBVD7XXL.js.map +0 -1
- package/dist/chunk-ONH2PCGH.js.map +0 -1
- package/dist/chunk-Z3AQYVUA.js +0 -36
- package/dist/chunk-Z3AQYVUA.js.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useThreadJump — going to one row of a thread (a search result, a pinned
|
|
3
|
+
* message, the first unread): load earlier pages until the row is held, then
|
|
4
|
+
* scroll to it and highlight it for two seconds. A row that can't be found
|
|
5
|
+
* says so.
|
|
6
|
+
*
|
|
7
|
+
* Promoted from genesis-chat's `useJumpToMessage` (G4), generalised from
|
|
8
|
+
* chat's sequence numbers to row ids. It's a state machine driven by the
|
|
9
|
+
* rows, not a one-shot: a target set before the first page has loaded waits
|
|
10
|
+
* for `loading` to end, a row that arrives a render or two after `loadUntil`
|
|
11
|
+
* resolves is still found, and going to the same id again (after `null`)
|
|
12
|
+
* goes again.
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
17
|
+
|
|
18
|
+
export interface UseThreadJumpOptions {
|
|
19
|
+
/** The row to go to; `null` clears it, and a new id (or the same one after `null`) starts again. */
|
|
20
|
+
target: string | null | undefined;
|
|
21
|
+
/** Whether the row is held now. */
|
|
22
|
+
has: (id: string) => boolean;
|
|
23
|
+
/** The first page is still loading: don't start until it's in. */
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
/** Load earlier pages until the row is held; resolve false when it can't be. Without it, a row not held is gone. */
|
|
26
|
+
loadUntil?: (id: string) => Promise<boolean>;
|
|
27
|
+
/** Scroll to the row. */
|
|
28
|
+
scrollTo: (id: string) => void;
|
|
29
|
+
/** Before loading or scrolling (stop following the bottom). */
|
|
30
|
+
onStart?: () => void;
|
|
31
|
+
/** Scrolled to it (say so to VoiceOver). */
|
|
32
|
+
onLanded?: (id: string) => void;
|
|
33
|
+
/** It isn't there (go back to where the thread was). */
|
|
34
|
+
onGone?: (id: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Pending = { id: string; phase: "new" | "loading" | "loaded" };
|
|
38
|
+
|
|
39
|
+
/** After `loadUntil` resolves, how long the rows have to arrive before the row counts as gone. */
|
|
40
|
+
export const JUMP_SETTLE_MS = 400;
|
|
41
|
+
|
|
42
|
+
export function useThreadJump({ target, has, loading = false, loadUntil, scrollTo, onStart, onLanded, onGone }: UseThreadJumpOptions) {
|
|
43
|
+
const [pending, setPending] = useState<Pending | null>(target ? { id: target, phase: "new" } : null);
|
|
44
|
+
const [highlightedId, setHighlightedId] = useState<string | null>(null);
|
|
45
|
+
const armed = useRef<Pending | null>(null);
|
|
46
|
+
const goneTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (target) setPending({ id: target, phase: "new" });
|
|
49
|
+
else {
|
|
50
|
+
// null cancels a jump in progress.
|
|
51
|
+
if (goneTimerRef.current) clearTimeout(goneTimerRef.current);
|
|
52
|
+
armed.current = null;
|
|
53
|
+
setPending(null);
|
|
54
|
+
}
|
|
55
|
+
}, [target]);
|
|
56
|
+
|
|
57
|
+
const latest = useRef({ scrollTo, onStart, onLanded, onGone, loadUntil });
|
|
58
|
+
latest.current = { scrollTo, onStart, onLanded, onGone, loadUntil };
|
|
59
|
+
const highlightTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
60
|
+
const goneTimer = goneTimerRef;
|
|
61
|
+
useEffect(
|
|
62
|
+
() => () => {
|
|
63
|
+
if (highlightTimer.current) clearTimeout(highlightTimer.current);
|
|
64
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
65
|
+
},
|
|
66
|
+
[],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const go = useCallback((id: string) => {
|
|
70
|
+
latest.current.onStart?.();
|
|
71
|
+
latest.current.scrollTo(id);
|
|
72
|
+
latest.current.onLanded?.(id);
|
|
73
|
+
setHighlightedId(id);
|
|
74
|
+
if (highlightTimer.current) clearTimeout(highlightTimer.current);
|
|
75
|
+
highlightTimer.current = setTimeout(() => setHighlightedId((h) => (h === id ? null : h)), 2000);
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!pending || loading) return;
|
|
80
|
+
const { id, phase } = pending;
|
|
81
|
+
if (has(id)) {
|
|
82
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
83
|
+
setPending(null);
|
|
84
|
+
go(id);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (phase === "loading") return;
|
|
88
|
+
if (phase === "loaded" || !latest.current.loadUntil) {
|
|
89
|
+
// The rows may reach the list a render or two after the load resolved: give them a moment,
|
|
90
|
+
// once per pending jump (new rows arriving in a busy thread don't restart it).
|
|
91
|
+
if (armed.current === pending) return;
|
|
92
|
+
armed.current = pending;
|
|
93
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
94
|
+
goneTimer.current = setTimeout(
|
|
95
|
+
() => {
|
|
96
|
+
setPending((p) => (p && p.id === id ? null : p));
|
|
97
|
+
latest.current.onGone?.(id);
|
|
98
|
+
},
|
|
99
|
+
phase === "loaded" ? JUMP_SETTLE_MS : 0,
|
|
100
|
+
);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
latest.current.onStart?.();
|
|
104
|
+
setPending({ id, phase: "loading" });
|
|
105
|
+
const settle = () => setPending((p) => (p && p.id === id ? { ...p, phase: "loaded" } : p));
|
|
106
|
+
void latest.current.loadUntil(id).then(settle, settle);
|
|
107
|
+
}, [pending, loading, has, go]);
|
|
108
|
+
|
|
109
|
+
return { highlightedId, jumping: pending !== null };
|
|
110
|
+
}
|
package/src/icon-names.ts
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
export const SF_SYMBOLS = {
|
|
10
10
|
"arrow-left": "arrow.left",
|
|
11
11
|
"arrow-up": "arrow.up",
|
|
12
|
+
aperture: "camera.aperture",
|
|
12
13
|
bell: "bell",
|
|
13
14
|
calendar: "calendar",
|
|
14
15
|
camera: "camera",
|
|
15
16
|
"camera-flip": "arrow.triangle.2.circlepath.camera",
|
|
16
17
|
check: "checkmark",
|
|
18
|
+
clapperboard: "movieclapper",
|
|
17
19
|
"chevron-down": "chevron.down",
|
|
18
20
|
"chevron-left": "chevron.left",
|
|
19
21
|
"chevron-right": "chevron.right",
|
|
@@ -29,6 +31,7 @@ export const SF_SYMBOLS = {
|
|
|
29
31
|
"external-link": "arrow.up.right.square",
|
|
30
32
|
file: "doc",
|
|
31
33
|
filter: "line.3.horizontal.decrease",
|
|
34
|
+
"folder-plus": "folder.badge.plus",
|
|
32
35
|
heart: "heart",
|
|
33
36
|
home: "house",
|
|
34
37
|
image: "photo",
|
|
@@ -36,6 +39,7 @@ export const SF_SYMBOLS = {
|
|
|
36
39
|
lock: "lock",
|
|
37
40
|
"log-out": "rectangle.portrait.and.arrow.right",
|
|
38
41
|
mail: "envelope",
|
|
42
|
+
maximize: "arrow.up.left.and.arrow.down.right",
|
|
39
43
|
menu: "line.3.horizontal",
|
|
40
44
|
message: "bubble.left",
|
|
41
45
|
mic: "mic",
|
|
@@ -46,10 +50,12 @@ export const SF_SYMBOLS = {
|
|
|
46
50
|
pin: "pin",
|
|
47
51
|
play: "play.fill",
|
|
48
52
|
plus: "plus",
|
|
53
|
+
radio: "dot.radiowaves.left.and.right",
|
|
49
54
|
refresh: "arrow.clockwise",
|
|
50
55
|
reply: "arrowshape.turn.up.left",
|
|
51
56
|
search: "magnifyingglass",
|
|
52
57
|
settings: "gearshape",
|
|
58
|
+
"settings-2": "slider.horizontal.3",
|
|
53
59
|
share: "square.and.arrow.up",
|
|
54
60
|
smile: "face.smiling",
|
|
55
61
|
star: "star",
|
package/src/icons/lucide.ts
CHANGED
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* @stability Beta
|
|
10
10
|
*/
|
|
11
11
|
import {
|
|
12
|
+
Aperture,
|
|
12
13
|
ArrowLeft,
|
|
13
14
|
ArrowUp,
|
|
14
15
|
Bell,
|
|
15
16
|
Calendar,
|
|
16
17
|
Camera,
|
|
17
18
|
Check,
|
|
19
|
+
Clapperboard,
|
|
18
20
|
ChevronDown,
|
|
19
21
|
ChevronLeft,
|
|
20
22
|
ChevronRight,
|
|
@@ -27,11 +29,13 @@ import {
|
|
|
27
29
|
Ellipsis,
|
|
28
30
|
ExternalLink,
|
|
29
31
|
File,
|
|
32
|
+
FolderPlus,
|
|
30
33
|
Funnel,
|
|
31
34
|
Heart,
|
|
32
35
|
House,
|
|
33
36
|
Image,
|
|
34
37
|
Info,
|
|
38
|
+
Maximize,
|
|
35
39
|
Maximize2,
|
|
36
40
|
Lock,
|
|
37
41
|
LogOut,
|
|
@@ -46,12 +50,14 @@ import {
|
|
|
46
50
|
Pin,
|
|
47
51
|
Play,
|
|
48
52
|
Plus,
|
|
53
|
+
Radio,
|
|
49
54
|
RefreshCw,
|
|
50
55
|
Reply,
|
|
51
56
|
Search,
|
|
52
57
|
Square,
|
|
53
58
|
SwitchCamera,
|
|
54
59
|
Settings,
|
|
60
|
+
Settings2,
|
|
55
61
|
Share,
|
|
56
62
|
Smile,
|
|
57
63
|
SquarePen,
|
|
@@ -70,11 +76,13 @@ import type { GenesisIconComponent } from "../native-modules";
|
|
|
70
76
|
export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
71
77
|
"arrow-left": ArrowLeft,
|
|
72
78
|
"arrow-up": ArrowUp,
|
|
79
|
+
aperture: Aperture,
|
|
73
80
|
bell: Bell,
|
|
74
81
|
calendar: Calendar,
|
|
75
82
|
camera: Camera,
|
|
76
83
|
"camera-flip": SwitchCamera,
|
|
77
84
|
check: Check,
|
|
85
|
+
clapperboard: Clapperboard,
|
|
78
86
|
"chevron-down": ChevronDown,
|
|
79
87
|
"chevron-left": ChevronLeft,
|
|
80
88
|
"chevron-right": ChevronRight,
|
|
@@ -90,6 +98,7 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
90
98
|
"external-link": ExternalLink,
|
|
91
99
|
file: File,
|
|
92
100
|
filter: Funnel,
|
|
101
|
+
"folder-plus": FolderPlus,
|
|
93
102
|
heart: Heart,
|
|
94
103
|
home: House,
|
|
95
104
|
image: Image,
|
|
@@ -97,6 +106,7 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
97
106
|
lock: Lock,
|
|
98
107
|
"log-out": LogOut,
|
|
99
108
|
mail: Mail,
|
|
109
|
+
maximize: Maximize,
|
|
100
110
|
menu: Menu,
|
|
101
111
|
message: MessageCircle,
|
|
102
112
|
mic: Mic,
|
|
@@ -107,10 +117,12 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
107
117
|
pin: Pin,
|
|
108
118
|
play: Play,
|
|
109
119
|
plus: Plus,
|
|
120
|
+
radio: Radio,
|
|
110
121
|
refresh: RefreshCw,
|
|
111
122
|
reply: Reply,
|
|
112
123
|
search: Search,
|
|
113
124
|
settings: Settings,
|
|
125
|
+
"settings-2": Settings2,
|
|
114
126
|
share: Share,
|
|
115
127
|
smile: Smile,
|
|
116
128
|
star: Star,
|
|
@@ -198,4 +198,10 @@ describe("InboxPage", () => {
|
|
|
198
198
|
expect(screen.getByTestId("inbox-row-a").getAttribute("aria-label")).toMatch(/^2 unread, Sam, Morning crew/);
|
|
199
199
|
expect(screen.getByTestId("inbox-row-b").getAttribute("aria-label")).not.toContain("Ignored");
|
|
200
200
|
});
|
|
201
|
+
|
|
202
|
+
it("marks a selected row (the conversation open beside the list), as the web does", () => {
|
|
203
|
+
render(<InboxPage testID="inbox" items={[{ id: "s", title: "Sam", selected: true, onPress: () => {} }, { id: "t", title: "Tia", onPress: () => {} }]} />);
|
|
204
|
+
expect(screen.getByTestId("inbox-row-s").getAttribute("aria-selected")).toBe("true");
|
|
205
|
+
expect(screen.getByTestId("inbox-row-t").getAttribute("aria-selected")).toBeNull();
|
|
206
|
+
});
|
|
201
207
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @feat:inbox-thread
|
|
2
|
-
import {
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
3
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { ThreadPage, getThreadPageStackOptions, readReceiptFor, type ThreadMessage } from "../thread-page";
|
|
6
|
-
import {
|
|
6
|
+
import { GenesisModulesProvider } from "../../native-modules";
|
|
7
7
|
|
|
8
8
|
const messages: ThreadMessage[] = [
|
|
9
9
|
{ id: "1", body: "The save button does nothing", mine: true, timestamp: "2026-10-24T09:00:00Z" },
|
|
@@ -99,27 +99,127 @@ describe("ThreadPage", () => {
|
|
|
99
99
|
expect(screen.getByTestId("t-empty").textContent).toContain("Say hello");
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
it("
|
|
102
|
+
it("sits in React Native's KeyboardAvoidingView without the keyboard module", () => {
|
|
103
103
|
render(<ThreadPage testID="t" messages={messages} composer={composer()} />);
|
|
104
|
-
|
|
105
|
-
expect(
|
|
104
|
+
const keyboard = screen.getByTestId("t-keyboard");
|
|
105
|
+
expect(keyboard.querySelector('[data-testid="t-composer-input"]')).toBeTruthy();
|
|
106
|
+
expect(keyboard.querySelector('[data-testid="t-messages"]')).toBeTruthy();
|
|
106
107
|
});
|
|
107
108
|
|
|
108
|
-
it("
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
109
|
+
it("follows the keyboard frame by frame with the app's keyboard-controller KeyboardAvoidingView", () => {
|
|
110
|
+
const seen: Record<string, unknown>[] = [];
|
|
111
|
+
const Kav = ({ children, testID, ...rest }: Record<string, unknown> & { children?: ReactNode; testID?: string }) => {
|
|
112
|
+
seen.push(rest);
|
|
112
113
|
return <div data-testid={testID}>{children}</div>;
|
|
113
|
-
}
|
|
114
|
+
};
|
|
115
|
+
render(
|
|
116
|
+
<GenesisModulesProvider modules={{ keyboardAvoidingView: Kav }}>
|
|
117
|
+
<ThreadPage testID="t" messages={messages} composer={composer()} keyboardVerticalOffset={64} />
|
|
118
|
+
</GenesisModulesProvider>,
|
|
119
|
+
);
|
|
120
|
+
expect(seen.at(-1)).toMatchObject({ behavior: "translate-with-padding", automaticOffset: true, keyboardVerticalOffset: 64 });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("shows events as centred lines, and keeps them out of the read receipt", () => {
|
|
124
|
+
const withEvent: ThreadMessage[] = [...messages, { id: "e", kind: "event", body: "Sam was assigned", mine: true, timestamp: "2026-10-24T09:20:00Z" }];
|
|
125
|
+
render(<ThreadPage testID="t" messages={withEvent} composer={composer()} readAt="2026-10-24T10:00:00Z" />);
|
|
126
|
+
expect(screen.getByTestId("t-event-e").textContent).toBe("Sam was assigned");
|
|
127
|
+
expect(screen.queryByTestId("t-message-e")).toBeNull();
|
|
128
|
+
expect(readReceiptFor(withEvent, "2026-10-24T10:00:00Z")).toBe("3");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("marks the first unread with a divider", () => {
|
|
132
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} firstUnreadId="2" labels={{ newMessages: "Unread" }} />);
|
|
133
|
+
expect(screen.getByTestId("t-unread").textContent).toBe("Unread");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("says each send state, and discards on request", () => {
|
|
137
|
+
const onDiscard = vi.fn();
|
|
138
|
+
const rows: ThreadMessage[] = [
|
|
139
|
+
{ id: "p", body: "a", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "pending" },
|
|
140
|
+
{ id: "z", body: "b", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "paused" },
|
|
141
|
+
{ id: "c", body: "c", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "conflict", onRetry: vi.fn(), onDiscard },
|
|
142
|
+
];
|
|
143
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
144
|
+
expect(screen.getByTestId("t-message-p-time").textContent).toBe("Waiting to send");
|
|
145
|
+
expect(screen.getByTestId("t-message-z-time").textContent).toBe("Sign in to send");
|
|
146
|
+
expect(screen.getByTestId("t-message-c-time").textContent).toMatch(/changed elsewhere/);
|
|
147
|
+
fireEvent.click(screen.getByTestId("t-message-c-discard"));
|
|
148
|
+
expect(onDiscard).toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("says it's updating while fresher rows load", () => {
|
|
152
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} updating />);
|
|
153
|
+
expect(screen.getByTestId("t-updating").textContent).toBe("Updating…");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("tints an internal note, and the composer in its internal mode", () => {
|
|
157
|
+
const rows: ThreadMessage[] = [{ id: "n", body: "Check the logs", mine: true, tone: "internal", timestamp: "2026-10-24T09:00:00Z" }];
|
|
158
|
+
const onModeChange = vi.fn();
|
|
159
|
+
render(
|
|
160
|
+
<ThreadPage
|
|
161
|
+
testID="t"
|
|
162
|
+
messages={rows}
|
|
163
|
+
composer={composer({ modes: [{ id: "reply", label: "Reply" }, { id: "note", label: "Internal note", tone: "internal" }], mode: "note", onModeChange })}
|
|
164
|
+
/>,
|
|
165
|
+
);
|
|
166
|
+
expect(screen.getByTestId("t-composer-mode-note").getAttribute("aria-selected")).toBe("true");
|
|
167
|
+
expect(screen.getByTestId("t-composer-input").getAttribute("placeholder")).toBe("Internal note");
|
|
168
|
+
fireEvent.click(screen.getByTestId("t-composer-mode-reply"));
|
|
169
|
+
expect(onModeChange).toHaveBeenCalledWith("reply");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("says an internal note is one, to VoiceOver", () => {
|
|
173
|
+
const rows: ThreadMessage[] = [{ id: "n", body: "Check the logs", mine: true, tone: "internal", timestamp: "2026-10-24T09:00:00Z" }];
|
|
174
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
175
|
+
expect(screen.getByTestId("t-message-n").getAttribute("aria-label")).toMatch(/^You, Internal note, Check the logs/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("offers Discard only on a message that hasn't gone", () => {
|
|
179
|
+
const onDiscard = vi.fn();
|
|
180
|
+
const rows: ThreadMessage[] = [{ id: "s", body: "sent", mine: true, timestamp: "2026-10-24T09:00:00Z", onDiscard }];
|
|
181
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
182
|
+
expect(screen.queryByTestId("t-message-s-discard")).toBeNull();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("doesn't offer Discard while a message is sending (it may already be on the server)", () => {
|
|
186
|
+
const onDiscard = vi.fn();
|
|
187
|
+
const rows: ThreadMessage[] = [
|
|
188
|
+
{ id: "a", body: "a", mine: true, timestamp: "2026-10-24T09:00:00Z", status: "sending", onDiscard },
|
|
189
|
+
{ id: "b", body: "b", mine: true, timestamp: "2026-10-24T09:01:00Z", status: "pending", onDiscard },
|
|
190
|
+
];
|
|
191
|
+
render(<ThreadPage testID="t" messages={rows} composer={composer()} />);
|
|
192
|
+
expect(screen.queryByTestId("t-message-a-discard")).toBeNull();
|
|
193
|
+
expect(screen.getByTestId("t-message-b-discard")).toBeTruthy();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("warns in development when keyboard-controller is set up but not passed as keyboardAvoidingView", async () => {
|
|
197
|
+
const { KeyboardScrollProvider } = await import("../keyboard");
|
|
198
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
199
|
+
const Scroll = ({ children }: { children?: ReactNode }) => <div>{children}</div>;
|
|
114
200
|
render(
|
|
115
201
|
<KeyboardScrollProvider component={Scroll}>
|
|
116
202
|
<ThreadPage testID="t" messages={messages} composer={composer()} />
|
|
117
203
|
</KeyboardScrollProvider>,
|
|
118
204
|
);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
205
|
+
expect(warn.mock.calls.some(([m]) => String(m).includes("keyboardAvoidingView"))).toBe(true);
|
|
206
|
+
warn.mockRestore();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("shows a skeleton, not the empty state, while the first page loads", () => {
|
|
210
|
+
render(<ThreadPage testID="t" messages={[]} composer={composer()} loading />);
|
|
211
|
+
expect(screen.getByTestId("t-messages-loading")).toBeTruthy();
|
|
212
|
+
expect(screen.queryByTestId("t-empty")).toBeNull();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("pins the header region above the list", () => {
|
|
216
|
+
const Props = ({ testID }: { testID: string }) => <div data-testid={testID}>Open · Sam</div>;
|
|
217
|
+
render(<ThreadPage testID="t" messages={messages} composer={composer()} slots={{ headerRegion: Props }} />);
|
|
218
|
+
const region = screen.getByTestId("t-header-region");
|
|
219
|
+
expect(region.textContent).toBe("Open · Sam");
|
|
220
|
+
expect(screen.getByTestId("t-messages").contains(region)).toBe(false);
|
|
221
|
+
// Outside the keyboard-avoiding view, so it doesn't move with the keyboard.
|
|
222
|
+
expect(screen.getByTestId("t-keyboard").contains(region)).toBe(false);
|
|
123
223
|
});
|
|
124
224
|
|
|
125
225
|
it("composes a standard header by default", () => {
|
|
@@ -41,49 +41,11 @@ import { NativeBadge } from "../components/badge";
|
|
|
41
41
|
import { NativeRefreshControl } from "../components/refresh-control";
|
|
42
42
|
import { NativeLoadingState } from "../components/loading-state";
|
|
43
43
|
import { composeHeaderOptions, type ScreenHeaderProps } from "./screen-container";
|
|
44
|
+
import { formatInboxTime, type InboxItem, type InboxSwipeAction } from "@marktiderman/genesis-core/conversation";
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
label: string;
|
|
49
|
-
onPress: () => void;
|
|
50
|
-
/** Destructive tone (delete, leave). */
|
|
51
|
-
destructive?: boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface InboxItem {
|
|
55
|
-
/** Stable id for keying. */
|
|
56
|
-
id: string;
|
|
57
|
-
title: string;
|
|
58
|
-
/** The latest message or a summary, at most two lines. */
|
|
59
|
-
preview?: string;
|
|
60
|
-
/** When it last changed. Shown as a short time or date. */
|
|
61
|
-
timestamp?: string | Date;
|
|
62
|
-
/** Something new the person hasn't read: a dot, and the title in bold. */
|
|
63
|
-
unread?: boolean;
|
|
64
|
-
/** How many unread messages; shown as a count instead of the dot when above 0. */
|
|
65
|
-
unreadCount?: number;
|
|
66
|
-
/** A short status shown under the preview ("In progress", "12 votes"). */
|
|
67
|
-
meta?: string;
|
|
68
|
-
/** Replaces the unread dot (an icon). For a picture of who it is, use `avatar`, which keeps the dot. */
|
|
69
|
-
leading?: ReactNode;
|
|
70
|
-
/**
|
|
71
|
-
* A picture of who or what it is (a `NativeAvatar`, about 40pt), between the
|
|
72
|
-
* unread dot and the text. The separator then starts at the text. It is hidden
|
|
73
|
-
* from screen readers; when it shows someone `title` doesn't name, say who in
|
|
74
|
-
* `avatarLabel`.
|
|
75
|
-
*/
|
|
76
|
-
avatar?: ReactNode;
|
|
77
|
-
/** Who the avatar shows, read before the title, when `title` doesn't name them. */
|
|
78
|
-
avatarLabel?: string;
|
|
79
|
-
/** Shown at the end of the row (a vote button, a badge). Replaces the chevron. */
|
|
80
|
-
trailing?: ReactNode;
|
|
81
|
-
/** Opens the conversation. Rows with `onPress` show a chevron unless `trailing` is set. */
|
|
82
|
-
onPress?: () => void;
|
|
83
|
-
swipeActions?: InboxSwipeAction[];
|
|
84
|
-
/** testID override. Default `<page testID>-row-<id>`. */
|
|
85
|
-
testID?: string;
|
|
86
|
-
}
|
|
46
|
+
// The conversation contract is genesis-core's, shared with genesis-ui's InboxPage.
|
|
47
|
+
export type { InboxItem, InboxSwipeAction } from "@marktiderman/genesis-core/conversation";
|
|
48
|
+
export { formatInboxTime } from "@marktiderman/genesis-core/conversation";
|
|
87
49
|
|
|
88
50
|
/** The parts `slots` and `slotProps` reach, with the props each receives. */
|
|
89
51
|
export type InboxPageSlotMap = {
|
|
@@ -140,18 +102,6 @@ export function getInboxPageStackOptions(props: ScreenHeaderProps & { headerTitl
|
|
|
140
102
|
});
|
|
141
103
|
}
|
|
142
104
|
|
|
143
|
-
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
144
|
-
|
|
145
|
-
/** The default row time: `9:41`, `Yesterday`, `Monday`, then a short date. */
|
|
146
|
-
export function formatInboxTime(date: Date, now: Date): string {
|
|
147
|
-
const start = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
148
|
-
const days = Math.round((start(now) - start(date)) / DAY_MS);
|
|
149
|
-
if (days <= 0) return date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
150
|
-
if (days === 1) return "Yesterday";
|
|
151
|
-
if (days < 7) return date.toLocaleDateString(undefined, { weekday: "long" });
|
|
152
|
-
return date.toLocaleDateString(undefined, { day: "numeric", month: "short", year: date.getFullYear() === now.getFullYear() ? undefined : "numeric" });
|
|
153
|
-
}
|
|
154
|
-
|
|
155
105
|
/** The row's leading padding, the unread dot's column, an avatar's default size and its gap to the text. */
|
|
156
106
|
const ROW_PADDING = 16;
|
|
157
107
|
const LEADING_WIDTH = 18;
|
|
@@ -349,13 +299,14 @@ function DefaultRow(row: InboxPageSlotMap["row"]) {
|
|
|
349
299
|
testID={row.testID}
|
|
350
300
|
accessibilityRole={row.onPress ? "button" : undefined}
|
|
351
301
|
accessibilityLabel={label}
|
|
302
|
+
accessibilityState={row.selected ? { selected: true } : undefined}
|
|
352
303
|
accessibilityActions={actions.map((a) => ({ name: a.id, label: a.label }))}
|
|
353
304
|
onAccessibilityAction={(event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress()}
|
|
354
305
|
onPress={row.onPress}
|
|
355
306
|
onLongPress={actions.length ? () => showInboxActions(row.title, actions) : undefined}
|
|
356
307
|
onPressIn={() => setPressed(true)}
|
|
357
308
|
onPressOut={() => setPressed(false)}
|
|
358
|
-
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: ROW_PADDING, paddingVertical: 11, minHeight: 60, backgroundColor: pressed && row.onPress ? colors.fill : undefined }}
|
|
309
|
+
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: ROW_PADDING, paddingVertical: 11, minHeight: 60, backgroundColor: (pressed && row.onPress) || row.selected ? colors.fill : undefined }}
|
|
359
310
|
>
|
|
360
311
|
<View style={{ width: LEADING_WIDTH, alignItems: "flex-start" }}>
|
|
361
312
|
{row.leading ?? (row.unreadCount && row.unreadCount > 0 ? null : <UnreadDot unread={!!row.unread} testID={`${row.testID}-unread`} color={colors.tint} />)}
|