From fcbb9c2e1fec7aa18f1206c82b6690bbe6042f54 Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Tue, 7 Jan 2025 16:27:39 +0100 Subject: [PATCH 1/2] suggestions --- src/components/MediaPreview.tsx | 62 ++++---- src/components/interstitials/Trending.tsx | 38 +++-- src/lib/strings/embed-player.ts | 9 ++ .../Messages/components/MessageInputEmbed.tsx | 6 +- src/screens/StarterPack/Wizard/State.tsx | 4 +- src/state/queries/notifications/util.ts | 22 ++- src/state/queries/util.ts | 19 ++- src/types/atproto/index.ts | 4 +- src/types/atproto/post.ts | 136 ------------------ src/types/atproto/profile.ts | 6 +- 10 files changed, 85 insertions(+), 221 deletions(-) delete mode 100644 src/types/atproto/post.ts diff --git a/src/components/MediaPreview.tsx b/src/components/MediaPreview.tsx index 9d9c755456..f292ea4422 100644 --- a/src/components/MediaPreview.tsx +++ b/src/components/MediaPreview.tsx @@ -1,15 +1,20 @@ import React from 'react' import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' import {Image} from 'expo-image' -import {AppBskyFeedDefs} from '@atproto/api' +import { + AppBskyEmbedExternal, + AppBskyEmbedImages, + AppBskyEmbedRecordWithMedia, + AppBskyEmbedVideo, +} from '@atproto/api' +import {$Typed} from '@atproto/api/dist/client/util' import {Trans} from '@lingui/macro' -import {parseTenorGif} from '#/lib/strings/embed-player' +import {isTenorGifUri} from '#/lib/strings/embed-player' import {atoms as a, useTheme} from '#/alf' import {MediaInsetBorder} from '#/components/MediaInsetBorder' import {Text} from '#/components/Typography' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' -import {parseEmbed} from '#/types/atproto/post' /** * Streamlined MediaPreview component which just handles images, gifs, and videos @@ -18,17 +23,22 @@ export function Embed({ embed, style, }: { - embed: AppBskyFeedDefs.PostView['embed'] + embed?: + | $Typed + | $Typed + | $Typed + | $Typed + | {$type: string} style?: StyleProp }) { - const e = parseEmbed(embed) - - if (!e) return null - - if (e.type === 'images') { + if (!embed) { + return null + } else if (AppBskyEmbedRecordWithMedia.isView(embed)) { + return + } else if (AppBskyEmbedImages.isView(embed)) { return ( - {e.view.images.map(image => ( + {embed.images.map(image => ( ) - } else if (e.type === 'link' && e.view.external.thumb) { - let url: URL | undefined - try { - url = new URL(e.view.external.uri) - } catch {} - if (url) { - const {success} = parseTenorGif(url) - if (success) { - return ( - - - - ) - } - } - } else if (e.type === 'video') { + } else if (AppBskyEmbedExternal.isView(embed)) { + if (!embed.external.thumb) return null + if (!isTenorGifUri(embed.external.uri)) return null + + return ( + + + + ) + } else if (AppBskyEmbedVideo.isView(embed)) { return ( - + ) } + // media is {$type: string} return null } diff --git a/src/components/interstitials/Trending.tsx b/src/components/interstitials/Trending.tsx index 1da361ef79..a217a7da2d 100644 --- a/src/components/interstitials/Trending.tsx +++ b/src/components/interstitials/Trending.tsx @@ -59,26 +59,24 @@ export function Inner() { ) : !trending?.topics ? null : ( <> {trending.topics.map(topic => ( - <> - { - logEvent('trendingTopic:click', {context: 'interstitial'}) - }}> - - - {topic.topic} - - - - + { + logEvent('trendingTopic:click', {context: 'interstitial'}) + }}> + + + {topic.topic} + + + ))}