diff --git a/src/shared/components/post/metadata-card.tsx b/src/shared/components/post/metadata-card.tsx index a1ddca7f..1269c0b7 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 f80cb970..b9a19131 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -49,7 +49,7 @@ import { PurgeType, VoteContentType, } from "../../interfaces"; -import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown"; +import { mdToHtml, mdToHtmlInline } from "../../markdown"; import { I18NextService, UserService } from "../../services"; import { setupTippy } from "../../tippy"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; @@ -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()} @@ -482,6 +485,15 @@ export class PostListing extends Component { )} + {/** + * 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. + */} + {!this.props.showBody && + post.url && + post.embed_title && + this.showPreviewButton()} + {post.removed && ( {I18NextService.i18n.t("removed")} @@ -624,27 +636,6 @@ export class PostListing extends Component { ); } - showPreviewButton() { - const post_view = this.postView; - const body = post_view.post.body; - - return ( - - ); - } - postActions() { // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button. // Possible enhancement: Make each button a component. @@ -656,14 +647,7 @@ export class PostListing extends Component { {this.saveButton} {this.crossPostButton} - {/** - * 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. - */} - {(post.url || (post.body && !this.props.showBody)) && - this.showPreviewButton()} - - {this.showBody && post_view.post.body && this.viewSourceButton} + {this.props.showBody && post_view.post.body && this.viewSourceButton}
); }