@@ -15,10 +15,7 @@ import {
1515 AndroidHeaderIconButton ,
1616 AndroidScreenHeader ,
1717} from "../../components/ui/AndroidScreenHeader" ;
18- import { DelimitedFilePreview } from "./DelimitedFilePreview" ;
19- import { AudioFilePreview } from "./AudioFilePreview" ;
2018import { Menu } from "../../components/ui/Menu" ;
21- import { EmptyState } from "../../components/ui/EmptyState" ;
2219import { FilePreviewModal , type FilePreviewSource } from "../../components/FilePreviewModal" ;
2320import { useAttachmentDocument } from "../../lib/attachmentDocument" ;
2421import { nativeViewerErrorMessage } from "../../lib/attachmentDownload" ;
@@ -29,13 +26,9 @@ import { removeComposerDraftAttachment, useComposerDraft } from "../../state/use
2926import { useEnvironmentServerConfig } from "../../state/entities" ;
3027import { useRefreshAssetUrl } from "../../state/assets" ;
3128import { scopedThreadKey } from "../../lib/scopedEntities" ;
32- import { FilePreviewLoading , FilePreviewNotice } from "./FilePreviewFeedback" ;
33- import { FileMarkdownPreview } from "./FileMarkdownPreview" ;
3429import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider" ;
35- import { SourceFileSurface } from "./SourceFileSurface" ;
36- import { WorkspaceFileWebPreview } from "./WorkspaceFileWebPreview" ;
37- import { HtmlRenderWebView } from "../threads/HtmlRenderWebView" ;
3830import { isZipFile , ZipArchiveView } from "./ZipArchiveView" ;
31+ import { AttachmentDocumentBody , nativeViewerKind } from "./AttachmentDocumentBody" ;
3932
4033export type AttachmentFileRouteParams = {
4134 readonly environmentId ?: string ;
@@ -50,105 +43,6 @@ export type AttachmentFileRouteParams = {
5043
5144type AttachmentFileScreenProps = StaticScreenProps < AttachmentFileRouteParams > ;
5245
53- export function nativeViewerKind ( kind : ReturnType < typeof useAttachmentDocument > [ "kind" ] ) {
54- if ( kind === "image" ) return "image" as const ;
55- if ( kind === "pdf" ) return "pdf" as const ;
56- if ( kind === "video" || kind === "unsupported" ) return "document" as const ;
57- return null ;
58- }
59-
60- export function AttachmentDocumentBody ( props : {
61- readonly document : Pick <
62- ReturnType < typeof useAttachmentDocument > ,
63- | "kind"
64- | "activeMode"
65- | "uri"
66- | "content"
67- | "table"
68- | "error"
69- | "needsText"
70- | "retry"
71- | "revision"
72- > ;
73- readonly name : string ;
74- readonly environmentId : EnvironmentId | null ;
75- readonly htmlRender : boolean ;
76- readonly nativeViewer : "pending" | "open" | "unavailable" | null ;
77- readonly nativeError : string | null ;
78- readonly onOpenNative : ( ) => void ;
79- } ) {
80- const { document } = props ;
81- if ( document . error ) {
82- return (
83- < View className = "flex-1 items-center justify-center bg-sheet px-6" >
84- < EmptyState
85- title = "File unavailable"
86- detail = { document . error }
87- actionLabel = "Try again"
88- onAction = { document . retry }
89- />
90- </ View >
91- ) ;
92- }
93- if ( props . nativeViewer !== null && props . nativeViewer !== "unavailable" ) {
94- return < FilePreviewLoading message = "Opening in file viewer..." /> ;
95- }
96- // ZIP text entries are read into memory and have no file URI.
97- if ( document . needsText ? ! document . content : ! document . uri ) {
98- return < FilePreviewLoading message = "Loading file..." /> ;
99- }
100- if ( document . needsText && document . content ) {
101- const { content, table } = document ;
102- return (
103- < View className = "flex-1 bg-sheet" >
104- { content . truncated ? (
105- < FilePreviewNotice title = "Partial file" >
106- Preview limited to the first 1 MB. Save or share the file to read it in full.
107- </ FilePreviewNotice >
108- ) : null }
109- { table && document . activeMode === "table" ? (
110- < DelimitedFilePreview table = { table } />
111- ) : document . activeMode === "markdown" && props . environmentId ? (
112- < FileMarkdownPreview
113- cwd = ""
114- relativePath = ""
115- environmentId = { props . environmentId }
116- threadId = { null }
117- markdown = { content . text }
118- captured
119- />
120- ) : (
121- < SourceFileSurface contents = { content . text } path = { props . name } selectable />
122- ) }
123- </ View >
124- ) ;
125- }
126- if ( ! document . uri ) return null ;
127- if ( document . kind === "audio" ) {
128- return < AudioFilePreview key = { document . revision } uri = { document . uri } onRetry = { document . retry } /> ;
129- }
130- if ( document . kind === "html" ) {
131- return props . htmlRender ? (
132- < HtmlRenderWebView key = { document . uri } uri = { document . uri } title = { props . name } nested = { false } />
133- ) : (
134- < WorkspaceFileWebPreview uri = { document . uri } />
135- ) ;
136- }
137- return (
138- < View className = "flex-1 items-center justify-center bg-sheet px-6" >
139- < EmptyState
140- title = "No preview for this file"
141- detail = {
142- props . nativeError ??
143- "No app on this device can show this format. Save or share it to open it elsewhere."
144- }
145- actionLabel = "Try again"
146- onAction = { props . onOpenNative }
147- />
148- </ View >
149- ) ;
150- }
151-
15246export function AttachmentFileScreen ( props : AttachmentFileScreenProps ) {
15347 const navigation = useNavigation ( ) ;
15448 const { appearance, setCodeWordBreak } = useAppearancePreferences ( ) ;
0 commit comments