Skip to content
TypeScript

refactor(mobile): finish shared alert adoption (#20000)

Julius Marminge3b43e3f1f09e
diff --git a/apps/mobile/src/components/ComposerContextAttachment.tsx b/apps/mobile/src/components/ComposerContextAttachment.tsx
index ab14dfb957b..5f40a8d6f4d 100644
--- a/apps/mobile/src/components/ComposerContextAttachment.tsx
+++ b/apps/mobile/src/components/ComposerContextAttachment.tsx
@@ -1,5 +1,6 @@
+import * as Dialog from "./Dialog";
import type { ComposerContextRecord, EnvironmentId } from "@t3tools/contracts";
-import { Alert, Pressable, View } from "react-native";
+import { Pressable, View } from "react-native";
import { Image } from "expo-image";
import { useEffect, useId, useMemo, useState } from "react";
import type { DraftComposerAttachment } from "../lib/composerImages";
@@ -82,7 +83,7 @@ export function ComposerContextAttachment(props: {
});
}
} catch (cause) {
- Alert.alert(
+ Dialog.alert(
"Could not open attachment",
cause instanceof Error ? cause.message : "Try again.",
);
diff --git a/apps/mobile/src/components/ComposerContextSheet.tsx b/apps/mobile/src/components/ComposerContextSheet.tsx
index 4cb92829285..2e09b8f94db 100644
--- a/apps/mobile/src/components/ComposerContextSheet.tsx
+++ b/apps/mobile/src/components/ComposerContextSheet.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "./Dialog";
import { useOpenPullRequest } from "../native/useOpenPullRequest";
import { SourceFileSurface } from "../features/files/SourceFileSurface";
import { filePreviewKind } from "@t3tools/shared/filePreview";
@@ -10,7 +11,7 @@ import type {
} from "@t3tools/contracts";
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
import { videoMimeType } from "@t3tools/shared/video";
-import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
+import { Platform, Pressable, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { REVIEW_MONO_FONT_FAMILY } from "../features/review/reviewDiffRendering";
import { ReviewCommentCard, useReviewCommentColors } from "../features/review/ReviewCommentCard";
@@ -354,7 +355,7 @@ export function ComposerContextSheet(props: {
onPress={() => {
props.onClose();
void openPullRequest(pullRequestUrl).catch(() =>
- Alert.alert("Could not open pull request", "Try again when connected."),
+ Dialog.alert("Could not open pull request", "Try again when connected."),
);
}}
className="rounded-xl bg-subtle p-4"
diff --git a/apps/mobile/src/components/ComposerEditor.tsx b/apps/mobile/src/components/ComposerEditor.tsx
index a4e2610dffc..3d89f309aaf 100644
--- a/apps/mobile/src/components/ComposerEditor.tsx
+++ b/apps/mobile/src/components/ComposerEditor.tsx
@@ -1,9 +1,9 @@
+import * as Dialog from "./Dialog";
import { ComposerContextId } from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import { useNavigation } from "@react-navigation/native";
import { useEffect, useMemo, useRef, useState } from "react";
-import { Alert } from "react-native";
import type { EnvironmentId } from "@t3tools/contracts";
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
@@ -107,20 +107,20 @@ export function ComposerEditor({
return;
}
if (!insertComposerDraftContext(draftKey, result, insertion)) {
- Alert.alert(
+ Dialog.alert(
"Could not paste context",
"Remove some attachments or context items from the draft, then paste again.",
);
return;
}
if (result.failures.length > 0)
- Alert.alert(
+ Dialog.alert(
"Some attachments could not be copied",
"Reconnect to the source environment and copy them again. References without their files are marked unavailable.",
);
} catch (error) {
if (!controller.signal.aborted)
- Alert.alert(
+ Dialog.alert(
"Could not paste context",
error instanceof Error ? error.message : "Try copying again.",
);
diff --git a/apps/mobile/src/components/CopyTextButton.tsx b/apps/mobile/src/components/CopyTextButton.tsx
index d946d07bd93..a34e7156a0d 100644
--- a/apps/mobile/src/components/CopyTextButton.tsx
+++ b/apps/mobile/src/components/CopyTextButton.tsx
@@ -1,6 +1,7 @@
+import * as Dialog from "./Dialog";
import { SymbolView } from "../components/AppSymbol";
import { memo, useEffect, useRef, useState } from "react";
-import { Alert, Pressable, type ColorValue } from "react-native";
+import { Pressable, type ColorValue } from "react-native";
import { tryCopyTextWithHaptic } from "../lib/copyTextWithHaptic";
@@ -43,11 +44,11 @@ export const CopyTextButton = memo(function CopyTextButton(props: {
if (props.onCopy) await props.onCopy();
else if (!(await tryCopyTextWithHaptic(props.text))) {
// A refused clipboard write is the common failure, and silence reads as success.
- Alert.alert("Could not copy", "Try again.");
+ Dialog.alert("Could not copy", "Try again.");
return;
}
} catch {
- Alert.alert("Could not copy", "Try again.");
+ Dialog.alert("Could not copy", "Try again.");
return;
}
setCopied(true);
diff --git a/apps/mobile/src/components/FilePreview.ios.tsx b/apps/mobile/src/components/FilePreview.ios.tsx
index 26780f8bffd..9357e491a87 100644
--- a/apps/mobile/src/components/FilePreview.ios.tsx
+++ b/apps/mobile/src/components/FilePreview.ios.tsx
@@ -1,6 +1,6 @@
+import * as Dialog from "./Dialog";
import { requireNativeModule } from "expo";
import { useEffect, useEffectEvent, useId } from "react";
-import { Alert } from "react-native";
import type { ResolvedFilePreviewSource } from "./FilePreviewModal.types";
@@ -30,7 +30,7 @@ function NativeFilePreview(props: {
const onRequestClose = useEffectEvent(props.onRequestClose);
const onOpenError = useEffectEvent((error: unknown) => {
if (props.onOpenError) props.onOpenError(error);
- else Alert.alert("Could not open preview", "The file could not be loaded. Please try again.");
+ else Dialog.alert("Could not open preview", "The file could not be loaded. Please try again.");
});
useEffect(() => {
diff --git a/apps/mobile/src/components/FilePreview.tsx b/apps/mobile/src/components/FilePreview.tsx
index dd5317aca92..0316de9c6d3 100644
--- a/apps/mobile/src/components/FilePreview.tsx
+++ b/apps/mobile/src/components/FilePreview.tsx
@@ -1,5 +1,6 @@
+import * as Dialog from "./Dialog";
import { useEffect, useEffectEvent } from "react";
-import { Alert, Modal, Pressable, View } from "react-native";
+import { Modal, Pressable, View } from "react-native";
import ImageViewing from "react-native-image-viewing";
import { openAttachmentInViewer } from "../lib/attachmentDownload";
@@ -17,7 +18,7 @@ function DocumentPreview(props: {
const onOpenError = useEffectEvent((error: unknown) => {
if (props.onOpenError) props.onOpenError(error);
else
- Alert.alert(
+ Dialog.alert(
"Could not open document",
"A compatible viewer must be installed. Check your connection and try again.",
);
diff --git a/apps/mobile/src/components/FilePreviewModal.tsx b/apps/mobile/src/components/FilePreviewModal.tsx
index 45aafe36b1b..f0550488a85 100644
--- a/apps/mobile/src/components/FilePreviewModal.tsx
+++ b/apps/mobile/src/components/FilePreviewModal.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "./Dialog";
import { useNavigation } from "@react-navigation/native";
import {
useCallback,
@@ -8,7 +9,7 @@ import {
useSyncExternalStore,
useMemo,
} from "react";
-import { Alert, Keyboard } from "react-native";
+import { Keyboard } from "react-native";
import { loadLocalAttachmentPreview } from "../lib/localAttachmentPreview";
import { useRefreshAssetUrl } from "../state/assets";
@@ -44,7 +45,7 @@ function PreviewItemResolver(props: {
const onRequestClose = useEffectEvent(props.onRequestClose);
const onResolutionError = useEffectEvent((error: unknown, fallbackMessage: string) => {
if (props.onOpenError) props.onOpenError(error);
- else Alert.alert("Could not open preview", fallbackMessage);
+ else Dialog.alert("Could not open preview", fallbackMessage);
onRequestClose();
});
useEffect(() => Keyboard.dismiss(), []);
diff --git a/apps/mobile/src/components/PermissionUpdateNotice.tsx b/apps/mobile/src/components/PermissionUpdateNotice.tsx
index 55f2de0638f..95c22cf0630 100644
--- a/apps/mobile/src/components/PermissionUpdateNotice.tsx
+++ b/apps/mobile/src/components/PermissionUpdateNotice.tsx
@@ -1,9 +1,9 @@
+import * as Dialog from "./Dialog";
import { useAtomValue } from "@effect/atom-react";
import { sessionHasLegacyPermissions } from "@t3tools/contracts";
import { Atom } from "effect/reactivity";
import * as SecureStore from "expo-secure-store";
import { useEffect, useMemo, useRef, useState } from "react";
-import { Alert } from "react-native";
import { useEnvironments } from "../state/environments";
import { environmentSession } from "../state/session";
@@ -73,7 +73,7 @@ export function PermissionUpdateNotice() {
// Remember for this launch even if persistent storage is unavailable.
});
};
- Alert.alert(
+ Dialog.alert(
`Permissions have changed for ${environment.label}`,
"This connection still uses the old permissions, so some actions may no longer be available. Pair again using a new link with the permissions you need.",
[{ text: "Got it", onPress: dismiss }],
diff --git a/apps/mobile/src/components/VideoPreviewModal.ios.tsx b/apps/mobile/src/components/VideoPreviewModal.ios.tsx
index 4cae4d30db4..7ea9c192b7a 100644
--- a/apps/mobile/src/components/VideoPreviewModal.ios.tsx
+++ b/apps/mobile/src/components/VideoPreviewModal.ios.tsx
@@ -1,7 +1,8 @@
+import * as Dialog from "./Dialog";
import { useIsFocused } from "@react-navigation/native";
import { requireNativeModule } from "expo";
import { useEffect, useEffectEvent, useId, useState } from "react";
-import { Alert, Keyboard } from "react-native";
+import { Keyboard } from "react-native";
import { loadLocalAttachmentPreview } from "../lib/localAttachmentPreview";
import { fullscreenVideoClosed, fullscreenVideoOpened } from "../lib/videoAudioSession";
@@ -61,7 +62,7 @@ function NativeVideoPreview(props: {
}, [playbackUrl, resolvedUrl]);
useEffect(() => {
if (!loadError) return;
- Alert.alert("Could not open video", loadError);
+ Dialog.alert("Could not open video", loadError);
onRequestClose();
}, [loadError]);
@@ -93,7 +94,7 @@ function NativeVideoPreview(props: {
if (controller.signal.aborted) return;
// AVKit gives no retry, so re-mint now; the cached URL may simply have expired.
if (ready) void refreshAssetUrl();
- Alert.alert(
+ Dialog.alert(
"Could not open video",
ready
? "This video couldn't be loaded or played. Check the connection, or touch and hold the video to save or share the original."
diff --git a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
index 61f24fe5678..0753c542302 100644
--- a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
+++ b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import {
deviceToolVersionLabels,
deviceToolUpdateOwnership,
@@ -9,7 +10,7 @@ import * as Cause from "effect/Cause";
import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react";
import * as Haptics from "expo-haptics";
import { Accelerometer } from "expo-sensors";
-import { Alert, AppState, BackHandler, Pressable, StatusBar, View } from "react-native";
+import { AppState, BackHandler, Pressable, StatusBar, View } from "react-native";
import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -139,7 +140,7 @@ function DevicePreviewScreen({
},
});
if (result._tag === "Failure") {
- Alert.alert("Could not shut down device", String(Cause.squash(result.cause)));
+ Dialog.alert("Could not shut down device", String(Cause.squash(result.cause)));
}
} finally {
setShuttingDown(false);
@@ -177,7 +178,7 @@ function DevicePreviewScreen({
title: "Device tool versions",
icon: "info.circle",
onPress: () =>
- Alert.alert(
+ Dialog.alert(
"Device tool versions",
deviceToolUpdateOwnership +
"\n\n" +
diff --git a/apps/mobile/src/features/home/usePendingTaskListActions.ts b/apps/mobile/src/features/home/usePendingTaskListActions.ts
index dcf127ccae2..ee4ca77819d 100644
--- a/apps/mobile/src/features/home/usePendingTaskListActions.ts
+++ b/apps/mobile/src/features/home/usePendingTaskListActions.ts
@@ -1,6 +1,6 @@
+import * as Dialog from "../../components/Dialog";
import { useNavigation } from "@react-navigation/native";
import { useCallback } from "react";
-import { Alert } from "react-native";
import { removeThreadOutboxMessage } from "../../state/thread-outbox-removal";
import { clearComposerDraftContent } from "../../state/use-composer-drafts";
@@ -31,7 +31,7 @@ export function usePendingTaskListActions(): {
const confirmDeletePendingTask = useCallback((pendingTask: PendingNewTask) => {
if (pendingTask.kind === "draft") {
- Alert.alert("Discard draft?", `“${pendingTask.title}” will be removed.`, [
+ Dialog.alert("Discard draft?", `“${pendingTask.title}” will be removed.`, [
{ text: "Cancel", style: "cancel" },
{
text: "Discard",
@@ -48,7 +48,7 @@ export function usePendingTaskListActions(): {
]);
return;
}
- Alert.alert(
+ Dialog.alert(
"Delete pending task?",
`“${pendingTask.title}” has not been sent yet and will be removed from the outbox.`,
[
@@ -63,7 +63,7 @@ export function usePendingTaskListActions(): {
void removeThreadOutboxMessage(pendingTask.message)
.then(() => releaseEditingQueuedMessage(pendingTask.message.messageId))
.catch((error) => {
- Alert.alert(
+ Dialog.alert(
"Could not delete pending task",
error instanceof Error ? error.message : "The pending task could not be removed.",
);
diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.ts
index b702d467efd..a73837447fa 100644
--- a/apps/mobile/src/features/home/useThreadListActions.test.ts
+++ b/apps/mobile/src/features/home/useThreadListActions.test.ts
@@ -44,6 +44,8 @@ vi.mock("expo-haptics", () => ({
ImpactFeedbackStyle: { Light: "light" },
}));
vi.mock("../../components/Dialog", () => ({
+ alert: (title: string, _message: string, buttons?: { text: string; onPress?: () => void }[]) =>
+ state.alerts.push({ title, buttons }),
confirm: (dialog: { onConfirm: () => void }) => state.dialogs.push(dialog),
}));
vi.mock("../archive/useArchivedThreadSnapshots", () => ({
diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts
index 889484418a4..126e01a71cc 100644
--- a/apps/mobile/src/features/home/useThreadListActions.ts
+++ b/apps/mobile/src/features/home/useThreadListActions.ts
@@ -5,7 +5,6 @@ import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Haptics from "expo-haptics";
import { useCallback, useRef } from "react";
-import { Alert } from "react-native";
import { withThreadDismissal } from "./thread-dismissal";
import * as Dialog from "../../components/Dialog";
@@ -112,7 +111,7 @@ function actionFailureTitle(action: ThreadListAction): string {
function checkThreadOperationPermission(thread: EnvironmentThreadShell, title: string): boolean {
if (readEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope)) return true;
- Alert.alert(title, "This connection cannot change threads.");
+ Dialog.alert(title, "This connection cannot change threads.");
return false;
}
@@ -142,7 +141,7 @@ function useThreadActionExecutor(
(action === "settle" || action === "unsettle") &&
!environmentSupportsSettlement(thread.environmentId)
) {
- Alert.alert(
+ Dialog.alert(
actionFailureTitle(action),
"This environment's server does not support settling yet. Update the server to use Settle.",
);
@@ -151,7 +150,7 @@ function useThreadActionExecutor(
// Archive keeps its original, narrower guard: never interrupt a
// thread mid-turn.
if (action === "archive" && !threadCanArchive(thread.runtime)) {
- Alert.alert(
+ Dialog.alert(
actionFailureTitle(action),
"This thread is working. Interrupt it first, then try again.",
);
@@ -182,7 +181,7 @@ function useThreadActionExecutor(
(result) => result._tag === "Success",
);
if (result._tag === "Failure") {
- Alert.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
+ Dialog.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
return false;
}
// Settled threads stay in the live shell stream; only the archive
@@ -286,14 +285,14 @@ export function useThreadListActions(): {
snoozeInFlightThreadKeys.current.add(key);
try {
if (!environmentSupportsSnooze(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not snooze thread",
"This environment's server does not support snoozing yet. Update the server to use Snooze.",
);
return false;
}
if (!canSnooze(thread, { now: new Date().toISOString() })) {
- Alert.alert(
+ Dialog.alert(
"Could not snooze thread",
thread.hasPendingApprovals ||
thread.hasPendingUserInput ||
@@ -319,7 +318,7 @@ export function useThreadListActions(): {
);
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not snooze thread",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -344,7 +343,7 @@ export function useThreadListActions(): {
snoozeInFlightThreadKeys.current.add(key);
try {
if (!environmentSupportsSnooze(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not wake thread",
"This environment's server does not support snoozing yet. Update the server to wake this thread.",
);
@@ -363,7 +362,7 @@ export function useThreadListActions(): {
);
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not wake thread",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -386,7 +385,7 @@ export function useThreadListActions(): {
async (thread: EnvironmentThreadShell) => {
if (!checkThreadOperationPermission(thread, "Could not pin thread")) return false;
if (!environmentSupportsPinning(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not pin thread",
"This environment's server does not support pinning yet. Update the server to use Pin.",
);
@@ -411,7 +410,7 @@ export function useThreadListActions(): {
});
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not pin thread",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -427,7 +426,7 @@ export function useThreadListActions(): {
async (thread: EnvironmentThreadShell) => {
if (!checkThreadOperationPermission(thread, "Could not unpin thread")) return false;
if (!environmentSupportsPinning(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not unpin thread",
"This environment's server does not support pinning yet. Update the server to use Pin.",
);
@@ -440,7 +439,7 @@ export function useThreadListActions(): {
});
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not unpin thread",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -455,7 +454,7 @@ export function useThreadListActions(): {
const setThreadAutoSettle = useCallback(
async (thread: EnvironmentThreadShell, enabled: boolean) => {
if (!environmentSupportsAutoSettleOptOut(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not update auto-settle",
"This environment's server does not support turning auto-settle off per thread yet. Update the server to use it.",
);
@@ -468,7 +467,7 @@ export function useThreadListActions(): {
});
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not update auto-settle",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -491,7 +490,7 @@ export function useThreadListActions(): {
return false;
}
if (!environmentSupportsTitleRegeneration(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not regenerate title",
"This environment's server does not support title regeneration yet. Update the server to regenerate thread titles.",
);
@@ -507,7 +506,7 @@ export function useThreadListActions(): {
});
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not regenerate title",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -527,7 +526,7 @@ export function useThreadListActions(): {
const commit = (title: string) => {
const resolution = resolveThreadTitleRename({ title, originalTitle: thread.title });
if (resolution.action === "reject-empty") {
- Alert.alert("Could not rename thread", "Thread title cannot be empty.");
+ Dialog.alert("Could not rename thread", "Thread title cannot be empty.");
return;
}
if (resolution.action === "noop") return;
@@ -538,7 +537,7 @@ export function useThreadListActions(): {
}).then((result) => {
if (result._tag === "Success") return;
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not rename thread",
error instanceof Error && error.message.trim().length > 0
? error.message
@@ -597,7 +596,7 @@ export function useThreadListActions(): {
: capabilities?.threadActiveReorder === true;
};
if (!supportsReorder(thread.environmentId)) {
- Alert.alert(
+ Dialog.alert(
"Could not move thread",
"This environment's server does not support reordering these threads. Update the server to arrange them.",
);
@@ -674,7 +673,7 @@ export function useThreadListActions(): {
input: { threadId: thread.id, ...(orderKey === undefined ? {} : { orderKey }) },
});
if (result._tag === "Failure") {
- Alert.alert("Could not pin thread", String(Cause.squash(result.cause)));
+ Dialog.alert("Could not pin thread", String(Cause.squash(result.cause)));
return false;
}
} else {
@@ -701,7 +700,7 @@ export function useThreadListActions(): {
});
if (result._tag === "Failure") {
const error = Cause.squash(result.cause);
- Alert.alert(
+ Dialog.alert(
"Could not move thread",
error instanceof Error && error.message.trim().length > 0
? error.message
diff --git a/apps/mobile/src/features/projects/AddProjectScreen.tsx b/apps/mobile/src/features/projects/AddProjectScreen.tsx
index 4828a4c0f09..468f54e3e63 100644
--- a/apps/mobile/src/features/projects/AddProjectScreen.tsx
+++ b/apps/mobile/src/features/projects/AddProjectScreen.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { AppActivityIndicator } from "../../components/AppActivityIndicator";
import { NavigationRow } from "../../components/NavigationRow";
import { SettingsScreen } from "../settings/components/SettingsScreen";
@@ -56,7 +57,7 @@ import {
import { CommonActions, StackActions, useNavigation } from "@react-navigation/native";
import { SymbolView } from "../../components/AppSymbol";
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
-import { Platform, Alert, Pressable, View } from "react-native";
+import { Platform, Pressable, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import * as Arr from "effect/Array";
import * as Cause from "effect/Cause";
@@ -718,7 +719,7 @@ function useCreateProject(environment: EnvironmentOption | null) {
!canCreateProjectInEnvironment(environment.connectionState) ||
!readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope)
) {
- Alert.alert(
+ Dialog.alert(
"Project not added",
`This connection cannot add projects right now. Any existing files remain at ${workspaceRoot}.`,
);
@@ -731,7 +732,7 @@ function useCreateProject(environment: EnvironmentOption | null) {
path: workspaceRoot,
});
if (existing) {
- Alert.alert("Project already exists", existing.title);
+ Dialog.alert("Project already exists", existing.title);
navigation.dispatch(
CommonActions.reset({
index: 0,
@@ -1092,7 +1093,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
}
const { projectId, workspaceRoot, commitError } = result.value;
if (commitError !== undefined) {
- Alert.alert("Created without a first commit", commitError);
+ Dialog.alert("Created without a first commit", commitError);
}
if (publishes && publishTarget !== null) {
void publishRepository({
@@ -1105,7 +1106,7 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
},
}).then((publishResult) => {
if (AsyncResult.isFailure(publishResult)) {
- Alert.alert(
+ Dialog.alert(
`Could not create the ${publishTarget.definition.label} repository`,
errorMessage(Cause.squash(publishResult.cause)),
);
diff --git a/apps/mobile/src/features/prompt-links/prompt-link-actions.ts b/apps/mobile/src/features/prompt-links/prompt-link-actions.ts
index c46e85afc07..f39aa6f096b 100644
--- a/apps/mobile/src/features/prompt-links/prompt-link-actions.ts
+++ b/apps/mobile/src/features/prompt-links/prompt-link-actions.ts
@@ -1,5 +1,5 @@
+import * as Dialog from "../../components/Dialog";
import { buildNewThreadLink, type LinkedPrompt } from "@t3tools/shared/promptLinks";
-import { Alert } from "react-native";
import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import {
@@ -11,7 +11,7 @@ import { linkedThreadDraftAction } from "./prompt-link-model";
/** Shows the one notice a prompt link owes the user, built with `promptLinkNotice`. */
export function showPromptLinkNotice(notice: string): void {
- Alert.alert("Prompt from a link", notice);
+ Dialog.alert("Prompt from a link", notice);
}
/**
@@ -27,7 +27,7 @@ export async function applyLinkedPromptToThreadDraft(
try {
await waitForComposerDraftsLoaded();
} catch {
- Alert.alert("Could not open link", "Drafts could not be loaded, so the prompt was not added.");
+ Dialog.alert("Could not open link", "Drafts could not be loaded, so the prompt was not added.");
return;
}
const action = linkedThreadDraftAction(getComposerDraftSnapshot(draftKey).text, prompt.text);
@@ -36,7 +36,7 @@ export async function applyLinkedPromptToThreadDraft(
showPromptLinkNotice(notice);
return;
}
- Alert.alert("Linked prompt ready. Replace draft?", notice, [
+ Dialog.alert("Linked prompt ready. Replace draft?", notice, [
{ text: "Keep mine", style: "cancel" },
{ text: "Replace", onPress: () => setComposerDraftText(draftKey, prompt.text) },
]);
@@ -45,6 +45,6 @@ export async function applyLinkedPromptToThreadDraft(
/** Copies a shareable link that opens a new task with this prompt. Used by sent user messages. */
export async function copyPromptLink(prompt: string): Promise<void> {
if (!(await tryCopyTextWithHaptic(buildNewThreadLink({ prompt }), { target: "prompt link" }))) {
- Alert.alert("Could not copy", "Try again.");
+ Dialog.alert("Could not copy", "Try again.");
}
}
diff --git a/apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts b/apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts
index a457b5d8102..4e5fdd6169a 100644
--- a/apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts
+++ b/apps/mobile/src/features/prompt-links/usePromptLinkResolver.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { StackActions, useNavigation } from "@react-navigation/native";
import { availableScratchWorkspaceRoot } from "@t3tools/client-runtime/operations/projects";
import {
@@ -18,7 +19,6 @@ import {
type PromptLinkRepository,
} from "@t3tools/shared/promptLinks";
import { useEffect, useEffectEvent, useRef } from "react";
-import { Alert } from "react-native";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { useServerConfigs, useThreadShells } from "../../state/entities";
@@ -103,7 +103,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
try {
await waitForComposerDraftsLoaded();
} catch {
- Alert.alert(
+ Dialog.alert(
"Could not open link",
"Drafts could not be loaded, so the prompt was not added.",
);
@@ -171,7 +171,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
.map((environment) => environment.environmentId),
);
if (environmentId === null) {
- Alert.alert(
+ Dialog.alert(
"Could not start without a project",
"No connected environment offers threads without a project.",
);
@@ -181,7 +181,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
if (result._tag === "Failure") {
if (!isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
- Alert.alert(
+ Dialog.alert(
"Could not start without a project",
error instanceof Error
? error.message
@@ -200,7 +200,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
const environmentId =
flow.selectedEnvironmentId ?? connectedEnvironments[0]?.environmentId ?? null;
if (environmentId === null) {
- Alert.alert("Could not clone", "Connect an environment first.");
+ Dialog.alert("Could not clone", "Connect an environment first.");
return;
}
// Only a tracked clone opens a draft the prompt can ride into; older servers do not.
@@ -236,7 +236,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
const resolveLink = useEffectEvent((linkSearch: string) => {
const parsed = parseNewThreadLink(linkSearch);
if (!parsed.ok) {
- Alert.alert("Could not open link", parsed.error);
+ Dialog.alert("Could not open link", parsed.error);
return;
}
const link = parsed.value;
@@ -289,7 +289,7 @@ export function usePromptLinkResolver(params: Readonly<Record<string, unknown>>
void openProjectDraft(project, request);
return;
}
- Alert.alert(`You don't have ${promptLinkRepositoryName(repository)}`, undefined, [
+ Dialog.alert(`You don't have ${promptLinkRepositoryName(repository)}`, undefined, [
{ text: "Cancel", style: "cancel" },
...(request.prompt
? [{ text: "Use without project", onPress: () => void openScratchDraft(request) }]
diff --git a/apps/mobile/src/features/prompt-links/useThreadPromptLink.ts b/apps/mobile/src/features/prompt-links/useThreadPromptLink.ts
index 87c0b46dd14..23b8068f7fb 100644
--- a/apps/mobile/src/features/prompt-links/useThreadPromptLink.ts
+++ b/apps/mobile/src/features/prompt-links/useThreadPromptLink.ts
@@ -1,7 +1,7 @@
+import * as Dialog from "../../components/Dialog";
import { useNavigation } from "@react-navigation/native";
import { parseThreadLinkPrompt } from "@t3tools/shared/promptLinks";
import { useEffect, useRef } from "react";
-import { Alert } from "react-native";
import { applyLinkedPromptToThreadDraft } from "./prompt-link-actions";
import {
@@ -33,7 +33,7 @@ export function useThreadPromptLink(
navigation.setParams(clearedPromptLinkParams(THREAD_LINK_KEYS));
const parsed = parseThreadLinkPrompt(search);
if (!parsed.ok) {
- Alert.alert("Could not open link", parsed.error);
+ Dialog.alert("Could not open link", parsed.error);
return;
}
if (parsed.value === null) return;
diff --git a/apps/mobile/src/features/pull-requests/usePullRequestAction.ts b/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
index 2b0193ca308..756a1c0bebb 100644
--- a/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
+++ b/apps/mobile/src/features/pull-requests/usePullRequestAction.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { useAtomRefresh } from "@effect/atom-react";
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import type {
@@ -6,7 +7,6 @@ import type {
PullRequestUpdateMethod,
} from "@t3tools/contracts";
import { useRef, useState } from "react";
-import { Alert } from "react-native";
import { composerPullRequests } from "../../state/pull-requests";
import { useAtomCommand } from "../../state/use-atom-command";
import { canPerformPullRequestAction } from "./pullRequestActions";
@@ -37,7 +37,7 @@ export function usePullRequestAction(params: PullRequestParams, pr: PullRequestD
refreshDetail();
refreshActivity();
} catch (cause) {
- Alert.alert(
+ Dialog.alert(
"Couldn't update this pull request",
cause instanceof Error ? cause.message : "Try again.",
);
@@ -47,7 +47,7 @@ export function usePullRequestAction(params: PullRequestParams, pr: PullRequestD
}
};
const confirm = (action: PullRequestAction, title: string, message: string) =>
- Alert.alert(title, message, [
+ Dialog.alert(title, message, [
{ text: "Cancel", style: "cancel" },
{
text: title,
diff --git a/apps/mobile/src/features/pull-requests/usePullRequestListActions.ts b/apps/mobile/src/features/pull-requests/usePullRequestListActions.ts
index 28732e4440c..12261c4d505 100644
--- a/apps/mobile/src/features/pull-requests/usePullRequestListActions.ts
+++ b/apps/mobile/src/features/pull-requests/usePullRequestListActions.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { RegistryContext, useAtomValue } from "@effect/atom-react";
import { useNavigation } from "@react-navigation/native";
import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
@@ -5,7 +6,7 @@ import type { EnvironmentId, PullRequestAction } from "@t3tools/contracts";
import * as Clipboard from "expo-clipboard";
import { Atom } from "effect/reactivity";
import { use, useCallback, useMemo, useRef, useState } from "react";
-import { Alert, Linking, Platform, Share } from "react-native";
+import { Linking, Platform, Share } from "react-native";
import type { MenuProps } from "../../components/Menu.types";
import { composerPullRequests } from "../../state/pull-requests";
import { useAtomCommand } from "../../state/use-atom-command";
@@ -97,7 +98,7 @@ export function usePullRequestListActions(
: { isDraft: action === "draft" },
);
} catch (cause) {
- Alert.alert(
+ Dialog.alert(
"Couldn't update this pull request",
cause instanceof Error ? cause.message : "Try again.",
);
@@ -140,7 +141,7 @@ export function usePullRequestListActions(
(value) => value === action,
);
if (!supported) return;
- Alert.alert(`${PR_ACTION_LABELS[supported]}?`, `#${entry.number} · ${entry.title}`, [
+ Dialog.alert(`${PR_ACTION_LABELS[supported]}?`, `#${entry.number} · ${entry.title}`, [
{ text: "Cancel", style: "cancel" },
{
text: PR_ACTION_LABELS[supported],
diff --git a/apps/mobile/src/features/pull-requests/usePullRequestThreads.ts b/apps/mobile/src/features/pull-requests/usePullRequestThreads.ts
index 8bd406962dd..9002f3b5372 100644
--- a/apps/mobile/src/features/pull-requests/usePullRequestThreads.ts
+++ b/apps/mobile/src/features/pull-requests/usePullRequestThreads.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { useNavigation, useNavigationState, useRoute } from "@react-navigation/native";
import { threadPullRequestLinkMode } from "@t3tools/client-runtime/thread-pull-request-compatibility";
import {
@@ -11,7 +12,7 @@ import { formatComposerContextReference } from "@t3tools/shared/composerContextR
import { parseChangeRequestUrl } from "@t3tools/shared/changeRequestUrl";
import { normalizeThreadPullRequestKey } from "@t3tools/shared/threadPullRequests";
import { useRef, useState } from "react";
-import { Alert, Platform } from "react-native";
+import { Platform } from "react-native";
import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
import { pullRequestComposerContext } from "../../lib/composerContext";
import { scopedThreadKey } from "../../lib/scopedEntities";
@@ -150,7 +151,7 @@ export function usePullRequestThreads(
params: { draftId: draftKey, title: `Ask about #${pr.number}` },
});
} catch (cause) {
- Alert.alert("Couldn't open a thread", cause instanceof Error ? cause.message : "Try again.");
+ Dialog.alert("Couldn't open a thread", cause instanceof Error ? cause.message : "Try again.");
} finally {
pending.current = false;
setBusy(false);
diff --git a/apps/mobile/src/features/sharing/IncomingShareProvider.tsx b/apps/mobile/src/features/sharing/IncomingShareProvider.tsx
index e25a3d5b92b..15468f4ff15 100644
--- a/apps/mobile/src/features/sharing/IncomingShareProvider.tsx
+++ b/apps/mobile/src/features/sharing/IncomingShareProvider.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import Constants from "expo-constants";
import * as Crypto from "expo-crypto";
import { PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
@@ -9,7 +10,7 @@ import {
type SharePayload,
} from "expo-sharing";
import React, { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
-import { Alert, AppState, Platform } from "react-native";
+import { AppState, Platform } from "react-native";
import {
buildIncomingShareDraft,
@@ -278,7 +279,7 @@ export function IncomingShareProvider(props: React.PropsWithChildren) {
if (!error) {
return;
}
- Alert.alert("Could not import shared content", error.message, [
+ Dialog.alert("Could not import shared content", error.message, [
{ text: "Dismiss", style: "cancel", onPress: () => setError(null) },
{
text: "Retry",
diff --git a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx b/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
index 159ea8d9f05..c2e327e443f 100644
--- a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
+++ b/apps/mobile/src/features/terminal/TerminalContextSheet.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import {
ComposerContextId,
COMPOSER_CONTEXT_TERMINAL_TEXT_MAX_CHARS,
@@ -6,7 +7,7 @@ import {
} from "@t3tools/contracts";
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
import { useState } from "react";
-import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
+import { Platform, Pressable, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { REVIEW_MONO_FONT_FAMILY } from "../review/reviewDiffRendering";
import { AppText as Text } from "../../components/AppText";
@@ -50,7 +51,7 @@ export function TerminalContextSheet(props: {
context: { version: 1, records: [record] },
})
) {
- Alert.alert("Too many context items", "Remove some context from the draft and try again.");
+ Dialog.alert("Too many context items", "Remove some context from the draft and try again.");
return;
}
props.onAttach();
diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx
index 143db0060ff..3a9261100d1 100644
--- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx
+++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import {
AuthTerminalReadScope,
AuthTerminalOperateScope,
@@ -12,7 +13,7 @@ import { AppBar } from "../../components/AppBar";
import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { Alert, Platform, Pressable, View } from "react-native";
+import { Platform, Pressable, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppText as Text } from "../../components/AppText";
import { TerminalContextSheet } from "./TerminalContextSheet";
@@ -1283,7 +1284,8 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps)
captureRequest={captureRequest}
onCapture={(text) => {
if (text.trim()) setCapturedOutput(text);
- else Alert.alert("No terminal output", "There is no visible output to attach.");
+ else
+ Dialog.alert("No terminal output", "There is no visible output to attach.");
}}
onInput={handleInput}
onResize={handleResize}
diff --git a/apps/mobile/src/features/threads/use-composer-command-menu.ts b/apps/mobile/src/features/threads/use-composer-command-menu.ts
index cb702af0605..b9b9fc3eaa2 100644
--- a/apps/mobile/src/features/threads/use-composer-command-menu.ts
+++ b/apps/mobile/src/features/threads/use-composer-command-menu.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import type {
EnvironmentId,
ProjectId,
@@ -14,7 +15,6 @@ import {
COMPOSER_CONTEXT_MAX_RECORDS,
PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS,
} from "@t3tools/contracts";
-import { Alert } from "react-native";
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
import { pullRequestComposerContext, threadComposerContext } from "../../lib/composerContext";
import { uuidv4 } from "../../lib/uuid";
@@ -564,7 +564,7 @@ export function useComposerCommandMenu({
const existing = getComposerDraftSnapshot(ownerKey).context?.records ?? [];
const alreadyAttached = existing.some((entry) => entry.contextId === record.contextId);
if (!alreadyAttached && existing.length >= COMPOSER_CONTEXT_MAX_RECORDS) {
- Alert.alert(
+ Dialog.alert(
"Too many context items",
"Remove some context from the draft and try again.",
);
@@ -599,7 +599,7 @@ export function useComposerCommandMenu({
(getComposerDraftSnapshot(ownerKey).context?.records.length ?? 0) >=
COMPOSER_CONTEXT_MAX_RECORDS
) {
- Alert.alert(
+ Dialog.alert(
"Too many context items",
"Remove some context from the draft and try again.",
);
diff --git a/apps/mobile/src/features/threads/useFileChipShare.ts b/apps/mobile/src/features/threads/useFileChipShare.ts
index 587aa8ad957..763ee0fc084 100644
--- a/apps/mobile/src/features/threads/useFileChipShare.ts
+++ b/apps/mobile/src/features/threads/useFileChipShare.ts
@@ -1,8 +1,8 @@
+import * as Dialog from "../../components/Dialog";
import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
import * as Option from "effect/Option";
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
-import { Alert } from "react-native";
import { downloadAndShareAttachment } from "../../lib/attachmentDownload";
import { assetEnvironment } from "../../state/assets";
@@ -52,7 +52,7 @@ export function useFileChipShare(
})()
.catch((error: unknown) => {
if (!request.signal.aborted) {
- Alert.alert(
+ Dialog.alert(
"Could not share file",
error instanceof Error ? error.message : "Try again.",
);
diff --git a/apps/mobile/src/features/updates/app-updates.ts b/apps/mobile/src/features/updates/app-updates.ts
index 5f8a110beaf..42f06b1d388 100644
--- a/apps/mobile/src/features/updates/app-updates.ts
+++ b/apps/mobile/src/features/updates/app-updates.ts
@@ -446,9 +446,9 @@ async function applyDeferredAppUpdateInstall(
}
async function defaultConfirmInstallNow(): Promise<boolean> {
- const { Alert } = await import("react-native");
+ const Dialog = await import("../../components/Dialog");
return new Promise<boolean>((resolve) => {
- Alert.alert(
+ Dialog.alert(
"Update ready",
"A new version has been downloaded and installs automatically the next time you leave the app. Install it now instead?",
[
diff --git a/apps/mobile/src/features/usage/UsageLimitsSection.tsx b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
index 0fb8fb9f269..7de23d36e60 100644
--- a/apps/mobile/src/features/usage/UsageLimitsSection.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
@@ -1,3 +1,4 @@
+import * as Dialog from "../../components/Dialog";
import { useAtomValue } from "@effect/atom-react";
import {
AuthProvidersManageScope,
@@ -19,7 +20,7 @@ import {
} from "@t3tools/shared/usageLimits";
import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from "react";
import { refreshUsageLimits } from "@t3tools/client-runtime/state/usage";
-import { Alert, Linking, Pressable, View } from "react-native";
+import { Linking, Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { ProviderIcon } from "../../components/ProviderIcon";
@@ -246,7 +247,7 @@ export function ResetCredits(props: {
const confirm = () => {
if (!readEnvironmentScope(environmentId, AuthProvidersManageScope)) return;
- Alert.alert(
+ Dialog.alert(
"Use a reset credit?",
"This redeems one credit on your account and clears the current rate-limit windows. It cannot be undone.",
[
diff --git a/apps/mobile/src/lib/attachmentDocument.ts b/apps/mobile/src/lib/attachmentDocument.ts
index b371523a89c..377b175216c 100644
--- a/apps/mobile/src/lib/attachmentDocument.ts
+++ b/apps/mobile/src/lib/attachmentDocument.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../components/Dialog";
import { filePreviewDelimiter, parseDelimitedPreview } from "@t3tools/shared/delimitedPreview";
import type { EnvironmentId } from "@t3tools/contracts";
import { readFilePreviewResponse } from "@t3tools/client-runtime/file-preview";
@@ -5,7 +6,6 @@ import { filePreviewKind, FILE_TEXT_PREVIEW_MAX_BYTES } from "@t3tools/shared/fi
import { fetch } from "expo/fetch";
import { File } from "expo-file-system";
import { useEffect, useMemo, useRef, useState } from "react";
-import { Alert } from "react-native";
import type { FileBackedComposerAttachment } from "./composerImages";
import { loadLocalAttachmentPreview } from "./localAttachmentPreview";
@@ -179,7 +179,7 @@ export function useAttachmentDocument(input: {
else await downloadAndShareAttachment({ ...request, url: (await refresh()) ?? uri });
} catch (cause) {
if (controller.signal.aborted) return;
- Alert.alert(
+ Dialog.alert(
"Could not share file",
cause instanceof Error ? cause.message : "Please try again.",
);
diff --git a/apps/mobile/src/state/mediaActions.ts b/apps/mobile/src/state/mediaActions.ts
index 4a6d52d1877..05216aef4b2 100644
--- a/apps/mobile/src/state/mediaActions.ts
+++ b/apps/mobile/src/state/mediaActions.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../components/Dialog";
import type { MediaActionsSource } from "../lib/mediaActionsSource";
import { useNavigation } from "@react-navigation/native";
import type { MediaActionId } from "@t3tools/client-runtime/media-actions";
@@ -11,7 +12,6 @@ import { normalizeNativeMarkdownUrl } from "../lib/markdownLinks";
import * as Option from "effect/Option";
import { AsyncResult } from "effect/reactivity";
import { useEffect, useRef, useState } from "react";
-import { Alert } from "react-native";
import { useRefreshAssetUrl } from "./assets";
import { appAtomRegistry } from "./atom-registry";
@@ -83,7 +83,7 @@ export function useMediaActions(source: MediaActionsSource | undefined, onOpenFi
})()
.catch((error: unknown) => {
if (!request.signal.aborted) {
- Alert.alert(
+ Dialog.alert(
"Could not share file",
error instanceof Error ? error.message : "Try again.",
);
diff --git a/apps/mobile/src/state/use-remote-environment-registry.ts b/apps/mobile/src/state/use-remote-environment-registry.ts
index d2d654b05f1..76dab709418 100644
--- a/apps/mobile/src/state/use-remote-environment-registry.ts
+++ b/apps/mobile/src/state/use-remote-environment-registry.ts
@@ -1,10 +1,10 @@
+import * as Dialog from "../components/Dialog";
import { useAtomValue } from "@effect/atom-react";
import { useNavigation } from "@react-navigation/native";
import type { EnvironmentId } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import { AsyncResult, Atom } from "effect/reactivity";
import { useCallback } from "react";
-import { Alert } from "react-native";
import { useConnectionController } from "../features/connection/useConnectionController";
import { environmentPresentations } from "./presentation";
@@ -124,7 +124,7 @@ export function useRemoteConnections() {
"reason" in error &&
error.reason === "unsupported"
) {
- Alert.alert("Client not supported", message);
+ Dialog.alert("Client not supported", message);
} else {
setPendingConnectionError(message);
}
@@ -171,7 +171,7 @@ export function useRemoteConnections() {
// Removing a T3 Connect environment here leaves its account registration
// and host space, so point to where it can be deregistered.
if (environment.isRelayManaged) {
- Alert.alert(
+ Dialog.alert(
"Remove from this device?",
`Forget ${environment.environmentLabel} and its cached threads on this device.\n\nIt stays on your T3 Connect account and keeps its host space. Deregister it under T3 Account → T3 Connect to free it.`,
[
@@ -185,7 +185,7 @@ export function useRemoteConnections() {
);
return;
}
- Alert.alert(
+ Dialog.alert(
"Remove from this device?",
`Forget ${environment.environmentLabel} and its cached threads on this device. Switch it off instead to keep it saved.`,
[{ text: "Cancel", style: "cancel" }, remove],
diff --git a/apps/mobile/src/state/use-selected-thread-requests.ts b/apps/mobile/src/state/use-selected-thread-requests.ts
index eeb5a017f06..5d4ae2d4781 100644
--- a/apps/mobile/src/state/use-selected-thread-requests.ts
+++ b/apps/mobile/src/state/use-selected-thread-requests.ts
@@ -1,5 +1,5 @@
+import * as Dialog from "../components/Dialog";
import { useServerConfigs } from "./entities";
-import { Alert } from "react-native";
import {
questionAttachmentDraftKey,
questionAttachmentDraftPrefix,
@@ -294,7 +294,7 @@ export function useSelectedThreadRequests() {
attachment.uploadEnvironmentId !== selectedThreadShell.environmentId,
)
) {
- Alert.alert(
+ Dialog.alert(
"Attachments are not ready",
"Wait for uploads to finish, or retry failed uploads.",
);
diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts
index 10ef09b7b77..5f1f335c6d5 100644
--- a/apps/mobile/src/state/use-thread-composer-state.ts
+++ b/apps/mobile/src/state/use-thread-composer-state.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../components/Dialog";
import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
import { readEnvironmentScope } from "./session";
import type { ComposerTextPaste } from "../native/T3ComposerEditor.types";
@@ -12,7 +13,6 @@ import {
threadRuntimeHasInterruptibleRun,
} from "@t3tools/client-runtime/state/thread-execution";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { Alert } from "react-native";
import {
CommandId,
@@ -131,7 +131,7 @@ export function appendReviewCommentToDraft(input: {
reidentifyComposerContext(upgraded.text, upgraded.records, uuidv4),
)
) {
- Alert.alert("Too many context items", "Remove some context from the draft and try again.");
+ Dialog.alert("Too many context items", "Remove some context from the draft and try again.");
return;
}
if (input.attachments && input.attachments.length > 0) {
@@ -502,14 +502,14 @@ export function useThreadComposerState() {
const text = draft.text.trim();
if (text.length === 0) {
// The server rejects an empty queued message, attachments or not.
- Alert.alert("Add a message", "A queued message cannot be left empty.");
+ Dialog.alert("Add a message", "A queued message cannot be left empty.");
return;
}
if (
edit.existingAttachments.length + draft.attachments.length >
PROVIDER_SEND_TURN_MAX_ATTACHMENTS
) {
- Alert.alert(
+ Dialog.alert(
"Too many attachments",
`Remove attachments until there are at most ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS}.`,
);
@@ -545,7 +545,7 @@ export function useThreadComposerState() {
},
});
if (result._tag !== "Success") {
- Alert.alert(
+ Dialog.alert(
"Could not save the queued message",
"It may have already started. Your edit is still in the composer.",
);
@@ -610,7 +610,7 @@ export function useThreadComposerState() {
// would enqueue a message that outbox recovery rejects forever, so block
// here until the user removes attachments.
if (attachments.length > PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
- Alert.alert(
+ Dialog.alert(
"Too many attachments",
`Remove attachments until there are at most ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS}.`,
);
@@ -619,7 +619,7 @@ export function useThreadComposerState() {
const contextBlockReason = composerContextSendBlockReason(draft.context);
if (contextBlockReason) {
- Alert.alert("Too much context", contextBlockReason);
+ Dialog.alert("Too much context", contextBlockReason);
return null;
}
@@ -634,7 +634,7 @@ export function useThreadComposerState() {
modelSelection,
thread.projectId,
);
- Alert.alert(title, detail);
+ Dialog.alert(title, detail);
return null;
}
const provider = serverConfig?.providers.find(
@@ -648,7 +648,7 @@ export function useThreadComposerState() {
if (!readEnvironmentScope(selectedThreadShell.environmentId, AuthOrchestrationOperateScope))
return null;
if (thread.activeProviderThreadId === null) {
- Alert.alert("Start a Codex thread first", "Send a message before you submit feedback.");
+ Dialog.alert("Start a Codex thread first", "Send a message before you submit feedback.");
return null;
}
const metadata = makeQueuedMessageMetadata();
@@ -806,7 +806,7 @@ export function useThreadComposerState() {
: []),
];
if (problems.length > 0) {
- Alert.alert("Could not attach photo or video", problems.join("\n\n"));
+ Dialog.alert("Could not attach photo or video", problems.join("\n\n"));
}
}, [composerDrafts, selectedEnvironmentRuntime?.serverConfig, selectedThreadShell]);
@@ -818,7 +818,7 @@ export function useThreadComposerState() {
selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.fileAttachments
?.maxUploadBytes;
if (maxBytes === undefined) {
- Alert.alert("Could not attach file", "This server does not support file attachments.");
+ Dialog.alert("Could not attach file", "This server does not support file attachments.");
return;
}
@@ -842,7 +842,7 @@ export function useThreadComposerState() {
: []),
];
if (problems.length > 0) {
- Alert.alert("Could not attach file", problems.join("\n\n"));
+ Dialog.alert("Could not attach file", problems.join("\n\n"));
}
}, [composerDrafts, selectedEnvironmentRuntime?.serverConfig, selectedThreadShell]);
diff --git a/apps/mobile/src/state/use-thread-outbox-drain.ts b/apps/mobile/src/state/use-thread-outbox-drain.ts
index 20f1ecebe02..64a4448713d 100644
--- a/apps/mobile/src/state/use-thread-outbox-drain.ts
+++ b/apps/mobile/src/state/use-thread-outbox-drain.ts
@@ -1,3 +1,4 @@
+import * as Dialog from "../components/Dialog";
import { useAtomValue } from "@effect/atom-react";
import {
threadRuntimeIsActive,
@@ -18,7 +19,6 @@ import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git";
import * as Cause from "effect/Cause";
import { AsyncResult } from "effect/reactivity";
import { useCallback, useEffect, useRef, useState } from "react";
-import { Alert } from "react-native";
import { createDebugLogger } from "../lib/debugLog";
import { scopedThreadKey } from "../lib/scopedEntities";
@@ -758,7 +758,7 @@ export function useThreadOutboxDrain(): void {
let mounted = true;
const load = async () => {
if ((await threadOutboxManager.load()) || !mounted) return;
- Alert.alert(
+ Dialog.alert(
"Some queued messages could not be loaded",
"Unreadable records and attachment files are still saved. Other messages can still be sent.",
[