Skip to content

Commit 85c75ac

Browse files
juliusmarmingecodex
andcommitted
fix(mobile): keep pending input actions usable
Co-authored-by: codex <[email protected]>
1 parent 2510bf7 commit 85c75ac

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { Pressable, ScrollView, View } from "react-native";
33

44
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
55
import { cn } from "../../lib/cn";
6-
import type { PendingUserInput, PendingUserInputDraftAnswer } from "../../lib/threadActivity";
6+
import {
7+
isPendingUserInputOptionSelected,
8+
type PendingUserInput,
9+
type PendingUserInputDraftAnswer,
10+
} from "../../lib/threadActivity";
711

812
export interface PendingUserInputCardProps {
913
readonly pendingUserInput: PendingUserInput;
@@ -60,9 +64,7 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
6064
</Text>
6165
<View className="flex-row flex-wrap gap-2.5">
6266
{question.options.map((option) => {
63-
const selected =
64-
draft?.selectedOptionLabels?.includes(option.label) === true &&
65-
!draft.customAnswer?.trim().length;
67+
const selected = isPendingUserInputOptionSelected(draft, option.label);
6668
return (
6769
<Pressable
6870
key={option.label}

‎apps/mobile/src/features/threads/pendingUserInputLayout.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ describe("derivePendingUserInputMaxHeight", () => {
2525
).toBe(387);
2626
});
2727

28-
it("never forces the card beyond a short landscape viewport", () => {
28+
it("keeps the fixed action area usable in a short keyboard-open viewport", () => {
2929
expect(
3030
derivePendingUserInputMaxHeight({
3131
windowHeight: 375,
3232
keyboardHeight: 240,
3333
navigationHeaderHeight: 44,
3434
composerOverlapHeight: 94,
3535
}),
36-
).toBe(0);
36+
).toBe(160);
3737
});
3838
});

‎apps/mobile/src/features/threads/pendingUserInputLayout.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const PENDING_USER_INPUT_MAX_HEIGHT = 560;
2+
const PENDING_USER_INPUT_MIN_HEIGHT = 160;
23
const PENDING_USER_INPUT_VERTICAL_GAP = 12;
34

45
export function derivePendingUserInputMaxHeight(input: {
@@ -14,5 +15,8 @@ export function derivePendingUserInputMaxHeight(input: {
1415
Math.max(0, input.composerOverlapHeight) -
1516
PENDING_USER_INPUT_VERTICAL_GAP;
1617

17-
return Math.min(PENDING_USER_INPUT_MAX_HEIGHT, Math.max(0, availableHeight));
18+
return Math.min(
19+
PENDING_USER_INPUT_MAX_HEIGHT,
20+
Math.max(PENDING_USER_INPUT_MIN_HEIGHT, availableHeight),
21+
);
1822
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
buildPendingUserInputAnswers,
1616
buildThreadFeed,
1717
deriveThreadFeedPresentation,
18+
isPendingUserInputOptionSelected,
1819
setPendingUserInputCustomAnswer,
1920
togglePendingUserInputOptionSelection,
2021
type ThreadFeedActivity,
@@ -98,6 +99,18 @@ describe("pending user input answers", () => {
9899
),
99100
).toEqual({ customAnswer: "Orders first" });
100101
});
102+
103+
it("matches selected chips against normalized option labels", () => {
104+
expect(
105+
isPendingUserInputOptionSelected({ selectedOptionLabels: ["Orders"] }, " Orders "),
106+
).toBe(true);
107+
expect(
108+
isPendingUserInputOptionSelected(
109+
{ selectedOptionLabels: ["Orders"], customAnswer: "Orders first" },
110+
" Orders ",
111+
),
112+
).toBe(false);
113+
});
101114
});
102115

103116
function makeActivity(

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,17 @@ export function setPendingUserInputCustomAnswer(
14561456
};
14571457
}
14581458

1459+
export function isPendingUserInputOptionSelected(
1460+
draft: PendingUserInputDraftAnswer | undefined,
1461+
optionLabel: string,
1462+
): boolean {
1463+
if (normalizeDraftAnswer(draft?.customAnswer)) {
1464+
return false;
1465+
}
1466+
1467+
return normalizeSelectedOptionLabels(draft?.selectedOptionLabels).includes(optionLabel.trim());
1468+
}
1469+
14591470
export function togglePendingUserInputOptionSelection(
14601471
question: UserInputQuestion,
14611472
draft: PendingUserInputDraftAnswer | undefined,

0 commit comments

Comments
 (0)