2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddModToCommunity,
|
2022-07-30 03:38:37 +00:00
|
|
|
BlockCommunity,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommunityModeratorView,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityView,
|
2020-12-24 01:58:27 +00:00
|
|
|
DeleteCommunity,
|
2021-07-17 20:42:55 +00:00
|
|
|
FollowCommunity,
|
2022-12-19 15:57:29 +00:00
|
|
|
Language,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgeCommunity,
|
2021-07-17 20:42:55 +00:00
|
|
|
RemoveCommunity,
|
2022-06-23 13:35:53 +00:00
|
|
|
SubscribedType,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2021-09-18 16:35:49 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
amAdmin,
|
|
|
|
amMod,
|
|
|
|
amTopMod,
|
2021-09-18 16:35:49 +00:00
|
|
|
getUnixTime,
|
|
|
|
mdToHtml,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2021-09-18 16:35:49 +00:00
|
|
|
numToSI,
|
|
|
|
wsClient,
|
|
|
|
} from "../../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { BannerIconHeader } from "../common/banner-icon-header";
|
2022-06-23 19:44:05 +00:00
|
|
|
import { Icon, PurgeWarning, Spinner } from "../common/icon";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { CommunityForm } from "../community/community-form";
|
|
|
|
import { CommunityLink } from "../community/community-link";
|
|
|
|
import { PersonListing } from "../person/person-listing";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface SidebarProps {
|
2020-12-24 01:58:27 +00:00
|
|
|
community_view: CommunityView;
|
|
|
|
moderators: CommunityModeratorView[];
|
2021-03-15 18:09:31 +00:00
|
|
|
admins: PersonViewSafe[];
|
2022-12-19 15:57:29 +00:00
|
|
|
allLanguages: Language[];
|
|
|
|
siteLanguages: number[];
|
2023-01-04 16:56:24 +00:00
|
|
|
communityLanguages?: number[];
|
2020-09-06 16:15:25 +00:00
|
|
|
online: number;
|
2022-06-21 21:42:29 +00:00
|
|
|
enableNsfw?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
showIcon?: boolean;
|
2022-12-19 15:57:29 +00:00
|
|
|
editable?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface SidebarState {
|
2023-01-04 16:56:24 +00:00
|
|
|
removeReason?: string;
|
|
|
|
removeExpires?: string;
|
2020-09-06 16:15:25 +00:00
|
|
|
showEdit: boolean;
|
|
|
|
showRemoveDialog: boolean;
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
purgeReason?: string;
|
2022-06-23 19:44:05 +00:00
|
|
|
purgeLoading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
showConfirmLeaveModTeam: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Sidebar extends Component<SidebarProps, SidebarState> {
|
2023-01-04 16:56:24 +00:00
|
|
|
state: SidebarState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
2022-06-23 19:44:05 +00:00
|
|
|
showPurgeDialog: false,
|
|
|
|
purgeLoading: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
showConfirmLeaveModTeam: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleEditCommunity = this.handleEditCommunity.bind(this);
|
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!this.state.showEdit ? (
|
|
|
|
this.sidebar()
|
|
|
|
) : (
|
|
|
|
<CommunityForm
|
2023-01-04 16:56:24 +00:00
|
|
|
community_view={this.props.community_view}
|
2022-12-19 15:57:29 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
|
|
|
siteLanguages={this.props.siteLanguages}
|
|
|
|
communityLanguages={this.props.communityLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
onEdit={this.handleEditCommunity}
|
|
|
|
onCancel={this.handleEditCancel}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sidebar() {
|
|
|
|
return (
|
|
|
|
<div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="card border-secondary mb-3">
|
|
|
|
<div className="card-body">
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.communityTitle()}
|
2022-12-19 15:57:29 +00:00
|
|
|
{this.props.editable && this.adminButtons()}
|
2020-09-23 23:01:45 +00:00
|
|
|
{this.subscribe()}
|
2022-05-23 19:22:15 +00:00
|
|
|
{this.canPost && this.createPost()}
|
2022-09-21 14:04:57 +00:00
|
|
|
{this.blockCommunity()}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="card border-secondary mb-3">
|
|
|
|
<div className="card-body">
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.description()}
|
|
|
|
{this.badges()}
|
|
|
|
{this.mods()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
communityTitle() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let community = this.props.community_view.community;
|
|
|
|
let subscribed = this.props.community_view.subscribed;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h5 className="mb-0">
|
|
|
|
{this.props.showIcon && (
|
|
|
|
<BannerIconHeader icon={community.icon} banner={community.banner} />
|
|
|
|
)}
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-2">{community.title}</span>
|
2022-06-23 13:35:53 +00:00
|
|
|
{subscribed == SubscribedType.Subscribed && (
|
2022-07-30 03:38:37 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary btn-sm mr-2"
|
2021-08-20 02:56:18 +00:00
|
|
|
onClick={linkEvent(this, this.handleUnsubscribe)}
|
2020-09-23 23:01:45 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="check" classes="icon-inline text-success mr-1" />
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("joined")}
|
2022-07-30 03:38:37 +00:00
|
|
|
</button>
|
2020-09-23 23:01:45 +00:00
|
|
|
)}
|
2022-06-23 13:35:53 +00:00
|
|
|
{subscribed == SubscribedType.Pending && (
|
2022-07-30 03:38:37 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-warning mr-2"
|
2022-07-11 18:07:47 +00:00
|
|
|
onClick={linkEvent(this, this.handleUnsubscribe)}
|
|
|
|
>
|
2022-06-23 13:35:53 +00:00
|
|
|
{i18n.t("subscribe_pending")}
|
2022-07-30 03:38:37 +00:00
|
|
|
</button>
|
2022-06-23 13:35:53 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
{community.removed && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<small className="mr-2 text-muted font-italic">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("removed")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{community.deleted && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<small className="mr-2 text-muted font-italic">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("deleted")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
{community.nsfw && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<small className="mr-2 text-muted font-italic">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("nsfw")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
<CommunityLink
|
|
|
|
community={community}
|
|
|
|
realLink
|
|
|
|
useApubName
|
|
|
|
muted
|
|
|
|
hideAvatar
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
badges() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let community_view = this.props.community_view;
|
2021-01-29 15:10:37 +00:00
|
|
|
let counts = community_view.counts;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<ul className="my-1 list-inline">
|
2020-09-23 23:01:45 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-09-18 16:35:49 +00:00
|
|
|
{i18n.t("number_online", {
|
|
|
|
count: this.props.online,
|
|
|
|
formattedCount: numToSI(this.props.online),
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
2021-02-02 17:12:16 +00:00
|
|
|
<li
|
|
|
|
className="list-inline-item badge badge-secondary pointer"
|
2021-09-18 17:06:12 +00:00
|
|
|
data-tippy-content={i18n.t("active_users_in_the_last_day", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_day,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: counts.users_active_day,
|
2021-09-18 17:06:12 +00:00
|
|
|
})}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_day,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.users_active_day),
|
2021-02-22 02:39:04 +00:00
|
|
|
})}{" "}
|
|
|
|
/ {i18n.t("day")}
|
2021-01-29 15:10:37 +00:00
|
|
|
</li>
|
2021-02-02 17:12:16 +00:00
|
|
|
<li
|
|
|
|
className="list-inline-item badge badge-secondary pointer"
|
2021-09-18 17:06:12 +00:00
|
|
|
data-tippy-content={i18n.t("active_users_in_the_last_week", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_week,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: counts.users_active_week,
|
2021-09-18 17:06:12 +00:00
|
|
|
})}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_week,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.users_active_week),
|
2021-02-22 02:39:04 +00:00
|
|
|
})}{" "}
|
|
|
|
/ {i18n.t("week")}
|
2021-01-29 15:10:37 +00:00
|
|
|
</li>
|
2021-02-02 17:12:16 +00:00
|
|
|
<li
|
|
|
|
className="list-inline-item badge badge-secondary pointer"
|
2021-09-18 17:06:12 +00:00
|
|
|
data-tippy-content={i18n.t("active_users_in_the_last_month", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_month,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: counts.users_active_month,
|
2021-09-18 17:06:12 +00:00
|
|
|
})}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_month,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.users_active_month),
|
2021-02-22 02:39:04 +00:00
|
|
|
})}{" "}
|
|
|
|
/ {i18n.t("month")}
|
2021-01-29 15:10:37 +00:00
|
|
|
</li>
|
2021-02-02 17:12:16 +00:00
|
|
|
<li
|
|
|
|
className="list-inline-item badge badge-secondary pointer"
|
2021-09-18 17:06:12 +00:00
|
|
|
data-tippy-content={i18n.t("active_users_in_the_last_six_months", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_half_year,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: counts.users_active_half_year,
|
2021-09-18 17:06:12 +00:00
|
|
|
})}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_half_year,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.users_active_half_year),
|
2021-02-22 02:39:04 +00:00
|
|
|
})}{" "}
|
2021-09-18 16:35:49 +00:00
|
|
|
/ {i18n.t("number_of_months", { count: 6, formattedCount: 6 })}
|
2021-01-29 15:10:37 +00:00
|
|
|
</li>
|
2020-09-23 23:01:45 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_subscribers", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.subscribers,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.subscribers),
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
</li>
|
2020-09-23 23:01:45 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_posts", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.posts,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.posts),
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
</li>
|
2020-09-23 23:01:45 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("number_of_comments", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.comments,
|
2021-09-18 16:35:49 +00:00
|
|
|
formattedCount: numToSI(counts.comments),
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<Link
|
2022-01-06 16:26:06 +00:00
|
|
|
className="badge badge-primary"
|
2020-12-24 01:58:27 +00:00
|
|
|
to={`/modlog/community/${this.props.community_view.community.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("modlog")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mods() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<ul className="list-inline small">
|
|
|
|
<li className="list-inline-item">{i18n.t("mods")}: </li>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.moderators.map(mod => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<li key={mod.moderator.id} className="list-inline-item">
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={mod.moderator} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-23 23:01:45 +00:00
|
|
|
createPost() {
|
2022-05-23 19:22:15 +00:00
|
|
|
let cv = this.props.community_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-21 14:04:57 +00:00
|
|
|
<Link
|
|
|
|
className={`btn btn-secondary btn-block mb-2 ${
|
|
|
|
cv.community.deleted || cv.community.removed ? "no-click" : ""
|
|
|
|
}`}
|
|
|
|
to={`/create_post?community_id=${cv.community.id}`}
|
|
|
|
>
|
|
|
|
{i18n.t("create_a_post")}
|
|
|
|
</Link>
|
2020-09-23 23:01:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribe() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let community_view = this.props.community_view;
|
2020-09-23 23:01:45 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="mb-2">
|
2022-06-23 13:35:53 +00:00
|
|
|
{community_view.subscribed == SubscribedType.NotSubscribed && (
|
2022-09-21 14:04:57 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary btn-block"
|
2022-09-21 14:04:57 +00:00
|
|
|
onClick={linkEvent(this, this.handleSubscribe)}
|
|
|
|
>
|
|
|
|
{i18n.t("subscribe")}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
blockCommunity() {
|
|
|
|
let community_view = this.props.community_view;
|
|
|
|
let blocked = this.props.community_view.blocked;
|
|
|
|
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="mb-2">
|
2022-09-21 14:04:57 +00:00
|
|
|
{community_view.subscribed == SubscribedType.NotSubscribed &&
|
|
|
|
(blocked ? (
|
2022-07-30 03:38:37 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-danger btn-block"
|
2022-09-21 14:04:57 +00:00
|
|
|
onClick={linkEvent(this, this.handleUnblock)}
|
2022-07-30 03:38:37 +00:00
|
|
|
>
|
2022-09-21 14:04:57 +00:00
|
|
|
{i18n.t("unblock_community")}
|
2022-07-30 03:38:37 +00:00
|
|
|
</button>
|
2022-09-21 14:04:57 +00:00
|
|
|
) : (
|
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-danger btn-block"
|
2022-09-21 14:04:57 +00:00
|
|
|
onClick={linkEvent(this, this.handleBlock)}
|
|
|
|
>
|
|
|
|
{i18n.t("block_community")}
|
|
|
|
</button>
|
|
|
|
))}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let desc = this.props.community_view.community.description;
|
|
|
|
return (
|
|
|
|
desc && (
|
2022-06-21 21:42:29 +00:00
|
|
|
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(desc)} />
|
2023-01-04 16:56:24 +00:00
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adminButtons() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let community_view = this.props.community_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-09-22 15:03:35 +00:00
|
|
|
<ul className="list-inline mb-1 text-muted font-weight-bold">
|
2023-01-04 16:56:24 +00:00
|
|
|
{amMod(this.props.moderators) && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<>
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
2021-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={i18n.t("edit")}
|
|
|
|
aria-label={i18n.t("edit")}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="edit" classes="icon-inline" />
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
2023-01-04 16:56:24 +00:00
|
|
|
{!amTopMod(this.props.moderators) &&
|
2020-09-06 16:15:25 +00:00
|
|
|
(!this.state.showConfirmLeaveModTeam ? (
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleShowConfirmLeaveModTeamClick
|
|
|
|
)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("leave_mod_team")}
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<li className="list-inline-item-action">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("are_you_sure")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleLeaveModTeamClick)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("yes")}
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleCancelLeaveModTeamClick
|
|
|
|
)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("no")}
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
))}
|
2023-01-04 16:56:24 +00:00
|
|
|
{amTopMod(this.props.moderators) && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleDeleteClick)}
|
|
|
|
data-tippy-content={
|
2020-12-24 01:58:27 +00:00
|
|
|
!community_view.community.deleted
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-02-06 20:20:41 +00:00
|
|
|
aria-label={
|
|
|
|
!community_view.community.deleted
|
2021-02-22 02:39:04 +00:00
|
|
|
? i18n.t("delete")
|
|
|
|
: i18n.t("restore")
|
2021-02-06 20:20:41 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon
|
|
|
|
icon="trash"
|
|
|
|
classes={`icon-inline ${
|
2021-02-22 02:39:04 +00:00
|
|
|
community_view.community.deleted && "text-danger"
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2021-02-11 20:35:27 +00:00
|
|
|
/>
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2022-09-28 12:50:47 +00:00
|
|
|
{amAdmin() && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item">
|
2020-12-24 01:58:27 +00:00
|
|
|
{!this.props.community_view.community.removed ? (
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleModRemoveShow)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("remove")}
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
) : (
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleModRemoveSubmit)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("restore")}
|
2021-07-17 20:42:55 +00:00
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
2022-06-23 19:44:05 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-link text-muted d-inline-block"
|
2022-06-23 19:44:05 +00:00
|
|
|
onClick={linkEvent(this, this.handlePurgeCommunityShow)}
|
|
|
|
aria-label={i18n.t("purge_community")}
|
|
|
|
>
|
|
|
|
{i18n.t("purge_community")}
|
|
|
|
</button>
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleModRemoveSubmit)}>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<label className="col-form-label" htmlFor="remove-reason">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("reason")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="remove-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("optional")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.removeReason}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{/* TODO hold off on expires for now */}
|
|
|
|
{/* <div class="form-group row"> */}
|
|
|
|
{/* <label class="col-form-label">Expires</label> */}
|
|
|
|
{/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.removeExpires} onInput={linkEvent(this, this.handleModRemoveExpiresChange)} /> */}
|
|
|
|
{/* </div> */}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<button type="submit" className="btn btn-secondary">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("remove_community")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
2022-06-23 19:44:05 +00:00
|
|
|
{this.state.showPurgeDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handlePurgeSubmit)}>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
2022-06-23 19:44:05 +00:00
|
|
|
<PurgeWarning />
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<label className="sr-only" htmlFor="purge-reason">
|
2022-06-23 19:44:05 +00:00
|
|
|
{i18n.t("reason")}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="purge-reason"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control mr-2"
|
2022-06-23 19:44:05 +00:00
|
|
|
placeholder={i18n.t("reason")}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.purgeReason}
|
2022-06-23 19:44:05 +00:00
|
|
|
onInput={linkEvent(this, this.handlePurgeReasonChange)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
2022-06-23 19:44:05 +00:00
|
|
|
{this.state.purgeLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2022-06-23 19:44:05 +00:00
|
|
|
aria-label={i18n.t("purge_community")}
|
|
|
|
>
|
|
|
|
{i18n.t("purge_community")}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: Sidebar) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showEdit: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCommunity() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ showEdit: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCancel() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ showEdit: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 23:01:45 +00:00
|
|
|
handleDeleteClick(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let deleteForm: DeleteCommunity = {
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
deleted: !i.props.community_view.community.deleted,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.deleteCommunity(deleteForm));
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmLeaveModTeamClick(i: Sidebar) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmLeaveModTeam: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLeaveModTeamClick(i: Sidebar) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let mui = UserService.Instance.myUserInfo;
|
|
|
|
let auth = myAuth();
|
|
|
|
if (auth && mui) {
|
|
|
|
let form: AddModToCommunity = {
|
|
|
|
person_id: mui.local_user_view.person.id,
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
added: false,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
|
|
|
i.setState({ showConfirmLeaveModTeam: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelLeaveModTeamClick(i: Sidebar) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showConfirmLeaveModTeam: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 02:56:18 +00:00
|
|
|
handleUnsubscribe(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2021-08-20 02:56:18 +00:00
|
|
|
let community_id = i.props.community_view.community.id;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: FollowCommunity = {
|
|
|
|
community_id,
|
|
|
|
follow: false,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
|
|
|
}
|
2021-08-20 02:56:18 +00:00
|
|
|
|
|
|
|
// Update myUserInfo
|
2023-01-04 16:56:24 +00:00
|
|
|
let mui = UserService.Instance.myUserInfo;
|
|
|
|
if (mui) {
|
|
|
|
mui.follows = mui.follows.filter(i => i.community.id != community_id);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 02:56:18 +00:00
|
|
|
handleSubscribe(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2021-08-20 02:56:18 +00:00
|
|
|
let community_id = i.props.community_view.community.id;
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: FollowCommunity = {
|
|
|
|
community_id,
|
|
|
|
follow: true,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
|
|
|
}
|
2021-08-20 02:56:18 +00:00
|
|
|
|
|
|
|
// Update myUserInfo
|
2023-01-04 16:56:24 +00:00
|
|
|
let mui = UserService.Instance.myUserInfo;
|
|
|
|
if (mui) {
|
|
|
|
mui.follows.push({
|
|
|
|
community: i.props.community_view.community,
|
|
|
|
follower: mui.local_user_view.person,
|
|
|
|
});
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 19:22:15 +00:00
|
|
|
get canPost(): boolean {
|
|
|
|
return (
|
|
|
|
!this.props.community_view.community.posting_restricted_to_mods ||
|
2023-01-04 16:56:24 +00:00
|
|
|
amMod(this.props.moderators) ||
|
2022-09-28 12:50:47 +00:00
|
|
|
amAdmin()
|
2022-05-23 19:22:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleModRemoveShow(i: Sidebar) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showRemoveDialog: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: Sidebar, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ removeReason: event.target.value });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveExpiresChange(i: Sidebar, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ removeExpires: event.target.value });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 23:01:45 +00:00
|
|
|
handleModRemoveSubmit(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let removeForm: RemoveCommunity = {
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
removed: !i.props.community_view.community.removed,
|
|
|
|
reason: i.state.removeReason,
|
|
|
|
expires: getUnixTime(i.state.removeExpires),
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.removeCommunity(removeForm));
|
|
|
|
|
|
|
|
i.setState({ showRemoveDialog: false });
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-06-23 19:44:05 +00:00
|
|
|
|
|
|
|
handlePurgeCommunityShow(i: Sidebar) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showPurgeDialog: true, showRemoveDialog: false });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeReasonChange(i: Sidebar, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.setState({ purgeReason: event.target.value });
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handlePurgeSubmit(i: Sidebar, event: any) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let form: PurgeCommunity = {
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
reason: i.state.purgeReason,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.purgeCommunity(form));
|
|
|
|
i.setState({ purgeLoading: true });
|
|
|
|
}
|
2022-06-23 19:44:05 +00:00
|
|
|
}
|
2022-07-30 03:38:37 +00:00
|
|
|
|
|
|
|
handleBlock(i: Sidebar, event: any) {
|
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let blockCommunityForm: BlockCommunity = {
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
block: true,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.blockCommunity(blockCommunityForm)
|
|
|
|
);
|
|
|
|
}
|
2022-07-30 03:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleUnblock(i: Sidebar, event: any) {
|
|
|
|
event.preventDefault();
|
2023-01-04 16:56:24 +00:00
|
|
|
let auth = myAuth();
|
|
|
|
if (auth) {
|
|
|
|
let blockCommunityForm: BlockCommunity = {
|
|
|
|
community_id: i.props.community_view.community.id,
|
|
|
|
block: false,
|
|
|
|
auth,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.blockCommunity(blockCommunityForm)
|
|
|
|
);
|
|
|
|
}
|
2022-07-30 03:38:37 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|