Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
import {
CommonActions,
StackActions,
useFocusEffect,
useNavigation,
usePreventRemove,
type NavigationAction,
} from "@react-navigation/native";
import { useCallback, useEffect, useRef, useState } from "react";
import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
Expand Down Expand Up @@ -212,6 +214,9 @@ export function NewTaskDraftScreen(props: {
const [isCancellingShareImport, setIsCancellingShareImport] = useState(false);
const [cancelledIncomingShareId, setCancelledIncomingShareId] = useState<string | null>(null);
const [isReturningToProjectPicker, setIsReturningToProjectPicker] = useState(false);
const [submitNavigationAction, setSubmitNavigationAction] = useState<NavigationAction | null>(
null,
);
const [shareImportAttempt, setShareImportAttempt] = useState(0);
const startedShareImportKeyRef = useRef<string | null>(null);
const cancellingShareImportKeyRef = useRef<string | null>(null);
Expand Down Expand Up @@ -275,12 +280,20 @@ export function NewTaskDraftScreen(props: {
voiceInput.elapsedSeconds,
);
const isVoiceInputPresented = voicePresentation.statusLabel !== null;
usePreventRemove(
const preventRemove =
(isIncomingShareTransferPending && !isProjectPickerReturnActive) ||
isCancellingShareImport ||
flow.submitting,
() => undefined,
);
isCancellingShareImport ||
flow.submitting;
usePreventRemove(preventRemove, () => undefined);
useEffect(() => {
if (preventRemove || submitNavigationAction === null) {
return;
}
// setSubmitting(false) does not release the guard synchronously. Navigate
// after usePreventRemove has committed, for both sent and queued tasks.
setSubmitNavigationAction(null);
(navigation.getParent() ?? navigation).dispatch(submitNavigationAction);
}, [navigation, preventRemove, submitNavigationAction]);
Comment thread
cursor[bot] marked this conversation as resolved.
const hasImportedIncomingShare = Boolean(
props.incomingShareId &&
flow.draftKey &&
Expand Down Expand Up @@ -872,7 +885,7 @@ export function NewTaskDraftScreen(props: {
clearWorkspaceSelection: true,
});
}
navigation.getParent()?.goBack();
setSubmitNavigationAction(CommonActions.goBack());
return;
}

Expand Down Expand Up @@ -943,7 +956,7 @@ export function NewTaskDraftScreen(props: {
clearWorkspaceSelection: true,
});
}
navigation.dispatch(
setSubmitNavigationAction(
StackActions.replace("Thread", {
environmentId: String(result.value.environmentId),
threadId: String(result.value.threadId),
Expand Down
Loading