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,
|
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,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
RemoveCommunity,
|
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";
|
|
|
|
import { authField, getUnixTime, mdToHtml, wsClient } from "../../utils";
|
|
|
|
import { BannerIconHeader } from "../common/banner-icon-header";
|
|
|
|
import { Icon } from "../common/icon";
|
|
|
|
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[];
|
2020-09-06 16:15:25 +00:00
|
|
|
online: number;
|
|
|
|
enableNsfw: boolean;
|
|
|
|
showIcon?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SidebarState {
|
|
|
|
showEdit: boolean;
|
|
|
|
showRemoveDialog: boolean;
|
|
|
|
removeReason: string;
|
|
|
|
removeExpires: string;
|
|
|
|
showConfirmLeaveModTeam: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Sidebar extends Component<SidebarProps, SidebarState> {
|
|
|
|
private emptyState: SidebarState = {
|
|
|
|
showEdit: false,
|
|
|
|
showRemoveDialog: false,
|
|
|
|
removeReason: null,
|
|
|
|
removeExpires: null,
|
|
|
|
showConfirmLeaveModTeam: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleEditCommunity = this.handleEditCommunity.bind(this);
|
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!this.state.showEdit ? (
|
|
|
|
this.sidebar()
|
|
|
|
) : (
|
|
|
|
<CommunityForm
|
2020-12-24 01:58:27 +00:00
|
|
|
community_view={this.props.community_view}
|
2020-09-06 16:15:25 +00:00
|
|
|
onEdit={this.handleEditCommunity}
|
|
|
|
onCancel={this.handleEditCancel}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sidebar() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.communityTitle()}
|
|
|
|
{this.adminButtons()}
|
2020-09-23 23:01:45 +00:00
|
|
|
{this.subscribe()}
|
|
|
|
{this.createPost()}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-23 23:01:45 +00:00
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">
|
|
|
|
{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} />
|
|
|
|
)}
|
2020-09-23 23:01:45 +00:00
|
|
|
<span class="mr-2">{community.title}</span>
|
2020-12-24 01:58:27 +00:00
|
|
|
{subscribed && (
|
2020-09-23 23:01:45 +00:00
|
|
|
<a
|
|
|
|
class="btn btn-secondary btn-sm mr-2"
|
|
|
|
href="#"
|
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")}
|
2020-09-23 23:01:45 +00:00
|
|
|
</a>
|
|
|
|
)}
|
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 (
|
|
|
|
<ul class="my-1 list-inline">
|
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_online", { count: 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-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={`${i18n.t("number_of_users", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_day,
|
2021-02-22 02:39:04 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("day")}`}
|
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-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-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={`${i18n.t("number_of_users", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_week,
|
2021-02-22 02:39:04 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("week")}`}
|
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-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-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={`${i18n.t("number_of_users", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_month,
|
2021-02-22 02:39:04 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("month")}`}
|
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-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-02-22 02:39:04 +00:00
|
|
|
data-tippy-content={`${i18n.t("number_of_users", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: counts.users_active_half_year,
|
2021-02-22 02:39:04 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("number_of_months", {
|
2021-02-02 17:12:16 +00:00
|
|
|
count: 6,
|
|
|
|
})}`}
|
|
|
|
>
|
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-02-22 02:39:04 +00:00
|
|
|
})}{" "}
|
|
|
|
/ {i18n.t("number_of_months", { count: 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,
|
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,
|
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,
|
2020-09-06 16:15:25 +00:00
|
|
|
})}
|
|
|
|
</li>
|
|
|
|
<li className="list-inline-item">
|
|
|
|
<Link
|
2020-09-23 23:01:45 +00:00
|
|
|
className="badge badge-secondary"
|
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 (
|
|
|
|
<ul class="list-inline small">
|
2021-02-22 02:39:04 +00:00
|
|
|
<li class="list-inline-item">{i18n.t("mods")}: </li>
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.props.moderators.map(mod => (
|
|
|
|
<li class="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() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let community_view = this.props.community_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2020-12-24 01:58:27 +00:00
|
|
|
community_view.subscribed && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<Link
|
2020-09-23 23:01:45 +00:00
|
|
|
className={`btn btn-secondary btn-block mb-2 ${
|
2020-12-24 01:58:27 +00:00
|
|
|
community_view.community.deleted || community_view.community.removed
|
2021-02-22 02:39:04 +00:00
|
|
|
? "no-click"
|
|
|
|
: ""
|
2020-09-06 16:15:25 +00:00
|
|
|
}`}
|
2020-12-24 01:58:27 +00:00
|
|
|
to={`/create_post?community_id=${community_view.community.id}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("create_a_post")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</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 (
|
|
|
|
<div class="mb-2">
|
2020-12-24 01:58:27 +00:00
|
|
|
{!community_view.subscribed && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<a
|
2020-09-23 23:01:45 +00:00
|
|
|
class="btn btn-secondary btn-block"
|
2020-09-06 16:15:25 +00:00
|
|
|
href="#"
|
2021-08-20 02:56:18 +00:00
|
|
|
onClick={linkEvent(this, this.handleSubscribe)}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("subscribe")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let description = this.props.community_view.community.description;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2020-12-24 01:58:27 +00:00
|
|
|
description && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<div
|
|
|
|
className="md-div"
|
2020-12-24 01:58:27 +00:00
|
|
|
dangerouslySetInnerHTML={mdToHtml(description)}
|
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 (
|
|
|
|
<>
|
|
|
|
<ul class="list-inline mb-1 text-muted font-weight-bold">
|
|
|
|
{this.canMod && (
|
|
|
|
<>
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
|
|
|
class="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>
|
2021-04-09 01:59:34 +00:00
|
|
|
{!this.amTopMod &&
|
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
|
|
|
|
class="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
|
|
|
|
class="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
|
|
|
|
class="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>
|
|
|
|
</>
|
|
|
|
))}
|
2021-04-09 01:59:34 +00:00
|
|
|
{this.amTopMod && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
|
|
|
class="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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{this.canAdmin && (
|
|
|
|
<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
|
|
|
|
class="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
|
|
|
|
class="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
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
{this.state.showRemoveDialog && (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleModRemoveSubmit)}>
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="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"
|
|
|
|
class="form-control mr-2"
|
2021-02-22 02:39:04 +00:00
|
|
|
placeholder={i18n.t("optional")}
|
2020-09-06 16:15:25 +00:00
|
|
|
value={this.state.removeReason}
|
|
|
|
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> */}
|
|
|
|
<div class="form-group row">
|
|
|
|
<button type="submit" class="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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick(i: Sidebar) {
|
|
|
|
i.state.showEdit = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCommunity() {
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCancel() {
|
|
|
|
this.state.showEdit = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2020-09-23 23:01:45 +00:00
|
|
|
handleDeleteClick(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2020-12-24 01:58:27 +00:00
|
|
|
let deleteForm: DeleteCommunity = {
|
2021-01-18 22:42:41 +00:00
|
|
|
community_id: i.props.community_view.community.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
deleted: !i.props.community_view.community.deleted,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.deleteCommunity(deleteForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleShowConfirmLeaveModTeamClick(i: Sidebar) {
|
|
|
|
i.state.showConfirmLeaveModTeam = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLeaveModTeamClick(i: Sidebar) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: AddModToCommunity = {
|
2021-08-20 02:56:18 +00:00
|
|
|
person_id: UserService.Instance.myUserInfo.local_user_view.person.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
community_id: i.props.community_view.community.id,
|
2020-09-06 16:15:25 +00:00
|
|
|
added: false,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.addModToCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.showConfirmLeaveModTeam = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCancelLeaveModTeamClick(i: Sidebar) {
|
|
|
|
i.state.showConfirmLeaveModTeam = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
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;
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: FollowCommunity = {
|
2021-08-20 02:56:18 +00:00
|
|
|
community_id,
|
2020-09-06 16:15:25 +00:00
|
|
|
follow: false,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
2021-08-20 02:56:18 +00:00
|
|
|
|
|
|
|
// Update myUserInfo
|
|
|
|
UserService.Instance.myUserInfo.follows =
|
|
|
|
UserService.Instance.myUserInfo.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;
|
2020-12-24 01:58:27 +00:00
|
|
|
let form: FollowCommunity = {
|
2021-08-20 02:56:18 +00:00
|
|
|
community_id,
|
2020-09-06 16:15:25 +00:00
|
|
|
follow: true,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.followCommunity(form));
|
2021-08-20 02:56:18 +00:00
|
|
|
|
|
|
|
// Update myUserInfo
|
|
|
|
UserService.Instance.myUserInfo.follows.push({
|
|
|
|
community: i.props.community_view.community,
|
|
|
|
follower: UserService.Instance.myUserInfo.local_user_view.person,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 01:59:34 +00:00
|
|
|
private get amTopMod(): boolean {
|
2021-03-15 18:09:31 +00:00
|
|
|
return (
|
2021-04-09 01:59:34 +00:00
|
|
|
this.props.moderators[0].moderator.id ==
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo.local_user_view.person.id
|
2021-03-15 18:09:31 +00:00
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get canMod(): boolean {
|
|
|
|
return (
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2020-09-06 16:15:25 +00:00
|
|
|
this.props.moderators
|
2020-12-24 01:58:27 +00:00
|
|
|
.map(m => m.moderator.id)
|
2021-08-20 02:56:18 +00:00
|
|
|
.includes(UserService.Instance.myUserInfo.local_user_view.person.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get canAdmin(): boolean {
|
|
|
|
return (
|
2021-08-20 02:56:18 +00:00
|
|
|
UserService.Instance.myUserInfo &&
|
2020-12-24 01:58:27 +00:00
|
|
|
this.props.admins
|
2021-03-15 18:09:31 +00:00
|
|
|
.map(a => a.person.id)
|
2021-08-20 02:56:18 +00:00
|
|
|
.includes(UserService.Instance.myUserInfo.local_user_view.person.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveShow(i: Sidebar) {
|
|
|
|
i.state.showRemoveDialog = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveReasonChange(i: Sidebar, event: any) {
|
|
|
|
i.state.removeReason = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModRemoveExpiresChange(i: Sidebar, event: any) {
|
|
|
|
console.log(event.target.value);
|
|
|
|
i.state.removeExpires = event.target.value;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-09-23 23:01:45 +00:00
|
|
|
handleModRemoveSubmit(i: Sidebar, event: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
event.preventDefault();
|
2020-12-24 01:58:27 +00:00
|
|
|
let removeForm: RemoveCommunity = {
|
2021-01-18 22:42:41 +00:00
|
|
|
community_id: i.props.community_view.community.id,
|
2020-12-24 01:58:27 +00:00
|
|
|
removed: !i.props.community_view.community.removed,
|
2020-09-06 16:15:25 +00:00
|
|
|
reason: i.state.removeReason,
|
|
|
|
expires: getUnixTime(i.state.removeExpires),
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.removeCommunity(removeForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
i.state.showRemoveDialog = false;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
}
|