2
0
Fork 0
mirror of https://github.com/LemmyNet/lemmy-ui.git synced 2024-12-04 02:01:13 +00:00

Let any mod feature and lock posts. Fixes

This commit is contained in:
Dessalines 2023-02-21 11:11:29 -05:00
parent deffaf1ee0
commit 5f8099033b

View file

@ -28,8 +28,8 @@ import { i18n } from "../../i18next";
import { BanType, PurgeType } from "../../interfaces"; import { BanType, PurgeType } from "../../interfaces";
import { UserService, WebSocketService } from "../../services"; import { UserService, WebSocketService } from "../../services";
import { import {
amAdmin,
amCommunityCreator, amCommunityCreator,
amMod,
canAdmin, canAdmin,
canMod, canMod,
futureDaysToUnixTime, futureDaysToUnixTime,
@ -608,7 +608,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
{this.state.showAdvanced && ( {this.state.showAdvanced && (
<> <>
{this.showBody && post_view.post.body && this.viewSourceButton} {this.showBody && post_view.post.body && this.viewSourceButton}
{this.canModOnSelf_ && ( {/* Any mod can do these, not limited to hierarchy*/}
{(amMod(this.props.moderators) || this.canAdmin_) && (
<> <>
{this.lockButton} {this.lockButton}
{this.featureButton} {this.featureButton}
@ -842,41 +843,40 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
} }
get featureButton() { get featureButton() {
const featured_community = this.props.post_view.post.featured_community; const featuredCommunity = this.props.post_view.post.featured_community;
const label_community = featured_community const labelCommunity = featuredCommunity
? i18n.t("unfeature_from_community") ? i18n.t("unfeature_from_community")
: i18n.t("feature_in_community"); : i18n.t("feature_in_community");
const is_admin = amAdmin(); const featuredLocal = this.props.post_view.post.featured_local;
const featured_local = this.props.post_view.post.featured_local; const labelLocal = featuredLocal
const label_local = featured_local
? i18n.t("unfeature_from_local") ? i18n.t("unfeature_from_local")
: i18n.t("feature_in_local"); : i18n.t("feature_in_local");
return ( return (
<span> <span>
<button <button
className="btn btn-link btn-animate text-muted py-0 pl-0" className="btn btn-link btn-animate text-muted py-0 pl-0"
onClick={() => this.handleModFeaturePost(this, true)} onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
data-tippy-content={label_community} data-tippy-content={labelCommunity}
aria-label={label_community} aria-label={labelCommunity}
> >
<Icon <Icon
icon="pin" icon="pin"
classes={classNames({ "text-success": featured_community })} classes={classNames({ "text-success": featuredCommunity })}
inline inline
/>{" "} />{" "}
Community Community
</button> </button>
{is_admin && ( {this.canAdmin_ && (
<button <button
className="btn btn-link btn-animate text-muted py-0" className="btn btn-link btn-animate text-muted py-0"
onClick={() => this.handleModFeaturePost(this, false)} onClick={linkEvent(this, this.handleModFeaturePostLocal)}
data-tippy-content={label_local} data-tippy-content={labelLocal}
aria-label={label_local} aria-label={labelLocal}
> >
<Icon <Icon
icon="pin" icon="pin"
classes={classNames({ "text-success": featured_local })} classes={classNames({ "text-success": featuredLocal })}
inline inline
/>{" "} />{" "}
Local Local
@ -1527,20 +1527,26 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
} }
} }
handleModFeaturePost(i: PostListing, is_community: boolean) { handleModFeaturePostLocal(i: PostListing) {
let auth = myAuth(); let auth = myAuth();
if (auth) { if (auth) {
let featured: [PostFeatureType, boolean] = is_community
? [
PostFeatureType.Community,
!i.props.post_view.post.featured_community,
]
: [PostFeatureType.Local, !i.props.post_view.post.featured_local];
let form: FeaturePost = { let form: FeaturePost = {
post_id: i.props.post_view.post.id, post_id: i.props.post_view.post.id,
feature_type: featured[0], feature_type: PostFeatureType.Local,
featured: featured[1], featured: !i.props.post_view.post.featured_local,
auth,
};
WebSocketService.Instance.send(wsClient.featurePost(form));
}
}
handleModFeaturePostCommunity(i: PostListing) {
let auth = myAuth();
if (auth) {
let form: FeaturePost = {
post_id: i.props.post_view.post.id,
feature_type: PostFeatureType.Community,
featured: !i.props.post_view.post.featured_community,
auth, auth,
}; };
WebSocketService.Instance.send(wsClient.featurePost(form)); WebSocketService.Instance.send(wsClient.featurePost(form));