From: Jay Sitter Date: Tue, 27 Jun 2023 00:12:21 +0000 (-0400) Subject: fix: Show metadata preview card on all post pages X-Git-Url: http://these/git/%7B%60https:/%7Bthis.state.thumbnail%7D?a=commitdiff_plain;h=5c964440daf3c8001e00e11b19396b05d17df8c3;p=lemmy-ui.git fix: Show metadata preview card on all post pages --- diff --git a/src/shared/components/post/metadata-card.tsx b/src/shared/components/post/metadata-card.tsx index a1ddca7..1269c0b 100644 --- a/src/shared/components/post/metadata-card.tsx +++ b/src/shared/components/post/metadata-card.tsx @@ -8,60 +8,54 @@ interface MetadataCardProps { post: Post; } -interface MetadataCardState { - expanded: boolean; -} - -export class MetadataCard extends Component< - MetadataCardProps, - MetadataCardState -> { +export class MetadataCard extends Component { constructor(props: any, context: any) { super(props, context); } render() { const post = this.props.post; - return ( - <> - {post.embed_title && post.url && ( -
-
-
-
- {post.name !== post.embed_title && ( - <> -
- - {post.embed_title} - -
- - - {new URL(post.url).hostname} - - - - - )} - {post.embed_description && ( -
- )} -
+ + if (post.embed_title && post.url) { + return ( +
+
+
+
+ {post.name !== post.embed_title && ( + <> +
+ + {post.embed_title} + +
+ + + {new URL(post.url).hostname} + + + + + )} + {post.embed_description && ( +
+ )}
- )} - - ); +
+ ); + } else { + return <>; + } } } diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index f898e83..2b761c5 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -105,6 +105,9 @@ interface PostListingProps { allLanguages: Language[]; siteLanguages: number[]; showCommunity?: boolean; + /** + * Controls whether to show both the body *and* the metadata preview card + */ showBody?: boolean; hideImage?: boolean; enableDownvotes?: boolean; @@ -200,7 +203,7 @@ export class PostListing extends Component { <> {this.listing()} {this.state.imageExpanded && !this.props.hideImage && this.img} - {post.url && this.state.showBody && post.embed_title && ( + {this.showBody && post.url && post.embed_title && ( )} {this.showBody && this.body()} @@ -483,10 +486,10 @@ export class PostListing extends Component { {/** - * If there is a URL, or if the post has a body and we were told not to - * show the body, show the MetadataCard/body toggle. + * If there is a URL, an embed title, and we were not told to show the + * body by the parent component, show the MetadataCard/body toggle. */} - {(post.url || (post.body && !this.props.showBody)) && ( + {!this.props.showBody && post.url && post.embed_title && (