X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fpost%2Fpost-listing.tsx;h=c92663501e474ecae19526a25c55a2f089e3c3ef;hb=2efe167f6d5f5cb65a2b749ba2fcee0934b247a3;hp=eb4dc8d974807547758e5d785ece3debf0510c35;hpb=9ce164245f51b834997f31f3f12497ee87474965;p=lemmy-ui.git diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index eb4dc8d..c926635 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1,4 +1,4 @@ -import { myAuthRequired } from "@utils/app"; +import { myAuth, myAuthRequired } from "@utils/app"; import { canShare, share } from "@utils/browser"; import { getExternalHost, getHttpBase } from "@utils/env"; import { @@ -34,6 +34,7 @@ import { FeaturePost, Language, LockPost, + MarkPostAsRead, PersonView, PostView, PurgePerson, @@ -130,6 +131,7 @@ interface PostListingProps { onAddModToCommunity(form: AddModToCommunity): void; onAddAdmin(form: AddAdmin): void; onTransferCommunity(form: TransferCommunity): void; + onMarkPostAsRead(form: MarkPostAsRead): void; } export class PostListing extends Component { @@ -310,16 +312,10 @@ export class PostListing extends Component { const url = post.url; const thumbnail = post.thumbnail_url; - if (url && isImage(url)) { - if (url.includes("pictrs")) { - return url; - } else if (thumbnail) { - return thumbnail; - } else { - return url; - } - } else if (thumbnail) { + if (thumbnail) { return thumbnail; + } else if (url && isImage(url)) { + return url; } else { return undefined; } @@ -353,6 +349,7 @@ export class PostListing extends Component { href={url} rel={relTags} title={url} + target={this.linkTarget} > {this.imgThumb(this.imageSrc)} { data-tippy-content={I18NextService.i18n.t("expand_here")} onClick={linkEvent(this, this.handleImageExpandClick)} aria-label={I18NextService.i18n.t("expand_here")} + target={this.linkTarget} >
@@ -380,7 +378,13 @@ export class PostListing extends Component { ); } else { return ( - +
@@ -393,6 +397,7 @@ export class PostListing extends Component { className="text-body" to={`/post/${post.id}`} title={I18NextService.i18n.t("comments")} + target={this.linkTarget} >
@@ -425,7 +430,7 @@ export class PostListing extends Component { { this.props.allLanguages.find( - lang => lang.id === post_view.post.language_id + lang => lang.id === post_view.post.language_id, )?.name } @@ -521,7 +526,7 @@ export class PostListing extends Component { @@ -741,6 +746,14 @@ export class PostListing extends Component { ); } + public get linkTarget(): string { + return UserService.Instance.myUserInfo?.local_user_view.local_user + .open_links_in_new_tab + ? "_blank" + : // _self is the default target on links when the field is not specified + "_self"; + } + get commentsButton() { const post_view = this.postView; const title = I18NextService.i18n.t("number_of_comments", { @@ -754,6 +767,7 @@ export class PostListing extends Component { title={title} to={`/post/${post_view.post.id}?scrollToComments=true`} data-tippy-content={title} + target={this.linkTarget} > {post_view.counts.comments} @@ -771,7 +785,7 @@ export class PostListing extends Component { get unreadCount(): number | undefined { const pv = this.postView; - return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0 + return pv.unread_comments === pv.counts.comments || pv.unread_comments === 0 ? undefined : pv.unread_comments; } @@ -1121,7 +1135,7 @@ export class PostListing extends Component { className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item" onClick={linkEvent( this, - !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit + !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit, )} > {/* TODO: Find an icon for this. */} @@ -1142,7 +1156,7 @@ export class PostListing extends Component { removeAndBanDialogs() { const post = this.postView; const purgeTypeText = - this.state.purgeType == PurgeType.Post + this.state.purgeType === PurgeType.Post ? I18NextService.i18n.t("purge_post") : `${I18NextService.i18n.t("purge")} ${post.creator.name}`; return ( @@ -1194,7 +1208,7 @@ export class PostListing extends Component { className="btn btn-link btn-animate text-muted py-0 d-inline-block" onClick={linkEvent( this, - this.handleCancelShowConfirmTransferCommunity + this.handleCancelShowConfirmTransferCommunity, )} aria-label={I18NextService.i18n.t("no")} > @@ -1411,7 +1425,7 @@ export class PostListing extends Component { private get myPost(): boolean { return ( - this.postView.creator.id == + this.postView.creator.id === UserService.Instance.myUserInfo?.local_user_view.person.id ); } @@ -1650,7 +1664,7 @@ export class PostListing extends Component { const ban = !i.props.post_view.creator_banned_from_community; // If its an unban, restore all their data - if (ban == false) { + if (ban === false) { i.setState({ removeData: false }); } const person_id = i.props.post_view.creator.id; @@ -1658,7 +1672,7 @@ export class PostListing extends Component { const reason = i.state.banReason; const expires = futureDaysToUnixTime(i.state.banExpireDays); - if (i.state.banType == BanType.Community) { + if (i.state.banType === BanType.Community) { const community_id = i.postView.community.id; i.props.onBanPersonFromCommunity({ community_id, @@ -1729,6 +1743,15 @@ export class PostListing extends Component { event.preventDefault(); i.setState({ imageExpanded: !i.state.imageExpanded }); setupTippy(); + + const auth = myAuth(); + if (auth && !i.props.post_view.read) { + i.props.onMarkPostAsRead({ + post_id: i.props.post_view.post.id, + read: true, + auth: auth, + }); + } } handleViewSource(i: PostListing) { @@ -1778,7 +1801,7 @@ export class PostListing extends Component { this.props.moderators, this.props.admins, undefined, - true + true, ); } @@ -1786,7 +1809,7 @@ export class PostListing extends Component { return canMod( this.postView.creator.id, this.props.moderators, - this.props.admins + this.props.admins, ); }