2022-06-21 21:42:29 +00:00
|
|
|
import { None, Option, Some } from "@sniptt/monads";
|
2021-07-18 03:56:33 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
|
|
|
AddModToCommunityResponse,
|
|
|
|
BanFromCommunityResponse,
|
2022-07-30 03:38:37 +00:00
|
|
|
BlockCommunityResponse,
|
2021-08-20 02:56:18 +00:00
|
|
|
BlockPersonResponse,
|
2021-09-28 10:38:59 +00:00
|
|
|
CommentReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommentResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommentView,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityResponse,
|
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,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetSiteResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
ListingType,
|
2021-09-28 10:38:59 +00:00
|
|
|
PostReportResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostResponse,
|
|
|
|
PostView,
|
2022-06-23 19:44:05 +00:00
|
|
|
PurgeItemResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
SortType,
|
2022-06-21 21:42:29 +00:00
|
|
|
toOption,
|
2021-07-17 20:42:55 +00:00
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
2022-07-30 13:28:08 +00:00
|
|
|
import {
|
|
|
|
CommentViewType,
|
|
|
|
DataType,
|
|
|
|
InitialFetchRequest,
|
|
|
|
} from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
auth,
|
2021-07-17 20:42:55 +00:00
|
|
|
commentsToFlatNodes,
|
|
|
|
communityRSSUrl,
|
2020-09-06 16:15:25 +00:00
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeFindRes,
|
2021-07-17 20:42:55 +00:00
|
|
|
editCommentRes,
|
2020-09-06 16:15:25 +00:00
|
|
|
editPostFindRes,
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes,
|
|
|
|
enableNsfw,
|
2021-07-17 20:42:55 +00:00
|
|
|
fetchLimit,
|
|
|
|
getDataTypeFromProps,
|
|
|
|
getPageFromProps,
|
|
|
|
getSortTypeFromProps,
|
2020-09-06 16:15:25 +00:00
|
|
|
notifyPost,
|
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,
|
|
|
|
saveCommentRes,
|
|
|
|
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
|
|
|
wsClient,
|
2020-09-08 15:17:49 +00:00
|
|
|
wsSubscribe,
|
2021-07-17 20:42:55 +00:00
|
|
|
} from "../../utils";
|
|
|
|
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
|
|
|
|
|
|
|
interface State {
|
2022-06-21 21:42:29 +00:00
|
|
|
communityRes: Option<GetCommunityResponse>;
|
2020-09-08 15:17:49 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2020-09-06 16:15:25 +00:00
|
|
|
communityName: string;
|
2020-12-02 15:13:01 +00:00
|
|
|
communityLoading: boolean;
|
|
|
|
postsLoading: boolean;
|
|
|
|
commentsLoading: boolean;
|
2020-12-24 01:58:27 +00:00
|
|
|
posts: PostView[];
|
|
|
|
comments: CommentView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface CommunityProps {
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
dataType?: string;
|
|
|
|
sort?: SortType;
|
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Community extends Component<any, State> {
|
2022-06-21 21:42:29 +00:00
|
|
|
private isoData = setIsoData(
|
|
|
|
this.context,
|
|
|
|
GetCommunityResponse,
|
|
|
|
GetPostsResponse,
|
|
|
|
GetCommentsResponse
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
private emptyState: State = {
|
2022-06-21 21:42:29 +00:00
|
|
|
communityRes: None,
|
2020-09-06 16:15:25 +00:00
|
|
|
communityName: this.props.match.params.name,
|
2020-12-02 15:13:01 +00:00
|
|
|
communityLoading: true,
|
|
|
|
postsLoading: true,
|
|
|
|
commentsLoading: true,
|
2020-09-06 16:15:25 +00:00
|
|
|
posts: [],
|
|
|
|
comments: [],
|
|
|
|
dataType: getDataTypeFromProps(this.props),
|
|
|
|
sort: getSortTypeFromProps(this.props),
|
|
|
|
page: getPageFromProps(this.props),
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-07-18 03:56:33 +00:00
|
|
|
showSidebarMobile: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
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
|
|
|
|
2020-09-08 15:17:49 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
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
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
communityRes: Some(this.isoData.routeData[0] as GetCommunityResponse),
|
|
|
|
};
|
2022-06-21 21:42:29 +00:00
|
|
|
let postsRes = Some(this.isoData.routeData[1] as GetPostsResponse);
|
|
|
|
let commentsRes = Some(this.isoData.routeData[2] as GetCommentsResponse);
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
if (postsRes.isSome()) {
|
|
|
|
this.state = { ...this.state, posts: postsRes.unwrap().posts };
|
|
|
|
}
|
2022-06-21 21:42:29 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
if (commentsRes.isSome()) {
|
|
|
|
this.state = { ...this.state, comments: commentsRes.unwrap().comments };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
communityLoading: false,
|
|
|
|
postsLoading: false,
|
|
|
|
commentsLoading: false,
|
|
|
|
};
|
2020-09-08 15:17:49 +00:00
|
|
|
} else {
|
|
|
|
this.fetchCommunity();
|
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchCommunity() {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new GetCommunity({
|
|
|
|
name: Some(this.state.communityName),
|
|
|
|
id: None,
|
|
|
|
auth: auth(false).ok(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getCommunity(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 17:40:48 +00:00
|
|
|
componentDidMount() {
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillUnmount() {
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
|
|
|
this.subscription.unsubscribe();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getDerivedStateFromProps(props: any): CommunityProps {
|
|
|
|
return {
|
|
|
|
dataType: getDataTypeFromProps(props),
|
|
|
|
sort: getSortTypeFromProps(props),
|
|
|
|
page: getPageFromProps(props),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-22 02:39:04 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2020-09-08 15:17:49 +00:00
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
2022-04-08 13:29:02 +00:00
|
|
|
let communityName = pathSplit[2];
|
2022-06-21 21:42:29 +00:00
|
|
|
let communityForm = new GetCommunity({
|
|
|
|
name: Some(communityName),
|
|
|
|
id: None,
|
|
|
|
auth: req.auth,
|
|
|
|
});
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getCommunity(communityForm));
|
2020-09-08 15:17:49 +00:00
|
|
|
|
|
|
|
let dataType: DataType = pathSplit[4]
|
|
|
|
? DataType[pathSplit[4]]
|
|
|
|
: DataType.Post;
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let sort: Option<SortType> = toOption(
|
|
|
|
pathSplit[6]
|
|
|
|
? SortType[pathSplit[6]]
|
|
|
|
: UserService.Instance.myUserInfo.match({
|
|
|
|
some: mui =>
|
|
|
|
Object.values(SortType)[
|
|
|
|
mui.local_user_view.local_user.default_sort_type
|
|
|
|
],
|
|
|
|
none: SortType.Active,
|
|
|
|
})
|
|
|
|
);
|
2020-09-08 15:17:49 +00:00
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
let page = toOption(pathSplit[8] ? Number(pathSplit[8]) : 1);
|
2020-09-08 15:17:49 +00:00
|
|
|
|
|
|
|
if (dataType == DataType.Post) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getPostsForm = new GetPosts({
|
|
|
|
community_name: Some(communityName),
|
|
|
|
community_id: None,
|
2020-09-08 15:17:49 +00:00
|
|
|
page,
|
2022-06-21 21:42:29 +00:00
|
|
|
limit: Some(fetchLimit),
|
2020-09-08 15:17:49 +00:00
|
|
|
sort,
|
2022-07-30 03:37:20 +00:00
|
|
|
type_: Some(ListingType.All),
|
2022-06-21 21:42:29 +00:00
|
|
|
saved_only: Some(false),
|
|
|
|
auth: req.auth,
|
|
|
|
});
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getPosts(getPostsForm));
|
2022-06-21 21:42:29 +00:00
|
|
|
promises.push(Promise.resolve());
|
2020-09-08 15:17:49 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
let getCommentsForm = new GetComments({
|
|
|
|
community_name: Some(communityName),
|
|
|
|
community_id: None,
|
2020-09-08 15:17:49 +00:00
|
|
|
page,
|
2022-06-21 21:42:29 +00:00
|
|
|
limit: Some(fetchLimit),
|
2022-07-30 13:28:08 +00:00
|
|
|
max_depth: None,
|
|
|
|
sort: sort.map(postToCommentSortType),
|
2022-07-30 03:37:20 +00:00
|
|
|
type_: Some(ListingType.All),
|
2022-06-21 21:42:29 +00:00
|
|
|
saved_only: Some(false),
|
2022-07-30 13:28:08 +00:00
|
|
|
post_id: None,
|
|
|
|
parent_id: None,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: req.auth,
|
|
|
|
});
|
|
|
|
promises.push(Promise.resolve());
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getComments(getCommentsForm));
|
2020-09-08 15:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentDidUpdate(_: any, lastState: State) {
|
|
|
|
if (
|
|
|
|
lastState.dataType !== this.state.dataType ||
|
|
|
|
lastState.sort !== this.state.sort ||
|
|
|
|
lastState.page !== this.state.page
|
|
|
|
) {
|
2020-12-02 15:13:01 +00:00
|
|
|
this.setState({ postsLoading: true, commentsLoading: true });
|
2020-09-06 16:15:25 +00:00
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.communityRes.match({
|
|
|
|
some: res =>
|
|
|
|
this.state.siteRes.site_view.match({
|
|
|
|
some: siteView =>
|
|
|
|
`${res.community_view.community.title} - ${siteView.site.name}`,
|
|
|
|
none: "",
|
|
|
|
}),
|
|
|
|
none: "",
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="container">
|
2020-12-02 15:13:01 +00:00
|
|
|
{this.state.communityLoading ? (
|
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>
|
|
|
|
) : (
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.communityRes.match({
|
|
|
|
some: res => (
|
|
|
|
<>
|
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
description={res.community_view.community.description}
|
|
|
|
image={res.community_view.community.icon}
|
|
|
|
/>
|
2021-07-18 03:56:33 +00:00
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-md-8">
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.communityInfo()}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-block d-md-none">
|
2022-06-21 21:42:29 +00:00
|
|
|
<button
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary d-inline-block mb-2 mr-3"
|
2022-06-21 21:42:29 +00:00
|
|
|
onClick={linkEvent(this, this.handleShowSidebarMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("sidebar")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSidebarMobile
|
|
|
|
? `minus-square`
|
|
|
|
: `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
2022-05-23 19:19:14 +00:00
|
|
|
/>
|
2022-06-21 21:42:29 +00:00
|
|
|
</button>
|
|
|
|
{this.state.showSidebarMobile && (
|
|
|
|
<>
|
|
|
|
<Sidebar
|
|
|
|
community_view={res.community_view}
|
|
|
|
moderators={res.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
|
|
|
online={res.online}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
/>
|
|
|
|
{!res.community_view.community.local &&
|
|
|
|
res.site.match({
|
|
|
|
some: site => (
|
|
|
|
<SiteSidebar
|
|
|
|
site={site}
|
|
|
|
showLocal={showLocal(this.isoData)}
|
|
|
|
admins={None}
|
|
|
|
counts={None}
|
|
|
|
online={None}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
|
|
|
</>
|
2022-04-28 20:42:15 +00:00
|
|
|
)}
|
2022-06-21 21:42:29 +00:00
|
|
|
</div>
|
|
|
|
{this.selects()}
|
|
|
|
{this.listings()}
|
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="d-none d-md-block col-md-4">
|
2022-06-21 21:42:29 +00:00
|
|
|
<Sidebar
|
|
|
|
community_view={res.community_view}
|
|
|
|
moderators={res.moderators}
|
|
|
|
admins={this.state.siteRes.admins}
|
|
|
|
online={res.online}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
/>
|
|
|
|
{!res.community_view.community.local &&
|
|
|
|
res.site.match({
|
|
|
|
some: site => (
|
|
|
|
<SiteSidebar
|
|
|
|
site={site}
|
|
|
|
showLocal={showLocal(this.isoData)}
|
|
|
|
admins={None}
|
|
|
|
counts={None}
|
|
|
|
online={None}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
|
|
|
</div>
|
2021-07-18 03:56:33 +00:00
|
|
|
</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
listings() {
|
|
|
|
return this.state.dataType == DataType.Post ? (
|
2020-12-02 15:13:01 +00:00
|
|
|
this.state.postsLoading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-12-02 15:13:01 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<PostListings
|
|
|
|
posts={this.state.posts}
|
|
|
|
removeDuplicates
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
2020-12-02 15:13:01 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
) : this.state.commentsLoading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-12-02 15:13:01 +00:00
|
|
|
</h5>
|
2020-09-06 16:15:25 +00:00
|
|
|
) : (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.comments)}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={CommentViewType.Flat}
|
2020-09-06 16:15:25 +00:00
|
|
|
noIndent
|
|
|
|
showContext
|
2022-06-21 21:42:29 +00:00
|
|
|
enableDownvotes={enableDownvotes(this.state.siteRes)}
|
|
|
|
moderators={this.state.communityRes.map(r => r.moderators)}
|
|
|
|
admins={Some(this.state.siteRes.admins)}
|
|
|
|
maxCommentsShown={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
communityInfo() {
|
2022-06-21 21:42:29 +00:00
|
|
|
return this.state.communityRes
|
|
|
|
.map(r => r.community_view.community)
|
|
|
|
.match({
|
|
|
|
some: community => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="mb-2">
|
2022-06-21 21:42:29 +00:00
|
|
|
<BannerIconHeader banner={community.banner} icon={community.icon} />
|
2022-09-22 15:03:35 +00:00
|
|
|
<h5 className="mb-0 overflow-wrap-anywhere">{community.title}</h5>
|
2022-06-21 21:42:29 +00:00
|
|
|
<CommunityLink
|
|
|
|
community={community}
|
|
|
|
realLink
|
|
|
|
useApubName
|
|
|
|
muted
|
|
|
|
hideAvatar
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
2022-06-21 21:42:29 +00:00
|
|
|
let communityRss = this.state.communityRes.map(r =>
|
|
|
|
communityRSSUrl(r.community_view.community.actor_id, this.state.sort)
|
2022-01-25 03:24:32 +00:00
|
|
|
);
|
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
|
|
|
|
type_={this.state.dataType}
|
|
|
|
onChange={this.handleDataTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="mr-2">
|
2020-09-06 16:15:25 +00:00
|
|
|
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
|
|
|
|
</span>
|
2022-06-21 21:42:29 +00:00
|
|
|
{communityRss.match({
|
|
|
|
some: rss => (
|
|
|
|
<>
|
|
|
|
<a href={rss} title="RSS" rel={relTags}>
|
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
|
|
|
</a>
|
|
|
|
<link rel="alternate" type="application/atom+xml" href={rss} />
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
none: <></>,
|
|
|
|
})}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(page: number) {
|
|
|
|
this.updateUrl({ page });
|
2020-09-06 16:15:25 +00:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSortChange(val: SortType) {
|
|
|
|
this.updateUrl({ sort: val, page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDataTypeChange(val: DataType) {
|
|
|
|
this.updateUrl({ dataType: DataType[val], page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
handleShowSidebarMobile(i: Community) {
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
|
2021-07-18 03:56:33 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType];
|
|
|
|
const sortStr = paramUpdates.sort || this.state.sort;
|
|
|
|
const page = paramUpdates.page || this.state.page;
|
2021-02-08 20:14:34 +00:00
|
|
|
|
2021-07-21 15:01:32 +00:00
|
|
|
let typeView = `/c/${this.state.communityName}`;
|
2021-02-08 20:14:34 +00:00
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
this.props.history.push(
|
2021-02-08 20:14:34 +00:00
|
|
|
`${typeView}/data_type/${dataTypeStr}/sort/${sortStr}/page/${page}`
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
if (this.state.dataType == DataType.Post) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new GetPosts({
|
|
|
|
page: Some(this.state.page),
|
|
|
|
limit: Some(fetchLimit),
|
|
|
|
sort: Some(this.state.sort),
|
2022-07-30 03:37:20 +00:00
|
|
|
type_: Some(ListingType.All),
|
2022-06-21 21:42:29 +00:00
|
|
|
community_name: Some(this.state.communityName),
|
|
|
|
community_id: None,
|
|
|
|
saved_only: Some(false),
|
|
|
|
auth: auth(false).ok(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getPosts(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
let form = new GetComments({
|
|
|
|
page: Some(this.state.page),
|
|
|
|
limit: Some(fetchLimit),
|
2022-07-30 13:28:08 +00:00
|
|
|
max_depth: None,
|
|
|
|
sort: Some(postToCommentSortType(this.state.sort)),
|
2022-07-30 03:37:20 +00:00
|
|
|
type_: Some(ListingType.All),
|
2022-06-21 21:42:29 +00:00
|
|
|
community_name: Some(this.state.communityName),
|
|
|
|
community_id: None,
|
|
|
|
saved_only: Some(false),
|
2022-07-30 13:28:08 +00:00
|
|
|
post_id: None,
|
|
|
|
parent_id: None,
|
2022-06-21 21:42:29 +00:00
|
|
|
auth: auth(false).ok(),
|
|
|
|
});
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getComments(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
2021-04-07 15:54:38 +00:00
|
|
|
console.log(msg);
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2021-02-22 02:39:04 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
|
|
|
this.context.router.history.push("/");
|
2020-09-06 16:15:25 +00:00
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
2022-06-21 21:42:29 +00:00
|
|
|
this.state.communityRes.match({
|
|
|
|
some: res => {
|
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({
|
|
|
|
community_id: res.community_view.community.id,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
none: void 0,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
this.fetchData();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetCommunity) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetCommunityResponse>(msg, GetCommunityResponse);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ communityRes: Some(data), communityLoading: false });
|
2020-12-24 01:58:27 +00:00
|
|
|
// TODO why is there no auth in this form?
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({
|
|
|
|
community_id: data.community_view.community.id,
|
|
|
|
})
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditCommunity ||
|
|
|
|
op == UserOperation.DeleteCommunity ||
|
|
|
|
op == UserOperation.RemoveCommunity
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommunityResponse>(msg, CommunityResponse);
|
|
|
|
this.state.communityRes.match({
|
|
|
|
some: res => (res.community_view = data.community_view),
|
|
|
|
none: void 0,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.FollowCommunity) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommunityResponse>(msg, CommunityResponse);
|
|
|
|
this.state.communityRes.match({
|
|
|
|
some: res => {
|
|
|
|
res.community_view.subscribed = data.community_view.subscribed;
|
|
|
|
res.community_view.counts.subscribers =
|
|
|
|
data.community_view.counts.subscribers;
|
|
|
|
},
|
|
|
|
none: void 0,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetPosts) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetPostsResponse>(msg, GetPostsResponse);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ posts: data.posts, postsLoading: false });
|
2021-02-02 18:36:59 +00:00
|
|
|
restoreScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditPost ||
|
|
|
|
op == UserOperation.DeletePost ||
|
|
|
|
op == UserOperation.RemovePost ||
|
|
|
|
op == UserOperation.LockPost ||
|
|
|
|
op == UserOperation.StickyPost ||
|
|
|
|
op == UserOperation.SavePost
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
editPostFindRes(data.post_view, this.state.posts);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePost) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.posts.unshift(data.post_view);
|
2021-08-20 02:56:18 +00:00
|
|
|
if (
|
2022-06-21 21:42:29 +00:00
|
|
|
UserService.Instance.myUserInfo
|
|
|
|
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
|
|
|
.unwrapOr(false)
|
2021-08-20 02:56:18 +00:00
|
|
|
) {
|
2021-07-22 20:18:13 +00:00
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePostLike) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
createPostLikeFindRes(data.post_view, this.state.posts);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.AddModToCommunity) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<AddModToCommunityResponse>(
|
|
|
|
msg,
|
|
|
|
AddModToCommunityResponse
|
|
|
|
);
|
|
|
|
this.state.communityRes.match({
|
|
|
|
some: res => (res.moderators = data.moderators),
|
|
|
|
none: void 0,
|
|
|
|
});
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.BanFromCommunity) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<BanFromCommunityResponse>(
|
|
|
|
msg,
|
|
|
|
BanFromCommunityResponse
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
// TODO this might be incorrect
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.posts
|
2021-03-15 18:09:31 +00:00
|
|
|
.filter(p => p.creator.id == data.person_view.person.id)
|
2020-12-24 01:58:27 +00:00
|
|
|
.forEach(p => (p.creator_banned_from_community = data.banned));
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetComments) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<GetCommentsResponse>(msg, GetCommentsResponse);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ comments: data.comments, commentsLoading: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
} else if (
|
2020-12-24 01:58:27 +00:00
|
|
|
op == UserOperation.EditComment ||
|
|
|
|
op == UserOperation.DeleteComment ||
|
|
|
|
op == UserOperation.RemoveComment
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
editCommentRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateComment) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Necessary since it might be a user reply
|
2021-01-07 18:55:09 +00:00
|
|
|
if (data.form_id) {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.comments.unshift(data.comment_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.SaveComment) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
saveCommentRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreateCommentLike) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg, CommentResponse);
|
2020-12-24 01:58:27 +00:00
|
|
|
createCommentLikeRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
2021-08-20 02:56:18 +00:00
|
|
|
} else if (op == UserOperation.BlockPerson) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<BlockPersonResponse>(msg, BlockPersonResponse);
|
2021-08-20 02:56:18 +00:00
|
|
|
updatePersonBlock(data);
|
2021-09-28 10:38:59 +00:00
|
|
|
} else if (op == UserOperation.CreatePostReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<PostReportResponse>(msg, PostReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
|
|
|
} else if (op == UserOperation.CreateCommentReport) {
|
2022-06-21 21:42:29 +00:00
|
|
|
let data = wsJsonToRes<CommentReportResponse>(msg, CommentReportResponse);
|
2021-09-28 10:38:59 +00:00
|
|
|
if (data) {
|
|
|
|
toast(i18n.t("report_created"));
|
|
|
|
}
|
2022-06-23 19:44:05 +00:00
|
|
|
} else if (op == UserOperation.PurgeCommunity) {
|
|
|
|
let data = wsJsonToRes<PurgeItemResponse>(msg, PurgeItemResponse);
|
|
|
|
if (data.success) {
|
|
|
|
toast(i18n.t("purge_success"));
|
|
|
|
this.context.router.history.push(`/`);
|
|
|
|
}
|
2022-07-30 03:38:37 +00:00
|
|
|
} 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);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|