2021-07-18 03:56:33 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2023-04-15 14:47:10 +00:00
|
|
|
import { RouteComponentProps } from "inferno-router/dist/Route";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2023-06-14 12:20:40 +00:00
|
|
|
AddAdmin,
|
|
|
|
AddModToCommunity,
|
2020-09-06 16:15:25 +00:00
|
|
|
AddModToCommunityResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
BanFromCommunity,
|
2020-09-06 16:15:25 +00:00
|
|
|
BanFromCommunityResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
BanPerson,
|
|
|
|
BanPersonResponse,
|
|
|
|
BlockCommunity,
|
|
|
|
BlockPerson,
|
|
|
|
CommentId,
|
|
|
|
CommentReplyResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
|
|
|
CommunityResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
CreateComment,
|
|
|
|
CreateCommentLike,
|
|
|
|
CreateCommentReport,
|
|
|
|
CreatePostLike,
|
|
|
|
CreatePostReport,
|
|
|
|
DeleteComment,
|
|
|
|
DeleteCommunity,
|
|
|
|
DeletePost,
|
|
|
|
DistinguishComment,
|
|
|
|
EditComment,
|
|
|
|
EditCommunity,
|
|
|
|
EditPost,
|
|
|
|
FeaturePost,
|
|
|
|
FollowCommunity,
|
2020-12-24 01:58:27 +00:00
|
|
|
GetComments,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetCommentsResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetCommunity,
|
|
|
|
GetCommunityResponse,
|
|
|
|
GetPosts,
|
|
|
|
GetPostsResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
GetSiteResponse,
|
|
|
|
LockPost,
|
|
|
|
MarkCommentReplyAsRead,
|
|
|
|
MarkPersonMentionAsRead,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
PurgeComment,
|
|
|
|
PurgeCommunity,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgeItemResponse,
|
2023-06-14 12:20:40 +00:00
|
|
|
PurgePerson,
|
|
|
|
PurgePost,
|
|
|
|
RemoveComment,
|
|
|
|
RemoveCommunity,
|
|
|
|
RemovePost,
|
|
|
|
SaveComment,
|
|
|
|
SavePost,
|
2021-07-17 20:42:55 +00:00
|
|
|
SortType,
|
2023-06-14 12:20:40 +00:00
|
|
|
TransferCommunity,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2022-07-30 13:28:08 +00:00
|
|
|
import {
|
|
|
|
CommentViewType,
|
|
|
|
DataType,
|
|
|
|
InitialFetchRequest,
|
|
|
|
} from "../../interfaces";
|
2023-06-14 12:20:40 +00:00
|
|
|
import { UserService } from "../../services";
|
|
|
|
import { FirstLoadService } from "../../services/FirstLoadService";
|
|
|
|
import { HttpService, RequestState } from "../../services/HttpService";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2023-06-17 12:47:43 +00:00
|
|
|
RouteDataResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
|
|
|
communityRSSUrl,
|
2023-06-14 12:20:40 +00:00
|
|
|
editComment,
|
|
|
|
editPost,
|
|
|
|
editWith,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
|
|
|
enableNsfw,
|
2021-07-17 20:42:55 +00:00
|
|
|
fetchLimit,
|
2023-06-14 12:20:40 +00:00
|
|
|
getCommentParentId,
|
2023-04-15 14:47:10 +00:00
|
|
|
getDataTypeString,
|
|
|
|
getPageFromString,
|
2023-01-04 16:56:24 +00:00
|
|
|
myAuth,
|
2022-07-30 13:28:08 +00:00
|
|
|
postToCommentSortType,
|
2022-02-24 15:31:44 +00:00
|
|
|
relTags,
|
2021-07-17 20:42:55 +00:00
|
|
|
restoreScrollPosition,
|
|
|
|
saveScrollPosition,
|
2020-09-08 15:17:49 +00:00
|
|
|
setIsoData,
|
2021-07-17 20:42:55 +00:00
|
|
|
setupTippy,
|
2022-05-23 19:19:14 +00:00
|
|
|
showLocal,
|
2021-07-17 20:42:55 +00:00
|
|
|
toast,
|
2022-07-30 03:38:37 +00:00
|
|
|
updateCommunityBlock,
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock,
|
2021-07-17 20:42:55 +00:00
|
|
|
} from "../../utils";
|
2023-06-16 21:25:53 +00:00
|
|
|
import { getQueryParams } from "../../utils/helpers/get-query-params";
|
|
|
|
import { getQueryString } from "../../utils/helpers/get-query-string";
|
|
|
|
import type { QueryParams } from "../../utils/types/query-params";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
|
|
|
import { BannerIconHeader } from "../common/banner-icon-header";
|
|
|
|
import { DataTypeSelect } from "../common/data-type-select";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { SortSelect } from "../common/sort-select";
|
|
|
|
import { Sidebar } from "../community/sidebar";
|
2022-04-28 20:42:15 +00:00
|
|
|
import { SiteSidebar } from "../home/site-sidebar";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { PostListings } from "../post/post-listings";
|
|
|
|
import { CommunityLink } from "./community-link";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
type CommunityData = RouteDataResponse<{
|
2023-06-16 02:39:04 +00:00
|
|
|
communityRes: GetCommunityResponse;
|
|
|
|
postsRes: GetPostsResponse;
|
|
|
|
commentsRes: GetCommentsResponse;
|
2023-06-16 02:08:14 +00:00
|
|
|
}>;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
interface State {
|
2023-06-14 12:20:40 +00:00
|
|
|
communityRes: RequestState<GetCommunityResponse>;
|
|
|
|
postsRes: RequestState<GetPostsResponse>;
|
|
|
|
commentsRes: RequestState<GetCommentsResponse>;
|
|
|
|
siteRes: GetSiteResponse;
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: boolean;
|
2023-06-14 12:20:40 +00:00
|
|
|
finished: Map<CommentId, boolean | undefined>;
|
|
|
|
isIsomorphic: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface CommunityProps {
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
function getCommunityQueryParams() {
|
|
|
|
return getQueryParams<CommunityProps>({
|
|
|
|
dataType: getDataTypeFromQuery,
|
|
|
|
page: getPageFromString,
|
|
|
|
sort: getSortTypeFromQuery,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
function getDataTypeFromQuery(type?: string): DataType {
|
|
|
|
return type ? DataType[type] : DataType.Post;
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
|
|
|
function getSortTypeFromQuery(type?: string): SortType {
|
|
|
|
const mySortType =
|
|
|
|
UserService.Instance.myUserInfo?.local_user_view.local_user
|
|
|
|
.default_sort_type;
|
|
|
|
|
2023-05-11 18:32:32 +00:00
|
|
|
return type ? (type as SortType) : mySortType ?? "Active";
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
export class Community extends Component<
|
|
|
|
RouteComponentProps<{ name: string }>,
|
|
|
|
State
|
|
|
|
> {
|
2023-05-30 00:40:00 +00:00
|
|
|
private isoData = setIsoData<CommunityData>(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
state: State = {
|
2023-06-14 12:20:40 +00:00
|
|
|
communityRes: { state: "empty" },
|
|
|
|
postsRes: { state: "empty" },
|
|
|
|
commentsRes: { state: "empty" },
|
|
|
|
siteRes: this.isoData.site_res,
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: false,
|
2023-06-14 12:20:40 +00:00
|
|
|
finished: new Map(),
|
|
|
|
isIsomorphic: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
constructor(props: RouteComponentProps<{ name: string }>, context: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
|
|
|
this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
// All of the action binds
|
|
|
|
this.handleDeleteCommunity = this.handleDeleteCommunity.bind(this);
|
|
|
|
this.handleEditCommunity = this.handleEditCommunity.bind(this);
|
|
|
|
this.handleFollow = this.handleFollow.bind(this);
|
|
|
|
this.handleRemoveCommunity = this.handleRemoveCommunity.bind(this);
|
|
|
|
this.handleCreateComment = this.handleCreateComment.bind(this);
|
|
|
|
this.handleEditComment = this.handleEditComment.bind(this);
|
|
|
|
this.handleSaveComment = this.handleSaveComment.bind(this);
|
|
|
|
this.handleBlockCommunity = this.handleBlockCommunity.bind(this);
|
|
|
|
this.handleBlockPerson = this.handleBlockPerson.bind(this);
|
|
|
|
this.handleDeleteComment = this.handleDeleteComment.bind(this);
|
|
|
|
this.handleRemoveComment = this.handleRemoveComment.bind(this);
|
|
|
|
this.handleCommentVote = this.handleCommentVote.bind(this);
|
|
|
|
this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
|
|
|
|
this.handleAddAdmin = this.handleAddAdmin.bind(this);
|
|
|
|
this.handlePurgePerson = this.handlePurgePerson.bind(this);
|
|
|
|
this.handlePurgeComment = this.handlePurgeComment.bind(this);
|
|
|
|
this.handleCommentReport = this.handleCommentReport.bind(this);
|
|
|
|
this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
|
|
|
|
this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
|
|
|
|
this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
|
|
|
|
this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
|
|
|
|
this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
|
|
|
|
this.handleBanPerson = this.handleBanPerson.bind(this);
|
|
|
|
this.handlePostVote = this.handlePostVote.bind(this);
|
|
|
|
this.handlePostEdit = this.handlePostEdit.bind(this);
|
|
|
|
this.handlePostReport = this.handlePostReport.bind(this);
|
|
|
|
this.handleLockPost = this.handleLockPost.bind(this);
|
|
|
|
this.handleDeletePost = this.handleDeletePost.bind(this);
|
|
|
|
this.handleRemovePost = this.handleRemovePost.bind(this);
|
|
|
|
this.handleSavePost = this.handleSavePost.bind(this);
|
|
|
|
this.handlePurgePost = this.handlePurgePost.bind(this);
|
|
|
|
this.handleFeaturePost = this.handleFeaturePost.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-08 15:17:49 +00:00
|
|
|
// Only fetch the data if coming from another route
|
2023-06-14 12:20:40 +00:00
|
|
|
if (FirstLoadService.isFirstLoad) {
|
2023-06-16 02:39:04 +00:00
|
|
|
const { communityRes, commentsRes, postsRes } = this.isoData.routeData;
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2023-06-14 12:20:40 +00:00
|
|
|
isIsomorphic: true,
|
2023-06-16 02:39:04 +00:00
|
|
|
commentsRes,
|
2023-06-14 12:20:40 +00:00
|
|
|
communityRes,
|
|
|
|
postsRes,
|
2022-09-22 15:03:35 +00:00
|
|
|
};
|
2020-09-08 15:17:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async fetchCommunity() {
|
|
|
|
this.setState({ communityRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
communityRes: await HttpService.client.getCommunity({
|
|
|
|
name: this.props.match.params.name,
|
|
|
|
auth: myAuth(),
|
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
if (!this.state.isIsomorphic) {
|
|
|
|
await Promise.all([this.fetchCommunity(), this.fetchData()]);
|
|
|
|
}
|
|
|
|
|
2021-11-25 17:40:48 +00:00
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillUnmount() {
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
static async fetchInitialData({
|
2023-04-15 14:47:10 +00:00
|
|
|
client,
|
|
|
|
path,
|
|
|
|
query: { dataType: urlDataType, page: urlPage, sort: urlSort },
|
|
|
|
auth,
|
2023-06-14 12:20:40 +00:00
|
|
|
}: InitialFetchRequest<QueryParams<CommunityProps>>): Promise<
|
2023-06-16 02:08:14 +00:00
|
|
|
Promise<CommunityData>
|
|
|
|
> {
|
2023-04-15 14:47:10 +00:00
|
|
|
const pathSplit = path.split("/");
|
|
|
|
|
|
|
|
const communityName = pathSplit[2];
|
|
|
|
const communityForm: GetCommunity = {
|
2023-01-04 16:56:24 +00:00
|
|
|
name: communityName,
|
2023-04-15 14:47:10 +00:00
|
|
|
auth,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
2020-09-08 15:17:49 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const dataType = getDataTypeFromQuery(urlDataType);
|
2020-09-08 15:17:49 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const sort = getSortTypeFromQuery(urlSort);
|
2023-01-04 16:56:24 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
const page = getPageFromString(urlPage);
|
2020-09-08 15:17:49 +00:00
|
|
|
|
2023-06-16 02:39:04 +00:00
|
|
|
let postsResponse: RequestState<GetPostsResponse> = { state: "empty" };
|
|
|
|
let commentsResponse: RequestState<GetCommentsResponse> = {
|
|
|
|
state: "empty",
|
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
if (dataType === DataType.Post) {
|
|
|
|
const getPostsForm: GetPosts = {
|
2023-01-04 16:56:24 +00:00
|
|
|
community_name: communityName,
|
2020-09-08 15:17:49 +00:00
|
|
|
page,
|
2023-01-04 16:56:24 +00:00
|
|
|
limit: fetchLimit,
|
2020-09-08 15:17:49 +00:00
|
|
|
sort,
|
2023-05-11 18:32:32 +00:00
|
|
|
type_: "All",
|
2023-01-04 16:56:24 +00:00
|
|
|
saved_only: false,
|
2023-04-15 14:47:10 +00:00
|
|
|
auth,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
postsResponse = await client.getPosts(getPostsForm);
|
2020-09-08 15:17:49 +00:00
|
|
|
} else {
|
2023-04-15 14:47:10 +00:00
|
|
|
const getCommentsForm: GetComments = {
|
2023-01-04 16:56:24 +00:00
|
|
|
community_name: communityName,
|
2020-09-08 15:17:49 +00:00
|
|
|
page,
|
2023-01-04 16:56:24 +00:00
|
|
|
limit: fetchLimit,
|
|
|
|
sort: postToCommentSortType(sort),
|
2023-05-11 18:32:32 +00:00
|
|
|
type_: "All",
|
2023-01-04 16:56:24 +00:00
|
|
|
saved_only: false,
|
2023-04-15 14:47:10 +00:00
|
|
|
auth,
|
2023-01-04 16:56:24 +00:00
|
|
|
};
|
2023-05-30 00:40:00 +00:00
|
|
|
|
2023-06-16 02:08:14 +00:00
|
|
|
commentsResponse = await client.getComments(getCommentsForm);
|
2020-09-08 15:17:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-30 00:40:00 +00:00
|
|
|
return {
|
2023-06-16 02:39:04 +00:00
|
|
|
communityRes: await client.getCommunity(communityForm),
|
|
|
|
commentsRes: commentsResponse,
|
|
|
|
postsRes: postsResponse,
|
2023-05-30 00:40:00 +00:00
|
|
|
};
|
2020-09-08 15:17:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
get documentTitle(): string {
|
2023-04-15 14:47:10 +00:00
|
|
|
const cRes = this.state.communityRes;
|
2023-06-14 12:20:40 +00:00
|
|
|
return cRes.state == "success"
|
|
|
|
? `${cRes.data.community_view.community.title} - ${this.isoData.site_res.site_view.site.name}`
|
2023-01-04 16:56:24 +00:00
|
|
|
: "";
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
renderCommunity() {
|
|
|
|
switch (this.state.communityRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
2020-09-06 16:15:25 +00:00
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
2023-06-14 12:20:40 +00:00
|
|
|
);
|
|
|
|
case "success": {
|
|
|
|
const res = this.state.communityRes.data;
|
|
|
|
const { page } = getCommunityQueryParams();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
description={res.community_view.community.description}
|
|
|
|
image={res.community_view.community.icon}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-md-8">
|
|
|
|
{this.communityInfo(res)}
|
|
|
|
<div className="d-block d-md-none">
|
|
|
|
<button
|
|
|
|
className="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowSidebarMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("sidebar")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSidebarMobile
|
|
|
|
? `minus-square`
|
|
|
|
: `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
{this.state.showSidebarMobile && this.sidebar(res)}
|
2023-01-04 16:56:24 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
{this.selects(res)}
|
|
|
|
{this.listings(res)}
|
|
|
|
<Paginator page={page} onChange={this.handlePageChange} />
|
2023-01-04 16:56:24 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
<div className="d-none d-md-block col-md-4">
|
|
|
|
{this.sidebar(res)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
render() {
|
|
|
|
return <div className="container-lg">{this.renderCommunity()}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
sidebar(res: GetCommunityResponse) {
|
2023-04-15 14:47:10 +00:00
|
|
|
const { site_res } = this.isoData;
|
|
|
|
// For some reason, this returns an empty vec if it matches the site langs
|
|
|
|
const communityLangs =
|
2023-06-14 12:20:40 +00:00
|
|
|
res.discussion_languages.length === 0
|
2023-04-15 14:47:10 +00:00
|
|
|
? site_res.all_languages.map(({ id }) => id)
|
2023-06-14 12:20:40 +00:00
|
|
|
: res.discussion_languages;
|
2023-04-15 14:47:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Sidebar
|
2023-06-14 12:20:40 +00:00
|
|
|
community_view={res.community_view}
|
|
|
|
moderators={res.moderators}
|
2023-04-15 14:47:10 +00:00
|
|
|
admins={site_res.admins}
|
|
|
|
enableNsfw={enableNsfw(site_res)}
|
|
|
|
editable
|
|
|
|
allLanguages={site_res.all_languages}
|
|
|
|
siteLanguages={site_res.discussion_languages}
|
|
|
|
communityLanguages={communityLangs}
|
2023-06-14 12:20:40 +00:00
|
|
|
onDeleteCommunity={this.handleDeleteCommunity}
|
|
|
|
onRemoveCommunity={this.handleRemoveCommunity}
|
|
|
|
onLeaveModTeam={this.handleAddModToCommunity}
|
|
|
|
onFollowCommunity={this.handleFollow}
|
|
|
|
onBlockCommunity={this.handleBlockCommunity}
|
|
|
|
onPurgeCommunity={this.handlePurgeCommunity}
|
|
|
|
onEditCommunity={this.handleEditCommunity}
|
2023-04-15 14:47:10 +00:00
|
|
|
/>
|
2023-06-14 12:20:40 +00:00
|
|
|
{!res.community_view.community.local && res.site && (
|
|
|
|
<SiteSidebar site={res.site} showLocal={showLocal(this.isoData)} />
|
2023-04-15 14:47:10 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
listings(communityRes: GetCommunityResponse) {
|
2023-04-15 14:47:10 +00:00
|
|
|
const { dataType } = getCommunityQueryParams();
|
|
|
|
const { site_res } = this.isoData;
|
2023-06-14 12:20:40 +00:00
|
|
|
|
|
|
|
if (dataType === DataType.Post) {
|
|
|
|
switch (this.state.postsRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success":
|
|
|
|
return (
|
|
|
|
<PostListings
|
|
|
|
posts={this.state.postsRes.data.posts}
|
|
|
|
removeDuplicates
|
|
|
|
enableDownvotes={enableDownvotes(site_res)}
|
|
|
|
enableNsfw={enableNsfw(site_res)}
|
|
|
|
allLanguages={site_res.all_languages}
|
|
|
|
siteLanguages={site_res.discussion_languages}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onPostEdit={this.handlePostEdit}
|
|
|
|
onPostVote={this.handlePostVote}
|
|
|
|
onPostReport={this.handlePostReport}
|
|
|
|
onLockPost={this.handleLockPost}
|
|
|
|
onDeletePost={this.handleDeletePost}
|
|
|
|
onRemovePost={this.handleRemovePost}
|
|
|
|
onSavePost={this.handleSavePost}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onPurgePost={this.handlePurgePost}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onFeaturePost={this.handleFeaturePost}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
} else {
|
2023-06-14 12:20:40 +00:00
|
|
|
switch (this.state.commentsRes.state) {
|
|
|
|
case "loading":
|
|
|
|
return (
|
|
|
|
<h5>
|
|
|
|
<Spinner large />
|
|
|
|
</h5>
|
|
|
|
);
|
|
|
|
case "success":
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.commentsRes.data.comments)}
|
|
|
|
viewType={CommentViewType.Flat}
|
|
|
|
finished={this.state.finished}
|
|
|
|
noIndent
|
|
|
|
showContext
|
|
|
|
enableDownvotes={enableDownvotes(site_res)}
|
|
|
|
moderators={communityRes.moderators}
|
|
|
|
admins={site_res.admins}
|
|
|
|
allLanguages={site_res.all_languages}
|
|
|
|
siteLanguages={site_res.discussion_languages}
|
|
|
|
onSaveComment={this.handleSaveComment}
|
|
|
|
onBlockPerson={this.handleBlockPerson}
|
|
|
|
onDeleteComment={this.handleDeleteComment}
|
|
|
|
onRemoveComment={this.handleRemoveComment}
|
|
|
|
onCommentVote={this.handleCommentVote}
|
|
|
|
onCommentReport={this.handleCommentReport}
|
|
|
|
onDistinguishComment={this.handleDistinguishComment}
|
|
|
|
onAddModToCommunity={this.handleAddModToCommunity}
|
|
|
|
onAddAdmin={this.handleAddAdmin}
|
|
|
|
onTransferCommunity={this.handleTransferCommunity}
|
|
|
|
onPurgeComment={this.handlePurgeComment}
|
|
|
|
onPurgePerson={this.handlePurgePerson}
|
|
|
|
onCommentReplyRead={this.handleCommentReplyRead}
|
|
|
|
onPersonMentionRead={this.handlePersonMentionRead}
|
|
|
|
onBanPersonFromCommunity={this.handleBanFromCommunity}
|
|
|
|
onBanPerson={this.handleBanPerson}
|
|
|
|
onCreateComment={this.handleCreateComment}
|
|
|
|
onEditComment={this.handleEditComment}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
communityInfo(res: GetCommunityResponse) {
|
|
|
|
const community = res.community_view.community;
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
return (
|
|
|
|
community && (
|
|
|
|
<div className="mb-2">
|
|
|
|
<BannerIconHeader banner={community.banner} icon={community.icon} />
|
|
|
|
<h5 className="mb-0 overflow-wrap-anywhere">{community.title}</h5>
|
|
|
|
<CommunityLink
|
|
|
|
community={community}
|
|
|
|
realLink
|
|
|
|
useApubName
|
|
|
|
muted
|
|
|
|
hideAvatar
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
selects(res: GetCommunityResponse) {
|
2023-01-04 16:56:24 +00:00
|
|
|
// let communityRss = this.state.communityRes.map(r =>
|
|
|
|
// communityRSSUrl(r.community_view.community.actor_id, this.state.sort)
|
|
|
|
// );
|
2023-04-15 14:47:10 +00:00
|
|
|
const { dataType, sort } = getCommunityQueryParams();
|
|
|
|
const communityRss = res
|
|
|
|
? communityRSSUrl(res.community_view.community.actor_id, sort)
|
2023-01-04 16:56:24 +00:00
|
|
|
: undefined;
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="mb-3">
|
|
|
|
<span className="mr-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<DataTypeSelect
|
2023-04-15 14:47:10 +00:00
|
|
|
type_={dataType}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={this.handleDataTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-2">
|
2023-04-15 14:47:10 +00:00
|
|
|
<SortSelect sort={sort} onChange={this.handleSortChange} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</span>
|
2023-01-04 16:56:24 +00:00
|
|
|
{communityRss && (
|
|
|
|
<>
|
|
|
|
<a href={communityRss} title="RSS" rel={relTags}>
|
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link
|
|
|
|
rel="alternate"
|
|
|
|
type="application/atom+xml"
|
|
|
|
href={communityRss}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-15 19:53:29 +00:00
|
|
|
handlePageChange(page: number) {
|
2021-07-16 19:40:56 +00:00
|
|
|
this.updateUrl({ page });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
handleSortChange(sort: SortType) {
|
2023-05-15 19:53:29 +00:00
|
|
|
this.updateUrl({ sort, page: 1 });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2023-04-15 14:47:10 +00:00
|
|
|
handleDataTypeChange(dataType: DataType) {
|
2023-05-15 19:53:29 +00:00
|
|
|
this.updateUrl({ dataType, page: 1 });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
handleShowSidebarMobile(i: Community) {
|
2023-04-15 14:47:10 +00:00
|
|
|
i.setState(({ showSidebarMobile }) => ({
|
|
|
|
showSidebarMobile: !showSidebarMobile,
|
|
|
|
}));
|
2021-07-18 03:56:33 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async updateUrl({ dataType, page, sort }: Partial<CommunityProps>) {
|
2023-04-15 14:47:10 +00:00
|
|
|
const {
|
|
|
|
dataType: urlDataType,
|
|
|
|
page: urlPage,
|
|
|
|
sort: urlSort,
|
|
|
|
} = getCommunityQueryParams();
|
|
|
|
|
|
|
|
const queryParams: QueryParams<CommunityProps> = {
|
|
|
|
dataType: getDataTypeString(dataType ?? urlDataType),
|
|
|
|
page: (page ?? urlPage).toString(),
|
|
|
|
sort: sort ?? urlSort,
|
|
|
|
};
|
2021-02-08 20:14:34 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
this.props.history.push(
|
2023-04-15 14:47:10 +00:00
|
|
|
`/c/${this.props.match.params.name}${getQueryString(queryParams)}`
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
await this.fetchData();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async fetchData() {
|
2023-04-15 14:47:10 +00:00
|
|
|
const { dataType, page, sort } = getCommunityQueryParams();
|
|
|
|
const { name } = this.props.match.params;
|
|
|
|
|
|
|
|
if (dataType === DataType.Post) {
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ postsRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
postsRes: await HttpService.client.getPosts({
|
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort,
|
|
|
|
type_: "All",
|
|
|
|
community_name: name,
|
|
|
|
saved_only: false,
|
|
|
|
auth: myAuth(),
|
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2023-06-14 12:20:40 +00:00
|
|
|
this.setState({ commentsRes: { state: "loading" } });
|
|
|
|
this.setState({
|
|
|
|
commentsRes: await HttpService.client.getComments({
|
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort: postToCommentSortType(sort),
|
|
|
|
type_: "All",
|
|
|
|
community_name: name,
|
|
|
|
saved_only: false,
|
|
|
|
auth: myAuth(),
|
|
|
|
}),
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
restoreScrollPosition(this.context);
|
|
|
|
setupTippy();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleDeleteCommunity(form: DeleteCommunity) {
|
|
|
|
const deleteCommunityRes = await HttpService.client.deleteCommunity(form);
|
|
|
|
this.updateCommunity(deleteCommunityRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleAddModToCommunity(form: AddModToCommunity) {
|
|
|
|
const addModRes = await HttpService.client.addModToCommunity(form);
|
|
|
|
this.updateModerators(addModRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleFollow(form: FollowCommunity) {
|
|
|
|
const followCommunityRes = await HttpService.client.followCommunity(form);
|
|
|
|
this.updateCommunity(followCommunityRes);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
// Update myUserInfo
|
|
|
|
if (followCommunityRes.state == "success") {
|
|
|
|
const communityId = followCommunityRes.data.community_view.community.id;
|
|
|
|
const mui = UserService.Instance.myUserInfo;
|
|
|
|
if (mui) {
|
|
|
|
mui.follows = mui.follows.filter(i => i.community.id != communityId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePurgeCommunity(form: PurgeCommunity) {
|
|
|
|
const purgeCommunityRes = await HttpService.client.purgeCommunity(form);
|
|
|
|
this.purgeItem(purgeCommunityRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePurgePerson(form: PurgePerson) {
|
|
|
|
const purgePersonRes = await HttpService.client.purgePerson(form);
|
|
|
|
this.purgeItem(purgePersonRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePurgeComment(form: PurgeComment) {
|
|
|
|
const purgeCommentRes = await HttpService.client.purgeComment(form);
|
|
|
|
this.purgeItem(purgeCommentRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePurgePost(form: PurgePost) {
|
|
|
|
const purgeRes = await HttpService.client.purgePost(form);
|
|
|
|
this.purgeItem(purgeRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleBlockCommunity(form: BlockCommunity) {
|
|
|
|
const blockCommunityRes = await HttpService.client.blockCommunity(form);
|
|
|
|
if (blockCommunityRes.state == "success") {
|
|
|
|
updateCommunityBlock(blockCommunityRes.data);
|
2023-06-16 17:01:09 +00:00
|
|
|
this.setState(s => {
|
|
|
|
if (s.communityRes.state == "success") {
|
|
|
|
s.communityRes.data.community_view.blocked =
|
|
|
|
blockCommunityRes.data.blocked;
|
|
|
|
}
|
|
|
|
});
|
2023-06-14 12:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleBlockPerson(form: BlockPerson) {
|
|
|
|
const blockPersonRes = await HttpService.client.blockPerson(form);
|
|
|
|
if (blockPersonRes.state == "success") {
|
|
|
|
updatePersonBlock(blockPersonRes.data);
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleRemoveCommunity(form: RemoveCommunity) {
|
|
|
|
const removeCommunityRes = await HttpService.client.removeCommunity(form);
|
|
|
|
this.updateCommunity(removeCommunityRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleEditCommunity(form: EditCommunity) {
|
|
|
|
const res = await HttpService.client.editCommunity(form);
|
|
|
|
this.updateCommunity(res);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
return res;
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCreateComment(form: CreateComment) {
|
|
|
|
const createCommentRes = await HttpService.client.createComment(form);
|
|
|
|
this.createAndUpdateComments(createCommentRes);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
return createCommentRes;
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleEditComment(form: EditComment) {
|
|
|
|
const editCommentRes = await HttpService.client.editComment(form);
|
|
|
|
this.findAndUpdateComment(editCommentRes);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
return editCommentRes;
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleDeleteComment(form: DeleteComment) {
|
|
|
|
const deleteCommentRes = await HttpService.client.deleteComment(form);
|
|
|
|
this.findAndUpdateComment(deleteCommentRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleDeletePost(form: DeletePost) {
|
|
|
|
const deleteRes = await HttpService.client.deletePost(form);
|
|
|
|
this.findAndUpdatePost(deleteRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleRemovePost(form: RemovePost) {
|
|
|
|
const removeRes = await HttpService.client.removePost(form);
|
|
|
|
this.findAndUpdatePost(removeRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleRemoveComment(form: RemoveComment) {
|
|
|
|
const removeCommentRes = await HttpService.client.removeComment(form);
|
|
|
|
this.findAndUpdateComment(removeCommentRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleSaveComment(form: SaveComment) {
|
|
|
|
const saveCommentRes = await HttpService.client.saveComment(form);
|
|
|
|
this.findAndUpdateComment(saveCommentRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleSavePost(form: SavePost) {
|
|
|
|
const saveRes = await HttpService.client.savePost(form);
|
|
|
|
this.findAndUpdatePost(saveRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleFeaturePost(form: FeaturePost) {
|
|
|
|
const featureRes = await HttpService.client.featurePost(form);
|
|
|
|
this.findAndUpdatePost(featureRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCommentVote(form: CreateCommentLike) {
|
|
|
|
const voteRes = await HttpService.client.likeComment(form);
|
|
|
|
this.findAndUpdateComment(voteRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePostEdit(form: EditPost) {
|
|
|
|
const res = await HttpService.client.editPost(form);
|
|
|
|
this.findAndUpdatePost(res);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePostVote(form: CreatePostLike) {
|
|
|
|
const voteRes = await HttpService.client.likePost(form);
|
|
|
|
this.findAndUpdatePost(voteRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCommentReport(form: CreateCommentReport) {
|
|
|
|
const reportRes = await HttpService.client.createCommentReport(form);
|
|
|
|
if (reportRes.state == "success") {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePostReport(form: CreatePostReport) {
|
|
|
|
const reportRes = await HttpService.client.createPostReport(form);
|
|
|
|
if (reportRes.state == "success") {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleLockPost(form: LockPost) {
|
|
|
|
const lockRes = await HttpService.client.lockPost(form);
|
|
|
|
this.findAndUpdatePost(lockRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleDistinguishComment(form: DistinguishComment) {
|
|
|
|
const distinguishRes = await HttpService.client.distinguishComment(form);
|
|
|
|
this.findAndUpdateComment(distinguishRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleAddAdmin(form: AddAdmin) {
|
|
|
|
const addAdminRes = await HttpService.client.addAdmin(form);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
if (addAdminRes.state == "success") {
|
|
|
|
this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleTransferCommunity(form: TransferCommunity) {
|
|
|
|
const transferCommunityRes = await HttpService.client.transferCommunity(
|
|
|
|
form
|
|
|
|
);
|
|
|
|
toast(i18n.t("transfer_community"));
|
|
|
|
this.updateCommunityFull(transferCommunityRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
|
|
|
|
const readRes = await HttpService.client.markCommentReplyAsRead(form);
|
|
|
|
this.findAndUpdateCommentReply(readRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
|
|
|
|
// TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
|
|
|
|
await HttpService.client.markPersonMentionAsRead(form);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleBanFromCommunity(form: BanFromCommunity) {
|
|
|
|
const banRes = await HttpService.client.banFromCommunity(form);
|
|
|
|
this.updateBanFromCommunity(banRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleBanPerson(form: BanPerson) {
|
|
|
|
const banRes = await HttpService.client.banPerson(form);
|
|
|
|
this.updateBan(banRes);
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
|
|
|
|
// Maybe not necessary
|
|
|
|
if (banRes.state == "success") {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.postsRes.state == "success") {
|
|
|
|
s.postsRes.data.posts
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(
|
|
|
|
c => (c.creator_banned_from_community = banRes.data.banned)
|
|
|
|
);
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
if (s.commentsRes.state == "success") {
|
|
|
|
s.commentsRes.data.comments
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(
|
|
|
|
c => (c.creator_banned_from_community = banRes.data.banned)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateBan(banRes: RequestState<BanPersonResponse>) {
|
|
|
|
// Maybe not necessary
|
|
|
|
if (banRes.state == "success") {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.postsRes.state == "success") {
|
|
|
|
s.postsRes.data.posts
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator.banned = banRes.data.banned));
|
|
|
|
}
|
|
|
|
if (s.commentsRes.state == "success") {
|
|
|
|
s.commentsRes.data.comments
|
|
|
|
.filter(c => c.creator.id == banRes.data.person_view.person.id)
|
|
|
|
.forEach(c => (c.creator.banned = banRes.data.banned));
|
2023-04-15 14:47:10 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateCommunity(res: RequestState<CommunityResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.communityRes.state == "success" && res.state == "success") {
|
|
|
|
s.communityRes.data.community_view = res.data.community_view;
|
|
|
|
s.communityRes.data.discussion_languages =
|
|
|
|
res.data.discussion_languages;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateCommunityFull(res: RequestState<GetCommunityResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.communityRes.state == "success" && res.state == "success") {
|
|
|
|
s.communityRes.data.community_view = res.data.community_view;
|
|
|
|
s.communityRes.data.moderators = res.data.moderators;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
|
|
|
|
if (purgeRes.state == "success") {
|
|
|
|
toast(i18n.t("purge_success"));
|
|
|
|
this.context.router.history.push(`/`);
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
findAndUpdateComment(res: RequestState<CommentResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.commentsRes.state == "success" && res.state == "success") {
|
|
|
|
s.commentsRes.data.comments = editComment(
|
|
|
|
res.data.comment_view,
|
|
|
|
s.commentsRes.data.comments
|
|
|
|
);
|
|
|
|
s.finished.set(res.data.comment_view.comment.id, true);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
createAndUpdateComments(res: RequestState<CommentResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.commentsRes.state == "success" && res.state == "success") {
|
|
|
|
s.commentsRes.data.comments.unshift(res.data.comment_view);
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
// Set finished for the parent
|
|
|
|
s.finished.set(
|
|
|
|
getCommentParentId(res.data.comment_view.comment) ?? 0,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.commentsRes.state == "success" && res.state == "success") {
|
|
|
|
s.commentsRes.data.comments = editWith(
|
|
|
|
res.data.comment_reply_view,
|
|
|
|
s.commentsRes.data.comments
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
findAndUpdatePost(res: RequestState<PostResponse>) {
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.postsRes.state == "success" && res.state == "success") {
|
|
|
|
s.postsRes.data.posts = editPost(
|
|
|
|
res.data.post_view,
|
|
|
|
s.postsRes.data.posts
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
}
|
2023-04-15 14:47:10 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
updateModerators(res: RequestState<AddModToCommunityResponse>) {
|
|
|
|
// Update the moderators
|
|
|
|
this.setState(s => {
|
|
|
|
if (s.communityRes.state == "success" && res.state == "success") {
|
|
|
|
s.communityRes.data.moderators = res.data.moderators;
|
2023-01-04 16:56:24 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
return s;
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|