From 9c54cad750981bf6328fcb1322966f9791b0419f Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 24 Jul 2024 16:23:09 -0500 Subject: [PATCH] Memoize --- src/view/com/util/post-embeds/index.tsx | 58 +++++++++++++++---------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx index eec17e6d0a..71c72b4978 100644 --- a/src/view/com/util/post-embeds/index.tsx +++ b/src/view/com/util/post-embeds/index.tsx @@ -55,10 +55,8 @@ export function PostEmbeds({ style?: StyleProp allowNestedQuotes?: boolean }) { - const pal = usePalette('default') const {openLightbox} = useLightboxControls() const largeAltBadge = useLargeAltBadgeEnabled() - const moderationOpts = useModerationOpts() // quote post with media // = @@ -77,32 +75,13 @@ export function PostEmbeds({ if (AppBskyEmbedRecord.isView(embed)) { // custom feed embed (i.e. generator view) - // = if (AppBskyFeedDefs.isGeneratorView(embed.record)) { - const moderation = moderationOpts - ? moderateFeedGenerator(embed.record, moderationOpts) - : undefined - return ( - - - - ) + return } // list embed if (AppBskyGraphDefs.isListView(embed.record)) { - const moderation = moderationOpts - ? moderateUserList(embed.record, moderationOpts) - : undefined - return ( - - - - ) + return } if (AppBskyGraphDefs.isStarterPackViewBasic(embed.record)) { @@ -200,6 +179,39 @@ export function PostEmbeds({ return } +function MaybeFeedCard({view}: {view: AppBskyFeedDefs.GeneratorView}) { + const pal = usePalette('default') + const moderationOpts = useModerationOpts() + const moderation = React.useMemo(() => { + return moderationOpts + ? moderateFeedGenerator(view, moderationOpts) + : undefined + }, [view, moderationOpts]) + + return ( + + + + ) +} + +function MaybeListCard({view}: {view: AppBskyGraphDefs.ListView}) { + const moderationOpts = useModerationOpts() + const moderation = React.useMemo(() => { + return moderationOpts ? moderateUserList(view, moderationOpts) : undefined + }, [view, moderationOpts]) + + return ( + + + + ) +} + const styles = StyleSheet.create({ container: { marginTop: 8,