Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(mobile): media previews share file leases and close on blur in one place #25527

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/25527/headmerged by juliusmarminge View on GitHub

Showing 13 changed files with 10 additions and 25 deletions (loading 12).

x
0 of 13 viewed, 13 left
10 additions and 25 deletionsapps/mobile/src/components/ComposerContextAttachment.tsxModified
View file
@@ -5,10 +5,13 @@
import type { ComposerContextRecord, EnvironmentId } from "@t3tools/contracts";
import { Pressable, View } from "react-native";
import { Image } from "expo-image";
-import { useEffect, useId, useState } from "react";
+import { useId, useState } from "react";
import type { DraftComposerAttachment } from "../lib/composerImages";
import { composerAttachmentInlineUri, isFileBackedComposerAttachment } from "../lib/composerImages";
-import { loadLocalAttachmentPreview } from "../lib/localAttachmentPreview";
+import {
+ loadLocalAttachmentPreview,
+ useLocalAttachmentPreview,
+} from "../lib/localAttachmentPreview";
import { downloadAndShareAttachment } from "../lib/attachmentDownload";
import { assetImageSource } from "../lib/assetImageSource";
import { useAssetUrlState, useRefreshAssetUrl } from "../state/assets";
@@ -35,31 +38,13 @@
const remoteEnvironmentId = local || inlineUri ? null : (props.environmentId ?? null);
const asset = useAssetUrlState(remoteEnvironmentId, resource);
const refresh = useRefreshAssetUrl(remoteEnvironmentId, resource);
- const [localUri, setLocalUri] = useState<string | null>(null);
- const [error, setError] = useState<string | null>(null);
+ const localPreview = useLocalAttachmentPreview(local ?? null);
+ const error = localPreview.error ? "The local file is unavailable. Attach it again." : null;
const [sharing, setSharing] = useState(false);
const [previewOpen, setPreviewOpen] = useState(false);
- useEffect(() => {
- if (!local) return;
- const controller = new AbortController();