mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 14:45:20 +00:00
* Adding block from community sidebar. Fixes #690 * Fixing lint
This commit is contained in:
parent
b2cab8d126
commit
e68babe38b
|
@ -3,6 +3,7 @@ import { Component, linkEvent } from "inferno";
|
||||||
import {
|
import {
|
||||||
AddModToCommunityResponse,
|
AddModToCommunityResponse,
|
||||||
BanFromCommunityResponse,
|
BanFromCommunityResponse,
|
||||||
|
BlockCommunityResponse,
|
||||||
BlockPersonResponse,
|
BlockPersonResponse,
|
||||||
CommentReportResponse,
|
CommentReportResponse,
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
|
@ -53,6 +54,7 @@ import {
|
||||||
setupTippy,
|
setupTippy,
|
||||||
showLocal,
|
showLocal,
|
||||||
toast,
|
toast,
|
||||||
|
updateCommunityBlock,
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
wsClient,
|
wsClient,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
|
@ -663,6 +665,17 @@ export class Community extends Component<any, State> {
|
||||||
toast(i18n.t("purge_success"));
|
toast(i18n.t("purge_success"));
|
||||||
this.context.router.history.push(`/`);
|
this.context.router.history.push(`/`);
|
||||||
}
|
}
|
||||||
|
} else if (op == UserOperation.BlockCommunity) {
|
||||||
|
let data = wsJsonToRes<BlockCommunityResponse>(
|
||||||
|
msg,
|
||||||
|
BlockCommunityResponse
|
||||||
|
);
|
||||||
|
this.state.communityRes.match({
|
||||||
|
some: res => (res.community_view.blocked = data.blocked),
|
||||||
|
none: void 0,
|
||||||
|
});
|
||||||
|
updateCommunityBlock(data);
|
||||||
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Component, linkEvent } from "inferno";
|
||||||
import { Link } from "inferno-router";
|
import { Link } from "inferno-router";
|
||||||
import {
|
import {
|
||||||
AddModToCommunity,
|
AddModToCommunity,
|
||||||
|
BlockCommunity,
|
||||||
CommunityModeratorView,
|
CommunityModeratorView,
|
||||||
CommunityView,
|
CommunityView,
|
||||||
DeleteCommunity,
|
DeleteCommunity,
|
||||||
|
@ -120,23 +121,21 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
)}
|
)}
|
||||||
<span class="mr-2">{community.title}</span>
|
<span class="mr-2">{community.title}</span>
|
||||||
{subscribed == SubscribedType.Subscribed && (
|
{subscribed == SubscribedType.Subscribed && (
|
||||||
<a
|
<button
|
||||||
class="btn btn-secondary btn-sm mr-2"
|
class="btn btn-secondary btn-sm mr-2"
|
||||||
href="#"
|
|
||||||
onClick={linkEvent(this, this.handleUnsubscribe)}
|
onClick={linkEvent(this, this.handleUnsubscribe)}
|
||||||
>
|
>
|
||||||
<Icon icon="check" classes="icon-inline text-success mr-1" />
|
<Icon icon="check" classes="icon-inline text-success mr-1" />
|
||||||
{i18n.t("joined")}
|
{i18n.t("joined")}
|
||||||
</a>
|
</button>
|
||||||
)}
|
)}
|
||||||
{subscribed == SubscribedType.Pending && (
|
{subscribed == SubscribedType.Pending && (
|
||||||
<a
|
<button
|
||||||
class="btn btn-warning mr-2"
|
class="btn btn-warning mr-2"
|
||||||
href="#"
|
|
||||||
onClick={linkEvent(this, this.handleUnsubscribe)}
|
onClick={linkEvent(this, this.handleUnsubscribe)}
|
||||||
>
|
>
|
||||||
{i18n.t("subscribe_pending")}
|
{i18n.t("subscribe_pending")}
|
||||||
</a>
|
</button>
|
||||||
)}
|
)}
|
||||||
{community.removed && (
|
{community.removed && (
|
||||||
<small className="mr-2 text-muted font-italic">
|
<small className="mr-2 text-muted font-italic">
|
||||||
|
@ -289,16 +288,33 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
|
|
||||||
subscribe() {
|
subscribe() {
|
||||||
let community_view = this.props.community_view;
|
let community_view = this.props.community_view;
|
||||||
|
let blocked = this.props.community_view.blocked;
|
||||||
return (
|
return (
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{community_view.subscribed == SubscribedType.NotSubscribed && (
|
{community_view.subscribed == SubscribedType.NotSubscribed && (
|
||||||
<a
|
<>
|
||||||
class="btn btn-secondary btn-block"
|
<button
|
||||||
href="#"
|
class="btn btn-secondary btn-block"
|
||||||
onClick={linkEvent(this, this.handleSubscribe)}
|
onClick={linkEvent(this, this.handleSubscribe)}
|
||||||
>
|
>
|
||||||
{i18n.t("subscribe")}
|
{i18n.t("subscribe")}
|
||||||
</a>
|
</button>
|
||||||
|
{blocked ? (
|
||||||
|
<button
|
||||||
|
class="btn btn-danger btn-block"
|
||||||
|
onClick={linkEvent(this, this.handleUnblock)}
|
||||||
|
>
|
||||||
|
{i18n.t("unblock_community")}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
class="btn btn-danger btn-block"
|
||||||
|
onClick={linkEvent(this, this.handleBlock)}
|
||||||
|
>
|
||||||
|
{i18n.t("block_community")}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -641,4 +657,24 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
|
||||||
i.state.purgeLoading = true;
|
i.state.purgeLoading = true;
|
||||||
i.setState(i.state);
|
i.setState(i.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBlock(i: Sidebar, event: any) {
|
||||||
|
event.preventDefault();
|
||||||
|
let blockCommunityForm = new BlockCommunity({
|
||||||
|
community_id: i.props.community_view.community.id,
|
||||||
|
block: true,
|
||||||
|
auth: auth().unwrap(),
|
||||||
|
});
|
||||||
|
WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUnblock(i: Sidebar, event: any) {
|
||||||
|
event.preventDefault();
|
||||||
|
let blockCommunityForm = new BlockCommunity({
|
||||||
|
community_id: i.props.community_view.community.id,
|
||||||
|
block: false,
|
||||||
|
auth: auth().unwrap(),
|
||||||
|
});
|
||||||
|
WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue