import { useAtomValue } from "@effect/atom-react"; import { useMemo, useState } from "react"; import { ActivityIndicator, Image, Pressable, View } from "react-native"; import ImageViewing from "react-native-image-viewing"; import { AsyncResult } from "effect/unstable/reactivity"; import { AppText as Text } from "../../components/AppText"; import { EmptyState } from "../../components/EmptyState"; import { workspaceFileImageAtom } from "./workspace-file-image-cache"; function ResolvedWorkspaceFileImagePreview(props: { readonly accessibilityLabel: string; readonly uri: string; }) { const [loadError, setLoadError] = useState(null); const [fullScreenVisible, setFullScreenVisible] = useState(false); const imageSource = useMemo( () => ({ uri: props.uri, cache: "force-cache" as const }), [props.uri], ); const fullScreenImages = useMemo(() => [imageSource], [imageSource]); return ( setFullScreenVisible(true)} > setLoadError(null)} onError={(event) => { setLoadError(event.nativeEvent.error || "The image could not be rendered."); }} /> {loadError !== null ? ( ) : null} setFullScreenVisible(false)} swipeToCloseEnabled doubleTapToZoomEnabled /> ); } function CachedWorkspaceFileImagePreview(props: { readonly accessibilityLabel: string; readonly uri: string; }) { const imageAtom = useMemo(() => workspaceFileImageAtom(props.uri), [props.uri]); const imageResult = useAtomValue(imageAtom); if (AsyncResult.isFailure(imageResult)) { return ( ); } if (!AsyncResult.isSuccess(imageResult)) { return ( Loading image... ); } return ( ); } export function WorkspaceFileImagePreview(props: { readonly accessibilityLabel: string; readonly uri: string | null; }) { if (props.uri === null) { return ( Preparing image preview... ); } return ( ); }