refactor(mobile): share file preview feedback (#12368)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-17 20:20:21 -07:00
1 parent 1a2a03f44b
commit 58fcae64ae
5 files changed
+56 -62

No files matched your search

@@ -5,7 +5,7 @@ import type { MenuAction } from "@react-native-menu/menu";
import { EnvironmentId } from "@t3tools/contracts";
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { ActivityIndicator, Alert, Platform, ScrollView, View } from "react-native";
import { Alert, Platform, ScrollView, View } from "react-native";
import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
import { AppText as Text } from "../../components/AppText";
@@ -19,6 +19,7 @@ import { isFileBackedComposerAttachment } from "../../lib/composerImages";
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import { removeComposerDraftAttachment, useComposerDraft } from "../../state/use-composer-drafts";
import { FilePreviewLoading, FilePreviewNotice } from "./FilePreviewFeedback";
import { FileMarkdownPreview } from "./FileMarkdownPreview";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { SourceFileSurface } from "./SourceFileSurface";
@@ -71,43 +72,26 @@ function AttachmentDocumentBody(props: {
);
}
if (props.nativeViewer !== null && props.nativeViewer !== "unavailable") {
return (
<View className="flex-1 items-center justify-center gap-3 bg-sheet px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">Opening in file viewer...</Text>
</View>
);
return <FilePreviewLoading message="Opening in file viewer..." />;
}
if (!document.uri || (document.needsText && !document.content)) {
return (
<View className="flex-1 items-center justify-center gap-3 bg-sheet px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">Loading file...</Text>
</View>
);
return <FilePreviewLoading message="Loading file..." />;
}
if (document.needsText && document.content) {
const { content, table } = document;
return (
<View className="flex-1 bg-sheet">
{content.truncated ? (
<View className="border-b border-warning-border bg-warning px-4 py-2">
<Text className="text-2xs font-t3-bold uppercase text-warning-foreground">
Partial file
</Text>
<Text className="text-xs leading-snug text-warning-foreground">
Preview limited to the first 1 MB. Save or share the file to read it in full.
</Text>
</View>
<FilePreviewNotice title="Partial file">
Preview limited to the first 1 MB. Save or share the file to read it in full.
</FilePreviewNotice>
) : null}
{table && document.activeMode === "table" ? (
<ScrollView className="flex-1">
{table.truncated ? (
<View className="border-b border-warning-border bg-warning px-4 py-2">
<Text className="text-xs leading-snug text-warning-foreground">
Table limited to the first 100 rows and 30 columns. Source shows the rest.
</Text>
</View>
<FilePreviewNotice>
Table limited to the first 100 rows and 30 columns. Source shows the rest.
</FilePreviewNotice>
) : null}
<ScrollView horizontal>
<View>
@@ -0,0 +1,34 @@
import { ActivityIndicator, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { cn } from "../../lib/cn";
export function FilePreviewLoading(props: {
readonly message: string;
readonly background?: "sheet" | "card";
}) {
return (
<View
className={cn(
"flex-1 items-center justify-center gap-3 px-6",
props.background === "card" ? "bg-card" : "bg-sheet",
)}
>
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">{props.message}</Text>
</View>
);
}
export function FilePreviewNotice(props: { readonly title?: string; readonly children: string }) {
return (
<View className="border-b border-warning-border bg-warning px-4 py-2">
{props.title ? (
<Text className="text-2xs font-t3-bold uppercase text-warning-foreground">
{props.title}
</Text>
) : null}
<Text className="text-xs leading-snug text-warning-foreground">{props.children}</Text>
</View>
);
}
@@ -2,7 +2,7 @@ import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/Stac
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
import type { MenuAction } from "@react-native-menu/menu";
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
import { ActivityIndicator, Platform, View } from "react-native";
import { Platform, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
import { EnvironmentId, type ProjectReadFileResult, ThreadId } from "@t3tools/contracts";
@@ -16,7 +16,6 @@ import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
import { MaterialScreenContent } from "../../components/MaterialScreenContent";
import { AppText as Text } from "../../components/AppText";
import { AudioFilePreview } from "../../components/AudioFilePreview";
import { ControlPillMenu } from "../../components/ControlPill";
import { EmptyState } from "../../components/EmptyState";
@@ -49,6 +48,7 @@ import {
} from "../layout/workspace-sidebar-toolbar";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { ThreadRouteScreen } from "../threads/ThreadRouteScreen";
import { FilePreviewLoading, FilePreviewNotice } from "./FilePreviewFeedback";
import { FileMarkdownPreview } from "./FileMarkdownPreview";
import { FileTreeBrowser } from "./FileTreeBrowser";
import { useFileTreeEntries } from "./useFileTreeEntries";
@@ -161,10 +161,7 @@ function FileContent(props: {
if (isAudioFile) {
return props.previewUri === null ? (
<View className="flex-1 items-center justify-center gap-3 bg-sheet px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">Loading file...</Text>
</View>
<FilePreviewLoading message="Loading file..." />
) : (
<AudioFilePreview uri={props.previewUri} onRetry={props.onRetryPreview} />
);
@@ -196,25 +193,15 @@ function FileContent(props: {
}
if (props.fileContents === null) {
return (
<View className="flex-1 items-center justify-center gap-3 bg-sheet px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">Loading file...</Text>
</View>
);
return <FilePreviewLoading message="Loading file..." />;
}
return (
<View className="flex-1 bg-sheet">
{props.truncated ? (
<View className="border-b border-warning-border bg-warning px-4 py-2">
<Text className="text-2xs font-t3-bold uppercase text-warning-foreground">
Partial file
</Text>
<Text className="text-xs leading-snug text-warning-foreground">
Preview limited to the first 1 MB of a truncated file.
</Text>
</View>
<FilePreviewNotice title="Partial file">
Preview limited to the first 1 MB of a truncated file.
</FilePreviewNotice>
) : null}
{props.activeMode === "preview" && isMarkdown ? (
<FileMarkdownPreview
@@ -1,7 +1,7 @@
import { useId, useMemo, useState } from "react";
import { ActivityIndicator, Image, Pressable, View } from "react-native";
import { Image, Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { FilePreviewLoading } from "./FilePreviewFeedback";
import { EmptyState } from "../../components/EmptyState";
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
import { PresentationSource } from "../../components/NativePresentation";
@@ -76,14 +76,7 @@ export function WorkspaceFileImagePreview(props: {
readonly actionsSource?: MediaActionsSource;
}) {
if (props.uri === null) {
return (
<View className="flex-1 items-center justify-center gap-3 bg-card px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">
Preparing image preview...
</Text>
</View>
);
return <FilePreviewLoading message="Preparing image preview..." background="card" />;
}
return (
@@ -3,6 +3,7 @@ import { ActivityIndicator, View } from "react-native";
import { WebView } from "react-native-webview";
import { AppText as Text } from "../../components/AppText";
import { FilePreviewLoading } from "./FilePreviewFeedback";
import { LoadingStrip } from "../../components/LoadingStrip";
export function WorkspaceFileWebPreview(props: { readonly uri: string | null }) {
@@ -10,12 +11,7 @@ export function WorkspaceFileWebPreview(props: { readonly uri: string | null })
const [loadError, setLoadError] = useState<string | null>(null);
if (props.uri === null) {
return (
<View className="flex-1 items-center justify-center gap-3 bg-card px-6">
<ActivityIndicator />
<Text className="text-center text-sm text-foreground-muted">Preparing preview...</Text>
</View>
);
return <FilePreviewLoading message="Preparing preview..." background="card" />;
}
return (