Skip to content

Commit 1690aa9

Browse files
committed
Fix option taps clearing the local IME answer
1 parent 71e062a commit 1690aa9

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
272272
questions={props.pendingUserInput.questions}
273273
disabled={responseDisabled}
274274
value={draft?.customAnswer ?? ""}
275+
outsideChange={draft?.customAnswerResetVersion ?? 0}
275276
onChangeText={(value) =>
276277
props.onChangeCustomAnswer(props.pendingUserInput.requestId, question.id, value)
277278
}

‎apps/mobile/src/features/threads/QuestionAttachments.test.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const question: UserInputQuestion = {
6969
let root: Root;
7070

7171
// `draft` is what the thread screen passes back; it can lag the input by a render.
72-
function render(draft: string) {
72+
function render(draft: string, outsideChange = 0) {
7373
act(() =>
7474
root.render(
7575
<QuestionAttachments
@@ -78,6 +78,7 @@ function render(draft: string) {
7878
questions={[question]}
7979
disabled={false}
8080
value={draft}
81+
outsideChange={outsideChange}
8182
onChangeText={() => {}}
8283
/>,
8384
),
@@ -148,5 +149,15 @@ describe("QuestionAttachments answer field", () => {
148149
render("a");
149150
render("");
150151
expect(input().value).toBe("");
152+
153+
type("new answer");
154+
render("", 1);
155+
expect(input().value).toBe("");
156+
157+
type("a");
158+
type("");
159+
type("ab");
160+
render("", 2);
161+
expect(input().value).toBe("");
151162
});
152163
});

‎apps/mobile/src/features/threads/QuestionAttachments.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function QuestionAttachments(props: {
3636
questions: ReadonlyArray<UserInputQuestion>;
3737
disabled: boolean;
3838
value: string;
39+
outsideChange: number;
3940
onChangeText: (value: string) => void;
4041
onInputFocusChange?: ((focused: boolean) => void) | undefined;
4142
}) {
@@ -67,10 +68,13 @@ export function QuestionAttachments(props: {
6768
// Late draft echoes replace iOS marked text; ignore them while accepting outside edits.
6869
const [text, setText] = useState(props.value);
6970
const [previousValue, setPreviousValue] = useState(props.value);
71+
const [previousOutsideChange, setPreviousOutsideChange] = useState(props.outsideChange);
7072
const [sentValues, setSentValues] = useState<ReadonlySet<string>>(() => new Set());
71-
if (props.value !== previousValue) {
73+
const outsideChanged = props.outsideChange !== previousOutsideChange;
74+
if (props.value !== previousValue || outsideChanged) {
7275
setPreviousValue(props.value);
73-
if (props.value === text || !sentValues.has(props.value)) {
76+
setPreviousOutsideChange(props.outsideChange);
77+
if (outsideChanged || props.value === text || !sentValues.has(props.value)) {
7478
setSentValues(new Set());
7579
setText(props.value);
7680
}

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export type PendingUserInput = ThreadPendingUserInput;
8484
export interface PendingUserInputDraftAnswer {
8585
readonly selectedOptionValues?: ReadonlyArray<string>;
8686
readonly customAnswer?: string;
87+
readonly customAnswerResetVersion?: number;
8788
readonly attachmentCount?: number;
8889
readonly attachmentsBlocked?: boolean;
8990
}

‎apps/mobile/src/state/use-selected-thread-requests.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ function setUserInputDraftOption(
7373
...current,
7474
[requestKey]: {
7575
...current[requestKey],
76-
[question.id]: togglePendingUserInputOptionSelection(
77-
question,
78-
seededDraft(current[requestKey], question),
79-
value,
80-
),
76+
[question.id]: {
77+
...togglePendingUserInputOptionSelection(
78+
question,
79+
seededDraft(current[requestKey], question),
80+
value,
81+
),
82+
customAnswerResetVersion:
83+
(current[requestKey]?.[question.id]?.customAnswerResetVersion ?? 0) + 1,
84+
},
8185
},
8286
});
8387
}
@@ -92,11 +96,14 @@ function setUserInputDraftCustomAnswer(
9296
...current,
9397
[requestKey]: {
9498
...current[requestKey],
95-
[question.id]: setPendingUserInputCustomAnswer(
96-
question,
97-
seededDraft(current[requestKey], question),
98-
customAnswer,
99-
),
99+
[question.id]: {
100+
...setPendingUserInputCustomAnswer(
101+
question,
102+
seededDraft(current[requestKey], question),
103+
customAnswer,
104+
),
105+
customAnswerResetVersion: current[requestKey]?.[question.id]?.customAnswerResetVersion ?? 0,
106+
},
100107
},
101108
});
102109
}
@@ -198,7 +205,7 @@ export function useSelectedThreadRequests() {
198205
const preparationCounts = useAtomValue(questionAttachmentPreparationAtom);
199206
const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
200207
// Suggested answers are shown until the user edits them; only edits are stored.
201-
const activePendingUserInputAnswerDrafts =
208+
const activePendingUserInputAnswerDrafts: Record<string, PendingUserInputDraftAnswer> =
202209
activePendingUserInput && selectedThreadShell
203210
? seedUserInputDraftAnswers(
204211
activePendingUserInput.questions,

0 commit comments

Comments
 (0)