diff --git a/src/view/com/composer/drafts/DraftItem.tsx b/src/view/com/composer/drafts/DraftItem.tsx index 28876d9a15..2ca0506e3b 100644 --- a/src/view/com/composer/drafts/DraftItem.tsx +++ b/src/view/com/composer/drafts/DraftItem.tsx @@ -1,7 +1,5 @@ -import {useCallback, useEffect, useMemo, useState} from 'react' +import {useCallback, useEffect, useState} from 'react' import {Pressable, View} from 'react-native' -import {Image} from 'expo-image' -import {type AppBskyEmbedImages} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -12,15 +10,10 @@ import {UserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import {DotGrid_Stroke2_Corner0_Rounded as DotsIcon} from '#/components/icons/DotGrid' -import {AutoSizedImage} from '#/components/images/AutoSizedImage' -import {ImageLayoutGrid} from '#/components/images/ImageLayoutGrid' +import * as MediaPreview from '#/components/MediaPreview' import * as Prompt from '#/components/Prompt' import {Text} from '#/components/Typography' -import { - type DraftPostDisplay, - type DraftSummary, - type LocalMediaDisplay, -} from './state/schema' +import {type DraftPostDisplay, type DraftSummary} from './state/schema' import * as storage from './state/storage' export function DraftItem({ @@ -217,124 +210,62 @@ function DraftPostRow({ type LoadedImage = { url: string - meta: LocalMediaDisplay - width?: number - height?: number + alt: string } function DraftMediaPreview({post}: {post: DraftPostDisplay}) { - const t = useTheme() const [loadedImages, setLoadedImages] = useState([]) + const [videoThumbnail, setVideoThumbnail] = useState() useEffect(() => { async function loadMedia() { - // Try to load all images - the exists flag may be stale due to async cache + // Load images if (post.images && post.images.length > 0) { const loaded: LoadedImage[] = [] for (const image of post.images) { try { const url = await storage.loadMediaFromLocal(image.localPath) - // Get dimensions using expo-image's loadAsync - let width: number | undefined - let height: number | undefined - try { - const imageRef = await Image.loadAsync(url) - width = imageRef.width - height = imageRef.height - } catch { - // Dimensions unavailable, will use default aspect ratio - } - loaded.push({url, meta: {...image, exists: true}, width, height}) + loaded.push({url, alt: image.altText || ''}) } catch (e) { // Image doesn't exist locally, skip it } } setLoadedImages(loaded) } + + // Load video thumbnail + if (post.video?.exists && post.video.localPath) { + try { + const url = await storage.loadMediaFromLocal(post.video.localPath) + setVideoThumbnail(url) + } catch (e) { + // Video doesn't exist locally + } + } } loadMedia() - }, [post.images]) - - // Convert loaded images to ViewImage format for the embed components - const viewImages = useMemo(() => { - return loadedImages.map(({url, width, height, meta}) => ({ - thumb: url, - fullsize: url, - alt: meta.altText || '', - aspectRatio: width && height ? {width, height} : {width: 1, height: 1}, - })) - }, [loadedImages]) - - // Count missing images (images we tried to load but couldn't) - const missingImageCount = (post.images?.length ?? 0) - loadedImages.length + }, [post.images, post.video]) // Nothing to show - if (viewImages.length === 0 && !post.gif && !post.video) { + if (loadedImages.length === 0 && !post.gif && !post.video) { return null } return ( - - {/* Images - use real embed components */} - {viewImages.length === 1 && ( - - )} - {viewImages.length > 1 && } - - {/* Missing images note */} - {missingImageCount > 0 && ( - - - {missingImageCount} image{missingImageCount > 1 ? 's' : ''} not - available - - - )} - - {/* GIF preview */} + + {loadedImages.map((image, i) => ( + + ))} {post.gif && ( - - - + )} - - {/* Video indicator */} {post.video && ( - - - {post.video.exists ? ( - Video attached - ) : ( - Video not available - )} - - + )} - + ) } diff --git a/src/view/com/composer/drafts/state/schema.ts b/src/view/com/composer/drafts/state/schema.ts index 59221380d7..d0e94ded71 100644 --- a/src/view/com/composer/drafts/state/schema.ts +++ b/src/view/com/composer/drafts/state/schema.ts @@ -26,6 +26,8 @@ export type GifDisplay = { width: number /** Height */ height: number + /** Alt text */ + alt: string } /**