Skip to content
TypeScript

fix(mobile): lock the composer while queued edits save (#21390)

maria834ae4f9faad
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx
index 8140517f4ab..8dd57c328bd 100644
--- a/apps/mobile/src/features/threads/ThreadComposer.tsx
+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx
@@ -496,6 +496,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
onChangeDraftMessage: (text) => setComposerDraftText(composerDraftKey, text),
onChangeSelection: composerMenu.onSelectionChange,
});
+ const isSubmissionLocked = queuedEdit?.saving === true || voiceInput.blocksSubmission;
const voicePresentation = resolveVoiceComposerPresentation(
voiceInput.state,
voiceInput.elapsedSeconds,
@@ -552,7 +553,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
(props.canOperateThread || props.connectionState !== "connected") &&
hasContent &&
!contextImports[composerDraftKey] &&
- !voiceInput.blocksSubmission &&
+ !isSubmissionLocked &&
sendBlockedReason === null &&
!modelUnavailable;
@@ -602,7 +603,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
setComposerEditing(false);
};
const handleSend = async (followUp?: ActiveTurnComposerAction) => {
- if (voiceInput.blocksSubmission || pendingPastedTextAttachmentCountRef.current > 0) return;
+ if (isSubmissionLocked || pendingPastedTextAttachmentCountRef.current > 0) return;
if (usageLimitsOffered && isUsageLimitsCommand(draftMessage) && draftAttachments.length === 0) {
if (openUsageLimits()) onChangeDraftMessage("");
return;
@@ -725,7 +726,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
<ComposerQueuedEditAttachments
environmentId={props.environmentId}
attachments={queuedEdit.existingAttachments}
- disabled={queuedEdit.saving || voiceInput.isBusy}
+ disabled={isSubmissionLocked}
onRemove={queuedEdit.onRemoveExistingAttachment}
/>
</Animated.View>
@@ -739,11 +740,11 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
<ComposerAttachmentStrip
environmentId={props.environmentId}
attachments={stripAttachments}
- onRemove={voiceInput.isBusy ? () => undefined : props.onRemoveDraftImage}
- onPressPreview={voiceInput.isBusy ? undefined : onPressPreview}
- onPressVideo={voiceInput.isBusy ? undefined : onPressVideo}
+ onRemove={isSubmissionLocked ? () => undefined : props.onRemoveDraftImage}
+ onPressPreview={isSubmissionLocked ? undefined : onPressPreview}
+ onPressVideo={isSubmissionLocked ? undefined : onPressVideo}
onPressDocument={
- voiceInput.isBusy
+ isSubmissionLocked
? undefined
: (attachment) =>
openDraftDocument({
@@ -807,7 +808,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
style={{ maxWidth: props.contentMaxWidth }}
onLayout={(event) => measureRow("surfaceWidth", event.nativeEvent.layout.width)}
>
- {!voiceInput.isBusy &&
+ {!isSubmissionLocked &&
composerMenu.trigger &&
(composerMenu.items.length > 0 || composerMenu.trigger.kind === "pull-request") ? (
<ComposerPopoverAnchor>
@@ -874,6 +875,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
>
{!usesCard ? (
<ComposerAttachmentButton
+ disabled={isSubmissionLocked}
supportsFiles={Boolean(
props.serverConfig?.environment.capabilities.fileAttachments,
)}
@@ -911,13 +913,18 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
multiline
value={draftMessage}
// The save uses a draft snapshot; further typing would be discarded on success.
- readOnly={voiceInput.freezesEditor || queuedEdit?.saving === true}
+ readOnly={isSubmissionLocked}
skills={composerMenu.skills}
selection={composerMenu.selection}
- onChangeText={props.onChangeDraftMessage}
+ onChangeText={(text) => {
+ if (!isSubmissionLocked) props.onChangeDraftMessage(text);
+ }}
onSelectionChange={composerMenu.onSelectionChange}
- onPasteImages={(uris) => void props.onNativePasteImages(uris)}
+ onPasteImages={(uris) => {
+ if (!isSubmissionLocked) void props.onNativePasteImages(uris);
+ }}
onPasteText={(paste) => {
+ if (isSubmissionLocked) return;
const insertPaste = () => {
const insertion = replaceTextSelection({
value: paste.value,
@@ -1045,8 +1052,8 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
size={30}
borderRadius={8}
compact
- onPressPreview={onPressPreview}
- onPressVideo={onPressVideo}
+ onPressPreview={isSubmissionLocked ? undefined : onPressPreview}
+ onPressVideo={isSubmissionLocked ? undefined : onPressVideo}
/>
))}
{stripAttachments.length > 3 ? (
@@ -1067,6 +1074,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
<ComposerDictationStartAction
state={voiceInput.state}
isAvailable={voiceInput.isAvailable}
+ disabled={isSubmissionLocked}
onStart={voiceInput.start}
onCancel={voiceInput.cancel}
/>
@@ -1139,6 +1147,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
) : (
<View className="min-w-0 flex-1 flex-row items-center justify-between">
<ComposerAttachmentButton
+ disabled={isSubmissionLocked}
supportsFiles={Boolean(
props.serverConfig?.environment.capabilities.fileAttachments,
)}
@@ -1153,6 +1162,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
state={voiceInput.state}
presentation={voicePresentation}
isAvailable={voiceInput.isAvailable}
+ disabled={isSubmissionLocked}
onStart={voiceInput.start}
onConfirm={voiceInput.stop}
onCancel={voiceInput.cancel}