@terreno/ui 0.23.1 → 0.24.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/dist/AiSuggestionBox.d.ts +11 -0
- package/dist/AiSuggestionBox.js +50 -23
- package/dist/AiSuggestionBox.js.map +1 -1
- package/dist/Common.d.ts +9 -1
- package/dist/Common.js.map +1 -1
- package/dist/icons/SparklesIcon.d.ts +7 -0
- package/dist/icons/SparklesIcon.js +32 -0
- package/dist/icons/SparklesIcon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +1 -0
- package/dist/icons/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ActionSheet.test.tsx +96 -0
- package/src/AiSuggestionBox.test.tsx +184 -15
- package/src/AiSuggestionBox.tsx +72 -55
- package/src/Common.ts +9 -1
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +489 -102
- package/src/icons/SparklesIcon.test.tsx +16 -0
- package/src/icons/SparklesIcon.tsx +38 -0
- package/src/icons/__snapshots__/SparklesIcon.test.tsx.snap +47 -0
- package/src/icons/index.ts +1 -0
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import {fireEvent} from "@testing-library/react-native";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
3
4
|
|
|
5
|
+
import {AiSuggestionBox} from "./AiSuggestionBox";
|
|
4
6
|
import {TextArea} from "./TextArea";
|
|
5
7
|
import {renderWithTheme} from "./test-utils";
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Presses a Button-backed element and waits out the press handler's async haptic +
|
|
11
|
+
* leading-edge debounce so the onClick side effects have applied before asserting.
|
|
12
|
+
*/
|
|
13
|
+
const pressButton = async (element: ReactTestInstance): Promise<void> => {
|
|
14
|
+
await act(async () => {
|
|
15
|
+
fireEvent.press(element);
|
|
16
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
7
20
|
describe("AiSuggestionBox in TextArea", () => {
|
|
8
21
|
describe("not-started state", () => {
|
|
9
22
|
it("should render default not-started text", () => {
|
|
@@ -100,7 +113,7 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
100
113
|
expect(getByText("Add to note")).toBeTruthy();
|
|
101
114
|
});
|
|
102
115
|
|
|
103
|
-
it("should call onAdd when Add to note is pressed", () => {
|
|
116
|
+
it("should call onAdd when Add to note is pressed", async () => {
|
|
104
117
|
const mockOnAdd = mock(() => {});
|
|
105
118
|
const {getByLabelText} = renderWithTheme(
|
|
106
119
|
<TextArea
|
|
@@ -115,11 +128,11 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
115
128
|
/>
|
|
116
129
|
);
|
|
117
130
|
|
|
118
|
-
|
|
131
|
+
await pressButton(getByLabelText("Add to note"));
|
|
119
132
|
expect(mockOnAdd).toHaveBeenCalledTimes(1);
|
|
120
133
|
});
|
|
121
134
|
|
|
122
|
-
it("should collapse when Hide is pressed", () => {
|
|
135
|
+
it("should collapse when Hide is pressed", async () => {
|
|
123
136
|
const {getByLabelText, getByText, queryByText} = renderWithTheme(
|
|
124
137
|
<TextArea
|
|
125
138
|
aiSuggestion={{
|
|
@@ -135,14 +148,14 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
135
148
|
|
|
136
149
|
expect(getByText("Suggestion text")).toBeTruthy();
|
|
137
150
|
|
|
138
|
-
|
|
151
|
+
await pressButton(getByLabelText("Hide"));
|
|
139
152
|
|
|
140
153
|
expect(queryByText("Suggestion text")).toBeNull();
|
|
141
154
|
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
142
155
|
expect(getByText("Show")).toBeTruthy();
|
|
143
156
|
});
|
|
144
157
|
|
|
145
|
-
it("should expand when Show is pressed after collapsing", () => {
|
|
158
|
+
it("should expand when Show is pressed after collapsing", async () => {
|
|
146
159
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
147
160
|
<TextArea
|
|
148
161
|
aiSuggestion={{
|
|
@@ -156,15 +169,15 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
156
169
|
/>
|
|
157
170
|
);
|
|
158
171
|
|
|
159
|
-
|
|
172
|
+
await pressButton(getByLabelText("Hide"));
|
|
160
173
|
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
161
174
|
|
|
162
|
-
|
|
175
|
+
await pressButton(getByLabelText("Show"));
|
|
163
176
|
expect(getByText("Suggestion text")).toBeTruthy();
|
|
164
177
|
expect(getByText("AI-generated note")).toBeTruthy();
|
|
165
178
|
});
|
|
166
179
|
|
|
167
|
-
it("should call onHide when Hide is pressed", () => {
|
|
180
|
+
it("should call onHide when Hide is pressed", async () => {
|
|
168
181
|
const mockOnHide = mock(() => {});
|
|
169
182
|
const {getByLabelText} = renderWithTheme(
|
|
170
183
|
<TextArea
|
|
@@ -180,11 +193,11 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
180
193
|
/>
|
|
181
194
|
);
|
|
182
195
|
|
|
183
|
-
|
|
196
|
+
await pressButton(getByLabelText("Hide"));
|
|
184
197
|
expect(mockOnHide).toHaveBeenCalledTimes(1);
|
|
185
198
|
});
|
|
186
199
|
|
|
187
|
-
it("should call onShow when Show is pressed", () => {
|
|
200
|
+
it("should call onShow when Show is pressed", async () => {
|
|
188
201
|
const mockOnShow = mock(() => {});
|
|
189
202
|
const {getByLabelText} = renderWithTheme(
|
|
190
203
|
<TextArea
|
|
@@ -200,15 +213,57 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
200
213
|
/>
|
|
201
214
|
);
|
|
202
215
|
|
|
203
|
-
|
|
204
|
-
|
|
216
|
+
await pressButton(getByLabelText("Hide"));
|
|
217
|
+
await pressButton(getByLabelText("Show"));
|
|
218
|
+
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("hidden state", () => {
|
|
223
|
+
it("should render collapsed with the hidden heading", () => {
|
|
224
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
225
|
+
<TextArea
|
|
226
|
+
aiSuggestion={{
|
|
227
|
+
onAdd: () => {},
|
|
228
|
+
status: "hidden",
|
|
229
|
+
text: "Hidden suggestion",
|
|
230
|
+
}}
|
|
231
|
+
onChange={() => {}}
|
|
232
|
+
value=""
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
237
|
+
expect(getByText("Show")).toBeTruthy();
|
|
238
|
+
expect(queryByText("Hidden suggestion")).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should call onShow and expand when Show is pressed", async () => {
|
|
242
|
+
const mockOnShow = mock(() => {});
|
|
243
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
244
|
+
<TextArea
|
|
245
|
+
aiSuggestion={{
|
|
246
|
+
onAdd: () => {},
|
|
247
|
+
onShow: mockOnShow,
|
|
248
|
+
status: "hidden",
|
|
249
|
+
text: "Hidden suggestion",
|
|
250
|
+
}}
|
|
251
|
+
onChange={() => {}}
|
|
252
|
+
testID="test"
|
|
253
|
+
value=""
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
await pressButton(getByLabelText("Show"));
|
|
258
|
+
|
|
205
259
|
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
260
|
+
expect(getByText("Hidden suggestion")).toBeTruthy();
|
|
206
261
|
});
|
|
207
262
|
});
|
|
208
263
|
|
|
209
264
|
describe("added state", () => {
|
|
210
|
-
it("should render added heading", () => {
|
|
211
|
-
const {getByText} = renderWithTheme(
|
|
265
|
+
it("should render collapsed with the added heading", () => {
|
|
266
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
212
267
|
<TextArea
|
|
213
268
|
aiSuggestion={{
|
|
214
269
|
onAdd: () => {},
|
|
@@ -221,7 +276,104 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
221
276
|
);
|
|
222
277
|
|
|
223
278
|
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
279
|
+
expect(getByText("Show")).toBeTruthy();
|
|
280
|
+
expect(queryByText("Added suggestion")).toBeNull();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("should expand locally on Show without persisting, keeping Add to note available", async () => {
|
|
284
|
+
const mockOnShow = mock(() => {});
|
|
285
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
286
|
+
<TextArea
|
|
287
|
+
aiSuggestion={{
|
|
288
|
+
onAdd: () => {},
|
|
289
|
+
onShow: mockOnShow,
|
|
290
|
+
status: "added",
|
|
291
|
+
text: "Added suggestion",
|
|
292
|
+
}}
|
|
293
|
+
onChange={() => {}}
|
|
294
|
+
testID="test"
|
|
295
|
+
value=""
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
await pressButton(getByLabelText("Show"));
|
|
300
|
+
|
|
301
|
+
// Expanding an added suggestion must not call onShow — that would reset the
|
|
302
|
+
// persisted acceptance record.
|
|
303
|
+
expect(mockOnShow).not.toHaveBeenCalled();
|
|
224
304
|
expect(getByText("Added suggestion")).toBeTruthy();
|
|
305
|
+
expect(getByText("Add to note")).toBeTruthy();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should collapse locally on Hide without persisting", async () => {
|
|
309
|
+
const mockOnHide = mock(() => {});
|
|
310
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
311
|
+
<TextArea
|
|
312
|
+
aiSuggestion={{
|
|
313
|
+
onAdd: () => {},
|
|
314
|
+
onHide: mockOnHide,
|
|
315
|
+
status: "added",
|
|
316
|
+
text: "Added suggestion",
|
|
317
|
+
}}
|
|
318
|
+
onChange={() => {}}
|
|
319
|
+
testID="test"
|
|
320
|
+
value=""
|
|
321
|
+
/>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
await pressButton(getByLabelText("Show"));
|
|
325
|
+
await pressButton(getByLabelText("Hide"));
|
|
326
|
+
|
|
327
|
+
expect(mockOnHide).not.toHaveBeenCalled();
|
|
328
|
+
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("collapse behavior across status transitions", () => {
|
|
333
|
+
it("should collapse when the status transitions from ready to added", () => {
|
|
334
|
+
const {getByText, queryByText, rerender} = renderWithTheme(
|
|
335
|
+
<AiSuggestionBox onAdd={() => {}} status="ready" text="Suggestion text" />
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
339
|
+
|
|
340
|
+
rerender(<AiSuggestionBox onAdd={() => {}} status="added" text="Suggestion text" />);
|
|
341
|
+
|
|
342
|
+
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
343
|
+
expect(queryByText("Suggestion text")).toBeNull();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("should keep the box expanded when a stale hide lands after a newer Show click", async () => {
|
|
347
|
+
const mockOnHide = mock(() => {});
|
|
348
|
+
const mockOnShow = mock(() => {});
|
|
349
|
+
const suggestion = {
|
|
350
|
+
onAdd: () => {},
|
|
351
|
+
onHide: mockOnHide,
|
|
352
|
+
onShow: mockOnShow,
|
|
353
|
+
text: "Suggestion text",
|
|
354
|
+
};
|
|
355
|
+
const {getByLabelText, getByText, queryByText, rerender} = renderWithTheme(
|
|
356
|
+
<AiSuggestionBox status="ready" {...suggestion} />
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
await pressButton(getByLabelText("Hide"));
|
|
360
|
+
expect(mockOnHide).toHaveBeenCalledTimes(1);
|
|
361
|
+
|
|
362
|
+
await pressButton(getByLabelText("Show"));
|
|
363
|
+
// A Show clicked while the hide is still in flight must persist the un-hide too,
|
|
364
|
+
// so the backend converges on the user's latest choice.
|
|
365
|
+
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
366
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
367
|
+
|
|
368
|
+
// The earlier hide's refetch lands after the newer Show click — the box must not
|
|
369
|
+
// snap back to collapsed.
|
|
370
|
+
rerender(<AiSuggestionBox status="hidden" {...suggestion} />);
|
|
371
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
372
|
+
expect(queryByText("AI-generated note (hidden)")).toBeNull();
|
|
373
|
+
|
|
374
|
+
// The show mutation then lands and the box stays expanded.
|
|
375
|
+
rerender(<AiSuggestionBox status="ready" {...suggestion} />);
|
|
376
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
225
377
|
});
|
|
226
378
|
});
|
|
227
379
|
|
|
@@ -353,6 +505,23 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
353
505
|
expect(component.toJSON()).toMatchSnapshot();
|
|
354
506
|
});
|
|
355
507
|
|
|
508
|
+
it("should match snapshot for hidden state", () => {
|
|
509
|
+
const component = renderWithTheme(
|
|
510
|
+
<TextArea
|
|
511
|
+
aiSuggestion={{
|
|
512
|
+
feedback: null,
|
|
513
|
+
onAdd: () => {},
|
|
514
|
+
status: "hidden",
|
|
515
|
+
text: "AI-generated suggestion text.",
|
|
516
|
+
}}
|
|
517
|
+
onChange={() => {}}
|
|
518
|
+
testID="test"
|
|
519
|
+
value=""
|
|
520
|
+
/>
|
|
521
|
+
);
|
|
522
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
523
|
+
});
|
|
524
|
+
|
|
356
525
|
it("should match snapshot for added state", () => {
|
|
357
526
|
const component = renderWithTheme(
|
|
358
527
|
<TextArea
|
package/src/AiSuggestionBox.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {type FC, useCallback, useEffect, useState} from "react";
|
|
2
2
|
import {Pressable, View} from "react-native";
|
|
3
3
|
|
|
4
|
+
import {Button} from "./Button";
|
|
4
5
|
import type {AiSuggestionProps} from "./Common";
|
|
5
6
|
import {Icon} from "./Icon";
|
|
7
|
+
import {SparklesIcon} from "./icons";
|
|
6
8
|
import {Text} from "./Text";
|
|
7
9
|
import {useTheme} from "./Theme";
|
|
8
10
|
|
|
@@ -10,6 +12,17 @@ export interface AiSuggestionBoxProps extends AiSuggestionProps {
|
|
|
10
12
|
testID?: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Inline AI suggestion box rendered inside TextField/TextArea via the `aiSuggestion` prop.
|
|
17
|
+
*
|
|
18
|
+
* Expansion is derived from the persisted `status` (`ready` expands; `hidden` and `added`
|
|
19
|
+
* condense into the collapsed header row), but an explicit user Show/Hide toggle always
|
|
20
|
+
* wins — including while a hide/show mutation is still in flight — so a quick
|
|
21
|
+
* Hide-then-Show never snaps back to collapsed when the earlier hide's refetch lands.
|
|
22
|
+
* Hide/Show on a non-`added` suggestion also invoke `onHide`/`onShow` so consumers can
|
|
23
|
+
* persist the choice; toggling an `added` suggestion is purely local so the acceptance
|
|
24
|
+
* record is never reset. "Add to note" stays available after a first add for re-adds.
|
|
25
|
+
*/
|
|
13
26
|
export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
14
27
|
status,
|
|
15
28
|
text,
|
|
@@ -23,15 +36,26 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
23
36
|
testID,
|
|
24
37
|
}) => {
|
|
25
38
|
const {theme} = useTheme();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
// The user's last explicit Show/Hide choice. While set, it overrides the
|
|
40
|
+
// status-derived default so in-flight hide/show mutations can't undo a newer click.
|
|
41
|
+
const [expandedIntent, setExpandedIntent] = useState<boolean | null>(null);
|
|
42
|
+
|
|
43
|
+
// Reconcile the local intent with persisted status transitions. Accepting a suggestion
|
|
44
|
+
// (`added`) always condenses the box, and once the persisted status agrees with the
|
|
45
|
+
// user's intent the override is dropped so later transitions (e.g. a regenerated
|
|
46
|
+
// suggestion flipping back to `ready`) use their status defaults. An intent that
|
|
47
|
+
// disagrees with the incoming status is kept — that status is a stale in-flight
|
|
48
|
+
// hide/show landing after a newer click, and must not undo it.
|
|
29
49
|
useEffect(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
setExpandedIntent((current) => {
|
|
51
|
+
if (current === null || status === "added") {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return current === (status === "ready") ? null : current;
|
|
55
|
+
});
|
|
33
56
|
}, [status]);
|
|
34
57
|
|
|
58
|
+
const expanded = expandedIntent ?? status === "ready";
|
|
35
59
|
const isAdded = status === "added";
|
|
36
60
|
|
|
37
61
|
const backgroundColor = isAdded
|
|
@@ -68,14 +92,24 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
68
92
|
: "AI-generated note (hidden)";
|
|
69
93
|
|
|
70
94
|
const handleHide = useCallback(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
setExpandedIntent(false);
|
|
96
|
+
// Persist the hide for any non-`added` suggestion — even when the status still reads
|
|
97
|
+
// `hidden` locally (an un-hide may be in flight). Hiding an `added` suggestion is a
|
|
98
|
+
// purely local collapse so the acceptance record stays intact.
|
|
99
|
+
if (status !== "added") {
|
|
100
|
+
onHide?.();
|
|
101
|
+
}
|
|
102
|
+
}, [status, onHide]);
|
|
74
103
|
|
|
75
104
|
const handleShow = useCallback(() => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
105
|
+
setExpandedIntent(true);
|
|
106
|
+
// Persist the un-hide for any non-`added` suggestion — even when the status still
|
|
107
|
+
// reads `ready` locally (a hide may be in flight, and this Show must override it).
|
|
108
|
+
// Expanding an `added` suggestion must not reset its status.
|
|
109
|
+
if (status !== "added") {
|
|
110
|
+
onShow?.();
|
|
111
|
+
}
|
|
112
|
+
}, [status, onShow]);
|
|
79
113
|
|
|
80
114
|
const handleThumbsUp = useCallback(() => {
|
|
81
115
|
if (!onFeedback) {
|
|
@@ -106,7 +140,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
106
140
|
<Icon
|
|
107
141
|
color={feedback === "like" ? "secondaryDark" : "secondaryLight"}
|
|
108
142
|
iconName="thumbs-up"
|
|
109
|
-
size="
|
|
143
|
+
size="md"
|
|
110
144
|
type={feedback === "like" ? "solid" : "regular"}
|
|
111
145
|
/>
|
|
112
146
|
</Pressable>
|
|
@@ -120,7 +154,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
120
154
|
<Icon
|
|
121
155
|
color={feedback === "dislike" ? "secondaryDark" : "secondaryLight"}
|
|
122
156
|
iconName="thumbs-down"
|
|
123
|
-
size="
|
|
157
|
+
size="md"
|
|
124
158
|
type={feedback === "dislike" ? "solid" : "regular"}
|
|
125
159
|
/>
|
|
126
160
|
</Pressable>
|
|
@@ -131,7 +165,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
131
165
|
return (
|
|
132
166
|
<View style={containerStyle} testID={testID}>
|
|
133
167
|
<View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
|
|
134
|
-
<
|
|
168
|
+
<SparklesIcon fill={theme.text.secondaryDark} />
|
|
135
169
|
<View style={{flex: 1}}>
|
|
136
170
|
<Text color="secondaryDark" size="sm">
|
|
137
171
|
{headingText}
|
|
@@ -146,24 +180,20 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
146
180
|
return (
|
|
147
181
|
<View style={{...containerStyle, flexDirection: "column"}} testID={testID}>
|
|
148
182
|
<View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
|
|
149
|
-
<
|
|
183
|
+
<SparklesIcon fill={theme.text.secondaryDark} />
|
|
150
184
|
<View style={{flex: 1}}>
|
|
151
185
|
<Text color="secondaryDark" size="sm">
|
|
152
186
|
{headingText}
|
|
153
187
|
</Text>
|
|
154
188
|
</View>
|
|
155
189
|
<View style={{alignItems: "center", flexDirection: "row", gap: 4}}>
|
|
156
|
-
<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
onPress={handleShow}
|
|
160
|
-
style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
|
|
190
|
+
<Button
|
|
191
|
+
onClick={handleShow}
|
|
192
|
+
size="sm"
|
|
161
193
|
testID={testID ? `${testID}-show` : undefined}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
</Text>
|
|
166
|
-
</Pressable>
|
|
194
|
+
text="Show"
|
|
195
|
+
variant="ghost"
|
|
196
|
+
/>
|
|
167
197
|
{renderFeedback()}
|
|
168
198
|
</View>
|
|
169
199
|
</View>
|
|
@@ -174,7 +204,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
174
204
|
return (
|
|
175
205
|
<View style={{...containerStyle, alignItems: "flex-end"}} testID={testID}>
|
|
176
206
|
<View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
|
|
177
|
-
<
|
|
207
|
+
<SparklesIcon fill={theme.text.secondaryDark} />
|
|
178
208
|
<View style={{flex: 1}}>
|
|
179
209
|
<Text color="secondaryDark" size="sm">
|
|
180
210
|
{headingText}
|
|
@@ -198,35 +228,22 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
|
|
|
198
228
|
width: "100%",
|
|
199
229
|
}}
|
|
200
230
|
>
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
onPress={handleHide}
|
|
205
|
-
style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
|
|
231
|
+
<Button
|
|
232
|
+
onClick={handleHide}
|
|
233
|
+
size="sm"
|
|
206
234
|
testID={testID ? `${testID}-hide` : undefined}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
borderRadius: 360,
|
|
220
|
-
height: 28,
|
|
221
|
-
justifyContent: "center",
|
|
222
|
-
paddingHorizontal: 16,
|
|
223
|
-
}}
|
|
224
|
-
testID={testID ? `${testID}-add` : undefined}
|
|
225
|
-
>
|
|
226
|
-
<Text bold color="inverted" size="sm">
|
|
227
|
-
Add to note
|
|
228
|
-
</Text>
|
|
229
|
-
</Pressable>
|
|
235
|
+
text="Hide"
|
|
236
|
+
variant="ghost"
|
|
237
|
+
/>
|
|
238
|
+
{Boolean(onAdd) && (
|
|
239
|
+
<Button
|
|
240
|
+
onClick={onAdd!}
|
|
241
|
+
size="sm"
|
|
242
|
+
testID={testID ? `${testID}-add` : undefined}
|
|
243
|
+
text="Add to note"
|
|
244
|
+
variant="secondary"
|
|
245
|
+
/>
|
|
246
|
+
)}
|
|
230
247
|
</View>
|
|
231
248
|
</View>
|
|
232
249
|
);
|
package/src/Common.ts
CHANGED
|
@@ -762,10 +762,18 @@ export interface ErrorTextProps {
|
|
|
762
762
|
}
|
|
763
763
|
|
|
764
764
|
export interface AiSuggestionProps {
|
|
765
|
-
|
|
765
|
+
/**
|
|
766
|
+
* Persisted suggestion state. `ready` renders expanded; `hidden` and `added` render
|
|
767
|
+
* condensed into the collapsed header row (re-expandable with "Show") so a hidden or
|
|
768
|
+
* accepted suggestion never disappears entirely.
|
|
769
|
+
*/
|
|
770
|
+
status: "not-started" | "generating" | "ready" | "added" | "hidden";
|
|
766
771
|
text?: string;
|
|
772
|
+
/** Adds the suggestion text to the note. Stays available after adding for re-adds. */
|
|
767
773
|
onAdd?: () => void;
|
|
774
|
+
/** Persists a hide. Called for any non-`added` status when the user presses "Hide". */
|
|
768
775
|
onHide?: () => void;
|
|
776
|
+
/** Persists an un-hide. Called for any non-`added` status when the user presses "Show". */
|
|
769
777
|
onShow?: () => void;
|
|
770
778
|
onFeedback?: (feedback: "like" | "dislike" | null) => void;
|
|
771
779
|
feedback?: "like" | "dislike" | null;
|