mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 22:31:13 +00:00
fix: Show metadata preview card on all post pages
This commit is contained in:
parent
1dd83dafdc
commit
5c964440da
2 changed files with 47 additions and 50 deletions
|
@ -8,60 +8,54 @@ interface MetadataCardProps {
|
||||||
post: Post;
|
post: Post;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MetadataCardState {
|
export class MetadataCard extends Component<MetadataCardProps> {
|
||||||
expanded: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MetadataCard extends Component<
|
|
||||||
MetadataCardProps,
|
|
||||||
MetadataCardState
|
|
||||||
> {
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const post = this.props.post;
|
const post = this.props.post;
|
||||||
return (
|
|
||||||
<>
|
if (post.embed_title && post.url) {
|
||||||
{post.embed_title && post.url && (
|
return (
|
||||||
<div className="post-metadata-card card border-secondary mt-3 mb-2">
|
<div className="post-metadata-card card border-secondary mt-3 mb-2">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
{post.name !== post.embed_title && (
|
{post.name !== post.embed_title && (
|
||||||
<>
|
<>
|
||||||
<h5 className="card-title d-inline">
|
<h5 className="card-title d-inline">
|
||||||
<a className="text-body" href={post.url} rel={relTags}>
|
<a className="text-body" href={post.url} rel={relTags}>
|
||||||
{post.embed_title}
|
{post.embed_title}
|
||||||
</a>
|
</a>
|
||||||
</h5>
|
</h5>
|
||||||
<span className="d-inline-block ms-2 mb-2 small text-muted">
|
<span className="d-inline-block ms-2 mb-2 small text-muted">
|
||||||
<a
|
<a
|
||||||
className="text-muted fst-italic"
|
className="text-muted fst-italic"
|
||||||
href={post.url}
|
href={post.url}
|
||||||
rel={relTags}
|
rel={relTags}
|
||||||
>
|
>
|
||||||
{new URL(post.url).hostname}
|
{new URL(post.url).hostname}
|
||||||
<Icon icon="external-link" classes="ms-1" />
|
<Icon icon="external-link" classes="ms-1" />
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{post.embed_description && (
|
{post.embed_description && (
|
||||||
<div
|
<div
|
||||||
className="card-text small text-muted md-div"
|
className="card-text small text-muted md-div"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: sanitizeHtml(post.embed_description),
|
__html: sanitizeHtml(post.embed_description),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</>
|
);
|
||||||
);
|
} else {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,9 @@ interface PostListingProps {
|
||||||
allLanguages: Language[];
|
allLanguages: Language[];
|
||||||
siteLanguages: number[];
|
siteLanguages: number[];
|
||||||
showCommunity?: boolean;
|
showCommunity?: boolean;
|
||||||
|
/**
|
||||||
|
* Controls whether to show both the body *and* the metadata preview card
|
||||||
|
*/
|
||||||
showBody?: boolean;
|
showBody?: boolean;
|
||||||
hideImage?: boolean;
|
hideImage?: boolean;
|
||||||
enableDownvotes?: boolean;
|
enableDownvotes?: boolean;
|
||||||
|
@ -200,7 +203,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
<>
|
<>
|
||||||
{this.listing()}
|
{this.listing()}
|
||||||
{this.state.imageExpanded && !this.props.hideImage && this.img}
|
{this.state.imageExpanded && !this.props.hideImage && this.img}
|
||||||
{post.url && this.state.showBody && post.embed_title && (
|
{this.showBody && post.url && post.embed_title && (
|
||||||
<MetadataCard post={post} />
|
<MetadataCard post={post} />
|
||||||
)}
|
)}
|
||||||
{this.showBody && this.body()}
|
{this.showBody && this.body()}
|
||||||
|
@ -483,10 +486,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
{/**
|
{/**
|
||||||
* If there is a URL, or if the post has a body and we were told not to
|
* If there is a URL, an embed title, and we were not told to show the
|
||||||
* show the body, show the MetadataCard/body toggle.
|
* 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 && (
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
|
className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
|
||||||
data-tippy-content={post.body && mdNoImages.render(post.body)}
|
data-tippy-content={post.body && mdNoImages.render(post.body)}
|
||||||
|
|
Loading…
Reference in a new issue