import { myAuthRequired } from "@utils/app"; import { getUnixTime, hostname } from "@utils/helpers"; import { amAdmin, amMod, amTopMod } from "@utils/roles"; import { Component, InfernoNode, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; import { Link } from "inferno-router"; import { AddModToCommunity, BlockCommunity, CommunityModeratorView, CommunityView, DeleteCommunity, EditCommunity, FollowCommunity, Language, PersonView, PurgeCommunity, RemoveCommunity, } from "lemmy-js-client"; import { mdToHtml } from "../../markdown"; import { I18NextService, UserService } from "../../services"; import { Badges } from "../common/badges"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { CommunityForm } from "../community/community-form"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; interface SidebarProps { community_view: CommunityView; moderators: CommunityModeratorView[]; admins: PersonView[]; allLanguages: Language[]; siteLanguages: number[]; communityLanguages?: number[]; enableNsfw?: boolean; showIcon?: boolean; editable?: boolean; onDeleteCommunity(form: DeleteCommunity): void; onRemoveCommunity(form: RemoveCommunity): void; onLeaveModTeam(form: AddModToCommunity): void; onFollowCommunity(form: FollowCommunity): void; onBlockCommunity(form: BlockCommunity): void; onPurgeCommunity(form: PurgeCommunity): void; onEditCommunity(form: EditCommunity): void; } interface SidebarState { removeReason?: string; removeExpires?: string; showEdit: boolean; showRemoveDialog: boolean; showPurgeDialog: boolean; purgeReason?: string; showConfirmLeaveModTeam: boolean; deleteCommunityLoading: boolean; removeCommunityLoading: boolean; leaveModTeamLoading: boolean; followCommunityLoading: boolean; purgeCommunityLoading: boolean; } export class Sidebar extends Component { state: SidebarState = { showEdit: false, showRemoveDialog: false, showPurgeDialog: false, showConfirmLeaveModTeam: false, deleteCommunityLoading: false, removeCommunityLoading: false, leaveModTeamLoading: false, followCommunityLoading: false, purgeCommunityLoading: false, }; constructor(props: any, context: any) { super(props, context); this.handleEditCancel = this.handleEditCancel.bind(this); } componentWillReceiveProps( nextProps: Readonly<{ children?: InfernoNode } & SidebarProps> ): void { if (this.props.moderators != nextProps.moderators) { this.setState({ showConfirmLeaveModTeam: false, }); } if (this.props.community_view != nextProps.community_view) { this.setState({ showEdit: false, showPurgeDialog: false, showRemoveDialog: false, deleteCommunityLoading: false, removeCommunityLoading: false, leaveModTeamLoading: false, followCommunityLoading: false, purgeCommunityLoading: false, }); } } render() { return (
{!this.state.showEdit ? ( this.sidebar() ) : ( )}
); } sidebar() { const myUSerInfo = UserService.Instance.myUserInfo; const { name, actor_id } = this.props.community_view.community; return ( ); } communityTitle() { const community = this.props.community_view.community; const subscribed = this.props.community_view.subscribed; return (
{this.props.showIcon && !community.removed && ( )} {subscribed === "Subscribed" && ( )} {subscribed === "Pending" && ( )} {community.removed && ( {I18NextService.i18n.t("removed")} )} {community.deleted && ( {I18NextService.i18n.t("deleted")} )} {community.nsfw && ( {I18NextService.i18n.t("nsfw")} )}
); } mods() { return ( ); } createPost() { const cv = this.props.community_view; return ( {I18NextService.i18n.t("create_a_post")} ); } subscribe() { const community_view = this.props.community_view; return ( <> {community_view.subscribed == "NotSubscribed" && ( )} ); } blockCommunity() { const { subscribed, blocked } = this.props.community_view; return ( <> {subscribed == "NotSubscribed" && ( )} ); } description() { const desc = this.props.community_view.community.description; return ( desc && (
) ); } adminButtons() { const community_view = this.props.community_view; return ( <> {this.state.showRemoveDialog && (
{/* TODO hold off on expires for now */} {/*
*/} {/* */} {/* */} {/*
*/}
)} {this.state.showPurgeDialog && (
{this.state.purgeCommunityLoading ? ( ) : ( )}
)} ); } handleEditClick(i: Sidebar) { i.setState({ showEdit: true }); } handleEditCancel() { this.setState({ showEdit: false }); } handleShowConfirmLeaveModTeamClick(i: Sidebar) { i.setState({ showConfirmLeaveModTeam: true }); } handleCancelLeaveModTeamClick(i: Sidebar) { i.setState({ showConfirmLeaveModTeam: false }); } get canPost(): boolean { return ( !this.props.community_view.community.posting_restricted_to_mods || amMod(this.props.moderators) || amAdmin() ); } handleModRemoveShow(i: Sidebar) { i.setState({ showRemoveDialog: true }); } handleModRemoveReasonChange(i: Sidebar, event: any) { i.setState({ removeReason: event.target.value }); } handleModRemoveExpiresChange(i: Sidebar, event: any) { i.setState({ removeExpires: event.target.value }); } handlePurgeCommunityShow(i: Sidebar) { i.setState({ showPurgeDialog: true, showRemoveDialog: false }); } handlePurgeReasonChange(i: Sidebar, event: any) { i.setState({ purgeReason: event.target.value }); } // TODO Do we need two of these? handleUnfollowCommunity(i: Sidebar) { i.setState({ followCommunityLoading: true }); i.props.onFollowCommunity({ community_id: i.props.community_view.community.id, follow: false, auth: myAuthRequired(), }); } handleFollowCommunity(i: Sidebar) { i.setState({ followCommunityLoading: true }); i.props.onFollowCommunity({ community_id: i.props.community_view.community.id, follow: true, auth: myAuthRequired(), }); } handleBlockCommunity(i: Sidebar) { const { community, blocked } = i.props.community_view; i.props.onBlockCommunity({ community_id: community.id, block: !blocked, auth: myAuthRequired(), }); } handleLeaveModTeam(i: Sidebar) { const myId = UserService.Instance.myUserInfo?.local_user_view.person.id; if (myId) { i.setState({ leaveModTeamLoading: true }); i.props.onLeaveModTeam({ community_id: i.props.community_view.community.id, person_id: 92, added: false, auth: myAuthRequired(), }); } } handleDeleteCommunity(i: Sidebar) { i.setState({ deleteCommunityLoading: true }); i.props.onDeleteCommunity({ community_id: i.props.community_view.community.id, deleted: !i.props.community_view.community.deleted, auth: myAuthRequired(), }); } handleRemoveCommunity(i: Sidebar, event: any) { event.preventDefault(); i.setState({ removeCommunityLoading: true }); i.props.onRemoveCommunity({ community_id: i.props.community_view.community.id, removed: !i.props.community_view.community.removed, reason: i.state.removeReason, expires: getUnixTime(i.state.removeExpires), // TODO fix this auth: myAuthRequired(), }); } handlePurgeCommunity(i: Sidebar, event: any) { event.preventDefault(); i.setState({ purgeCommunityLoading: true }); i.props.onPurgeCommunity({ community_id: i.props.community_view.community.id, reason: i.state.purgeReason, auth: myAuthRequired(), }); } }