X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fpost%2Fpost-listing.tsx;h=bc853b37f846594aaf1c2f044a3034eb6799c118;hb=9869b911cf480ee88c7b1e7d2f689cc2e1c65157;hp=ac90b0d8fb13bdd04731eb7409fa9884331aa5b9;hpb=937dd5f86a897a7f09bf81f04adc5f10a804c1ae;p=lemmy-ui.git diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index ac90b0d..bc853b3 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -49,12 +49,13 @@ 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"; import { MomentTime } from "../common/moment-time"; import { PictrsImage } from "../common/pictrs-image"; +import { UserBadges } from "../common/user-badges"; import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; @@ -105,6 +106,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; @@ -183,7 +187,6 @@ export class PostListing extends Component { addModLoading: false, addAdminLoading: false, transferLoading: false, - imageExpanded: false, }); } } @@ -201,7 +204,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()} @@ -329,27 +332,33 @@ export class PostListing extends Component { if (!this.props.hideImage && url && isImage(url) && this.imageSrc) { return ( - {this.imgThumb(this.imageSrc)} - - + + ); } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) { return ( {this.imgThumb(this.imageSrc)} - + ); } else if (url) { @@ -395,24 +404,16 @@ export class PostListing extends Component { createdLine() { const post_view = this.postView; + return ( - - - {this.creatorIsMod_ && ( - - {I18NextService.i18n.t("mod")} - - )} - {this.creatorIsAdmin_ && ( - - {I18NextService.i18n.t("admin")} - - )} - {post_view.creator.bot_account && ( - - {I18NextService.i18n.t("bot_account").toLowerCase()} - - )} +
+ + {this.props.showCommunity && ( <> {" "} @@ -434,7 +435,7 @@ export class PostListing extends Component { published={post_view.post.published} updated={post_view.post.updated} /> - +
); } @@ -482,26 +483,22 @@ export class PostListing extends Component { this.postLink )} - {(url && isImage(url)) || - (post.thumbnail_url && ( - - ))} + + {/** + * 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")} )} + {post.deleted && ( { )} + {post.locked && ( { )} + {post.featured_community && ( { )} + {post.featured_local && ( { )} + {post.nsfw && ( {I18NextService.i18n.t("nsfw")} @@ -634,27 +635,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. @@ -666,14 +646,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}
@@ -982,6 +999,121 @@ export class PostListing extends Component { ); } + get modBanFromCommunityButton() { + return ( + + ); + } + + get modUnbanFromCommunityButton() { + return ( + + ); + } + + get addModToCommunityButton() { + return ( + + ); + } + + get modBanButton() { + return ( + + ); + } + + get modUnbanButton() { + return ( + + ); + } + + get purgePersonButton() { + return ( + + ); + } + + get purgePostButton() { + return ( + + ); + } + + get toggleAdminButton() { + return ( + + ); + } + + get transferCommunityButton() { + return ( + + ); + } + get modRemoveButton() { const removed = this.postView.post.removed; return ( @@ -996,188 +1128,17 @@ export class PostListing extends Component { {this.state.removeLoading ? ( ) : !removed ? ( - I18NextService.i18n.t("remove") + capitalizeFirstLetter(I18NextService.i18n.t("remove_post")) ) : ( - I18NextService.i18n.t("restore") + <> + {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "} + {I18NextService.i18n.t("post")} + )} ); } - /** - * Mod/Admin actions to be taken against the author. - */ - userActionsLine() { - // TODO: make nicer - const post_view = this.postView; - return ( - this.state.showAdvanced && ( -
- {this.canMod_ && ( - <> - {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community ? ( - - ) : ( - - ))} - {!post_view.creator_banned_from_community && ( - - )} - - )} - {/* Community creators and admins can transfer community to another mod */} - {(amCommunityCreator(post_view.creator.id, this.props.moderators) || - this.canAdmin_) && - this.creatorIsMod_ && - (!this.state.showConfirmTransferCommunity ? ( - - ) : ( - <> - - - - - ))} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin_ && ( - <> - {!this.creatorIsAdmin_ && ( - <> - {!isBanned(post_view.creator) ? ( - - ) : ( - - )} - - - - )} - {!isBanned(post_view.creator) && post_view.creator.local && ( - - )} - - )} -
- ) - ); - } - removeAndBanDialogs() { const post = this.postView; const purgeTypeText = @@ -1205,11 +1166,7 @@ export class PostListing extends Component { value={this.state.removeReason} onInput={linkEvent(this, this.handleModRemoveReasonChange)} /> - )} + {this.state.showConfirmTransferCommunity && ( + <> + + + + + )} {this.state.showBanDialog && (
@@ -1235,12 +1219,12 @@ export class PostListing extends Component { value={this.state.banReason} onInput={linkEvent(this, this.handleModBanReasonChange)} /> -
*/}
- )} @@ -1368,15 +1340,18 @@ export class PostListing extends Component { ); } - showBodyPreview() { - const { body, id } = this.postView.post; - - return !this.showBody && body ? ( - -
{body}
- - ) : ( - <> + showPreviewButton() { + return ( + ); } @@ -1392,11 +1367,7 @@ export class PostListing extends Component { {/* If it has a thumbnail, do a right aligned thumbnail */} {this.mobileThumbnail()} - {/* Show a preview of the post body */} - {this.showBodyPreview()} - {this.commentsLine(true)} - {this.userActionsLine()} {this.duplicatesLine()} {this.removeAndBanDialogs()}
@@ -1407,27 +1378,27 @@ export class PostListing extends Component {
{!this.props.viewOnly && ( - +
+ +
)} -
-
{this.thumbnail()}
-
-
+
-
+
+
{this.thumbnail()}
+
+
{this.postTitleLine()} {this.createdLine()} - {this.showBodyPreview()} {this.commentsLine()} {this.duplicatesLine()} - {this.userActionsLine()} {this.removeAndBanDialogs()}