2021-02-23 14:58:31 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { T } from "inferno-i18next";
|
2021-02-23 14:58:31 +00:00
|
|
|
import { Link } from "inferno-router";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
AddAdminResponse,
|
|
|
|
BanPersonResponse,
|
|
|
|
CommentResponse,
|
|
|
|
CommentView,
|
2020-12-24 01:58:27 +00:00
|
|
|
CommunityFollowerView,
|
2021-07-17 20:42:55 +00:00
|
|
|
CommunityView,
|
|
|
|
GetComments,
|
|
|
|
GetCommentsResponse,
|
2020-09-06 16:15:25 +00:00
|
|
|
GetFollowedCommunitiesResponse,
|
2021-07-17 20:42:55 +00:00
|
|
|
GetPosts,
|
|
|
|
GetPostsResponse,
|
|
|
|
GetSiteResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
ListCommunities,
|
2020-09-06 16:15:25 +00:00
|
|
|
ListCommunitiesResponse,
|
|
|
|
ListingType,
|
|
|
|
PostResponse,
|
2020-12-24 01:58:27 +00:00
|
|
|
PostView,
|
2021-07-17 20:42:55 +00:00
|
|
|
SiteResponse,
|
|
|
|
SortType,
|
|
|
|
UserOperation,
|
2021-02-23 14:58:31 +00:00
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { DataType, InitialFetchRequest } from "../../interfaces";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
2020-09-06 16:15:25 +00:00
|
|
|
import {
|
2021-07-17 20:42:55 +00:00
|
|
|
authField,
|
|
|
|
commentsToFlatNodes,
|
|
|
|
createCommentLikeRes,
|
|
|
|
createPostLikeFindRes,
|
|
|
|
editCommentRes,
|
|
|
|
editPostFindRes,
|
2020-09-06 16:15:25 +00:00
|
|
|
fetchLimit,
|
2021-07-17 20:42:55 +00:00
|
|
|
getDataTypeFromProps,
|
2020-09-06 16:15:25 +00:00
|
|
|
getListingTypeFromProps,
|
|
|
|
getPageFromProps,
|
|
|
|
getSortTypeFromProps,
|
2021-07-17 20:42:55 +00:00
|
|
|
mdToHtml,
|
2020-09-06 16:15:25 +00:00
|
|
|
notifyPost,
|
2021-07-17 20:42:55 +00:00
|
|
|
restoreScrollPosition,
|
|
|
|
saveCommentRes,
|
|
|
|
saveScrollPosition,
|
2020-09-08 04:09:11 +00:00
|
|
|
setIsoData,
|
2020-12-24 22:05:57 +00:00
|
|
|
setOptionalAuth,
|
2021-07-17 20:42:55 +00:00
|
|
|
setupTippy,
|
2021-04-23 21:48:31 +00:00
|
|
|
showLocal,
|
2021-07-17 20:42:55 +00:00
|
|
|
toast,
|
|
|
|
wsClient,
|
|
|
|
wsJsonToRes,
|
|
|
|
wsSubscribe,
|
|
|
|
wsUserOp,
|
|
|
|
} 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 { ListingTypeSelect } from "../common/listing-type-select";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { SortSelect } from "../common/sort-select";
|
|
|
|
import { CommunityLink } from "../community/community-link";
|
|
|
|
import { PersonListing } from "../person/person-listing";
|
|
|
|
import { PostListings } from "../post/post-listings";
|
|
|
|
import { SiteForm } from "./site-form";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
interface HomeState {
|
2020-12-24 01:58:27 +00:00
|
|
|
subscribedCommunities: CommunityFollowerView[];
|
|
|
|
trendingCommunities: CommunityView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
siteRes: GetSiteResponse;
|
|
|
|
showEditSite: boolean;
|
2021-07-18 03:56:33 +00:00
|
|
|
showSubscribedMobile: boolean;
|
|
|
|
showTrendingMobile: boolean;
|
|
|
|
showSidebarMobile: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: boolean;
|
2020-12-24 01:58:27 +00:00
|
|
|
posts: PostView[];
|
|
|
|
comments: CommentView[];
|
2020-09-06 16:15:25 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
interface HomeProps {
|
2020-09-06 16:15:25 +00:00
|
|
|
listingType: ListingType;
|
|
|
|
dataType: DataType;
|
|
|
|
sort: SortType;
|
|
|
|
page: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UrlParams {
|
|
|
|
listingType?: ListingType;
|
|
|
|
dataType?: string;
|
|
|
|
sort?: SortType;
|
|
|
|
page?: number;
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
export class Home extends Component<any, HomeState> {
|
2020-09-08 04:09:11 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
private subscription: Subscription;
|
2021-07-17 20:42:55 +00:00
|
|
|
private emptyState: HomeState = {
|
2020-09-06 16:15:25 +00:00
|
|
|
subscribedCommunities: [],
|
|
|
|
trendingCommunities: [],
|
2020-12-24 01:58:27 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2020-09-06 16:15:25 +00:00
|
|
|
showEditSite: false,
|
2021-07-18 03:56:33 +00:00
|
|
|
showSubscribedMobile: false,
|
|
|
|
showTrendingMobile: false,
|
|
|
|
showSidebarMobile: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: true,
|
|
|
|
posts: [],
|
|
|
|
comments: [],
|
|
|
|
listingType: getListingTypeFromProps(this.props),
|
|
|
|
dataType: getDataTypeFromProps(this.props),
|
|
|
|
sort: getSortTypeFromProps(this.props),
|
|
|
|
page: getPageFromProps(this.props),
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
|
|
|
this.handleEditCancel = this.handleEditCancel.bind(this);
|
|
|
|
this.handleSortChange = this.handleSortChange.bind(this);
|
|
|
|
this.handleListingTypeChange = this.handleListingTypeChange.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 04:09:11 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
|
|
|
|
// Only fetch the data if coming from another route
|
|
|
|
if (this.isoData.path == this.context.router.route.match.url) {
|
|
|
|
if (this.state.dataType == DataType.Post) {
|
|
|
|
this.state.posts = this.isoData.routeData[0].posts;
|
|
|
|
} else {
|
|
|
|
this.state.comments = this.isoData.routeData[0].comments;
|
|
|
|
}
|
|
|
|
this.state.trendingCommunities = this.isoData.routeData[1].communities;
|
2021-03-15 18:09:31 +00:00
|
|
|
if (UserService.Instance.localUserView) {
|
2021-07-16 19:40:56 +00:00
|
|
|
this.state.subscribedCommunities =
|
|
|
|
this.isoData.routeData[2].communities;
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
this.state.loading = false;
|
|
|
|
} else {
|
|
|
|
this.fetchTrendingCommunities();
|
|
|
|
this.fetchData();
|
2021-03-15 18:09:31 +00:00
|
|
|
if (UserService.Instance.localUserView) {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.getFollowedCommunities({
|
|
|
|
auth: authField(),
|
|
|
|
})
|
|
|
|
);
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2020-09-08 04:09:11 +00:00
|
|
|
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchTrendingCommunities() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let listCommunitiesForm: ListCommunities = {
|
2021-01-26 15:59:38 +00:00
|
|
|
type_: ListingType.Local,
|
2020-09-08 04:09:11 +00:00
|
|
|
sort: SortType.Hot,
|
|
|
|
limit: 6,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(false),
|
2020-09-08 04:09:11 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.listCommunities(listCommunitiesForm)
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 15:37:23 +00:00
|
|
|
componentDidMount() {
|
2020-09-15 16:44:46 +00:00
|
|
|
// This means it hasn't been set up yet
|
2020-12-24 01:58:27 +00:00
|
|
|
if (!this.state.siteRes.site_view) {
|
2021-02-23 14:58:31 +00:00
|
|
|
this.context.router.history.push("/setup");
|
2020-09-15 16:44:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.communityJoin({ community_id: 0 }));
|
2020-09-13 15:37:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
componentWillUnmount() {
|
2021-02-02 18:36:59 +00:00
|
|
|
saveScrollPosition(this.context);
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
window.isoData.path = undefined;
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
static getDerivedStateFromProps(props: any): HomeProps {
|
2020-09-08 04:09:11 +00:00
|
|
|
return {
|
|
|
|
listingType: getListingTypeFromProps(props),
|
|
|
|
dataType: getDataTypeFromProps(props),
|
|
|
|
sort: getSortTypeFromProps(props),
|
|
|
|
page: getPageFromProps(props),
|
|
|
|
};
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
2021-02-23 14:58:31 +00:00
|
|
|
let pathSplit = req.path.split("/");
|
2020-09-08 04:09:11 +00:00
|
|
|
let dataType: DataType = pathSplit[3]
|
|
|
|
? DataType[pathSplit[3]]
|
|
|
|
: DataType.Post;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2020-09-08 04:09:11 +00:00
|
|
|
// TODO figure out auth default_listingType, default_sort_type
|
|
|
|
let type_: ListingType = pathSplit[5]
|
|
|
|
? ListingType[pathSplit[5]]
|
2021-03-15 18:09:31 +00:00
|
|
|
: UserService.Instance.localUserView
|
2020-09-08 04:09:11 +00:00
|
|
|
? Object.values(ListingType)[
|
2021-03-15 18:09:31 +00:00
|
|
|
UserService.Instance.localUserView.local_user.default_listing_type
|
2020-09-08 04:09:11 +00:00
|
|
|
]
|
2020-10-05 02:11:48 +00:00
|
|
|
: ListingType.Local;
|
2020-09-08 04:09:11 +00:00
|
|
|
let sort: SortType = pathSplit[7]
|
|
|
|
? SortType[pathSplit[7]]
|
2021-03-15 18:09:31 +00:00
|
|
|
: UserService.Instance.localUserView
|
|
|
|
? Object.values(SortType)[
|
|
|
|
UserService.Instance.localUserView.local_user.default_sort_type
|
|
|
|
]
|
2020-09-08 04:09:11 +00:00
|
|
|
: SortType.Active;
|
|
|
|
|
|
|
|
let page = pathSplit[9] ? Number(pathSplit[9]) : 1;
|
|
|
|
|
|
|
|
let promises: Promise<any>[] = [];
|
|
|
|
|
|
|
|
if (dataType == DataType.Post) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let getPostsForm: GetPosts = {
|
2020-09-08 04:09:11 +00:00
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort,
|
|
|
|
type_,
|
2021-03-23 22:58:13 +00:00
|
|
|
saved_only: false,
|
2020-09-08 04:09:11 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
setOptionalAuth(getPostsForm, req.auth);
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getPosts(getPostsForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
let getCommentsForm: GetComments = {
|
2020-09-08 04:09:11 +00:00
|
|
|
page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort,
|
|
|
|
type_,
|
2021-03-23 22:58:13 +00:00
|
|
|
saved_only: false,
|
2020-09-08 04:09:11 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
setOptionalAuth(getCommentsForm, req.auth);
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.getComments(getCommentsForm));
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
let trendingCommunitiesForm: ListCommunities = {
|
2021-01-26 15:59:38 +00:00
|
|
|
type_: ListingType.Local,
|
2020-09-08 04:09:11 +00:00
|
|
|
sort: SortType.Hot,
|
|
|
|
limit: 6,
|
|
|
|
};
|
2020-11-12 21:56:46 +00:00
|
|
|
promises.push(req.client.listCommunities(trendingCommunitiesForm));
|
2020-09-08 04:09:11 +00:00
|
|
|
|
2020-11-12 21:56:46 +00:00
|
|
|
if (req.auth) {
|
|
|
|
promises.push(req.client.getFollowedCommunities({ auth: req.auth }));
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return promises;
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
componentDidUpdate(_: any, lastState: HomeState) {
|
2020-09-08 04:09:11 +00:00
|
|
|
if (
|
|
|
|
lastState.listingType !== this.state.listingType ||
|
|
|
|
lastState.dataType !== this.state.dataType ||
|
|
|
|
lastState.sort !== this.state.sort ||
|
|
|
|
lastState.page !== this.state.page
|
|
|
|
) {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
this.fetchData();
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 04:09:11 +00:00
|
|
|
get documentTitle(): string {
|
2020-09-15 16:44:46 +00:00
|
|
|
return `${
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.siteRes.site_view
|
2021-04-26 13:57:41 +00:00
|
|
|
? this.state.siteRes.site_view.site.description
|
|
|
|
? `${this.state.siteRes.site_view.site.name} - ${this.state.siteRes.site_view.site.description}`
|
|
|
|
: this.state.siteRes.site_view.site.name
|
2021-02-23 14:58:31 +00:00
|
|
|
: "Lemmy"
|
2020-09-15 16:44:46 +00:00
|
|
|
}`;
|
2020-09-08 04:09:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2021-01-19 15:34:04 +00:00
|
|
|
{this.state.siteRes.site_view?.site && (
|
2020-09-15 16:44:46 +00:00
|
|
|
<div class="row">
|
|
|
|
<main role="main" class="col-12 col-md-8">
|
2021-07-18 03:56:33 +00:00
|
|
|
<div class="d-block d-md-none">{this.mobileView()}</div>
|
2020-09-15 16:44:46 +00:00
|
|
|
{this.posts()}
|
|
|
|
</main>
|
2021-07-18 03:56:33 +00:00
|
|
|
<aside class="d-none d-md-block col-md-4">{this.mySidebar()}</aside>
|
2020-09-15 16:44:46 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
mobileView() {
|
|
|
|
return (
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-12">
|
|
|
|
{UserService.Instance.localUserView &&
|
|
|
|
this.state.subscribedCommunities.length > 0 && (
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowSubscribedMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("subscribed")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showSubscribedMobile
|
|
|
|
? `minus-square`
|
|
|
|
: `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
class="btn btn-secondary d-inline-block mb-2 mr-3"
|
|
|
|
onClick={linkEvent(this, this.handleShowTrendingMobile)}
|
|
|
|
>
|
|
|
|
{i18n.t("trending")}{" "}
|
|
|
|
<Icon
|
|
|
|
icon={
|
|
|
|
this.state.showTrendingMobile ? `minus-square` : `plus-square`
|
|
|
|
}
|
|
|
|
classes="icon-inline"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="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.showSubscribedMobile && (
|
|
|
|
<div class="col-12 card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.subscribedCommunities()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.state.showTrendingMobile && (
|
|
|
|
<div class="col-12 card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.trendingCommunities()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.state.showSidebarMobile && (
|
|
|
|
<div class="col-12 card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.sidebar()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
mySidebar() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!this.state.loading && (
|
|
|
|
<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.trendingCommunities()}
|
|
|
|
{this.createCommunityButton()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
{UserService.Instance.localUserView &&
|
2020-09-23 23:01:45 +00:00
|
|
|
this.state.subscribedCommunities.length > 0 && (
|
|
|
|
<div class="card border-secondary mb-3">
|
|
|
|
<div class="card-body">{this.subscribedCommunities()}</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div class="card border-secondary mb-3">
|
2020-09-06 16:15:25 +00:00
|
|
|
<div class="card-body">{this.sidebar()}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
createCommunityButton() {
|
|
|
|
return (
|
2020-09-08 04:09:11 +00:00
|
|
|
<Link className="btn btn-secondary btn-block" to="/create_community">
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("create_a_community")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
trendingCommunities() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
<T i18nKey="trending_communities">
|
|
|
|
#
|
2020-09-08 04:09:11 +00:00
|
|
|
<Link className="text-body" to="/communities">
|
2020-09-06 16:15:25 +00:00
|
|
|
#
|
|
|
|
</Link>
|
|
|
|
</T>
|
|
|
|
</h5>
|
|
|
|
<ul class="list-inline">
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.trendingCommunities.map(cv => (
|
2021-01-08 05:03:02 +00:00
|
|
|
<li class="list-inline-item d-inline-block">
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cv.community} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribedCommunities() {
|
|
|
|
return (
|
2020-09-23 23:01:45 +00:00
|
|
|
<div>
|
|
|
|
<h5>
|
|
|
|
<T i18nKey="subscribed_to_communities">
|
|
|
|
#
|
|
|
|
<Link className="text-body" to="/communities">
|
2020-09-06 16:15:25 +00:00
|
|
|
#
|
2020-09-23 23:01:45 +00:00
|
|
|
</Link>
|
|
|
|
</T>
|
|
|
|
</h5>
|
|
|
|
<ul class="list-inline mb-0">
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.subscribedCommunities.map(cfv => (
|
2021-01-08 05:03:02 +00:00
|
|
|
<li class="list-inline-item d-inline-block">
|
2020-12-24 01:58:27 +00:00
|
|
|
<CommunityLink community={cfv.community} />
|
2020-09-23 23:01:45 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sidebar() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let site = this.state.siteRes.site_view.site;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{!this.state.showEditSite ? (
|
2020-09-23 23:01:45 +00:00
|
|
|
<div>
|
|
|
|
<div class="mb-2">
|
|
|
|
{this.siteName()}
|
|
|
|
{this.adminButtons()}
|
|
|
|
</div>
|
2020-12-24 01:58:27 +00:00
|
|
|
<BannerIconHeader banner={site.banner} />
|
2020-09-23 23:01:45 +00:00
|
|
|
{this.siteInfo()}
|
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
) : (
|
2020-12-24 01:58:27 +00:00
|
|
|
<SiteForm site={site} onCancel={this.handleEditCancel} />
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateUrl(paramUpdates: UrlParams) {
|
|
|
|
const listingTypeStr = paramUpdates.listingType || this.state.listingType;
|
|
|
|
const dataTypeStr = paramUpdates.dataType || DataType[this.state.dataType];
|
|
|
|
const sortStr = paramUpdates.sort || this.state.sort;
|
|
|
|
const page = paramUpdates.page || this.state.page;
|
|
|
|
this.props.history.push(
|
|
|
|
`/home/data_type/${dataTypeStr}/listing_type/${listingTypeStr}/sort/${sortStr}/page/${page}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
siteInfo() {
|
2021-04-23 22:26:36 +00:00
|
|
|
let site = this.state.siteRes.site_view.site;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2021-04-23 22:26:36 +00:00
|
|
|
{site.description && <h6>{site.description}</h6>}
|
|
|
|
{site.sidebar && this.siteSidebar()}
|
2020-09-06 16:15:25 +00:00
|
|
|
{this.badges()}
|
|
|
|
{this.admins()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
siteName() {
|
2021-05-04 17:57:02 +00:00
|
|
|
let site = this.state.siteRes.site_view.site;
|
|
|
|
return site.name && <h5 class="mb-0">{site.name}</h5>;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
admins() {
|
|
|
|
return (
|
|
|
|
<ul class="mt-1 list-inline small mb-0">
|
2021-02-23 14:58:31 +00:00
|
|
|
<li class="list-inline-item">{i18n.t("admins")}:</li>
|
2020-12-24 01:58:27 +00:00
|
|
|
{this.state.siteRes.admins.map(av => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<li class="list-inline-item">
|
2021-03-15 18:09:31 +00:00
|
|
|
<PersonListing person={av.person} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
badges() {
|
2021-01-29 15:10:37 +00:00
|
|
|
let counts = this.state.siteRes.site_view.counts;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<ul class="my-2 list-inline">
|
2020-09-23 23:01:45 +00:00
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("number_online", { count: this.state.siteRes.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-23 14:58:31 +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-23 14:58:31 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("day")}`}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_day,
|
2021-02-23 14:58:31 +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-23 14:58:31 +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-23 14:58:31 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("week")}`}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_week,
|
2021-02-23 14:58:31 +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-23 14:58:31 +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-23 14:58:31 +00:00
|
|
|
})} ${i18n.t("active_in_the_last")} ${i18n.t("month")}`}
|
2021-02-02 17:12:16 +00:00
|
|
|
>
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_month,
|
2021-02-23 14:58:31 +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-23 14:58:31 +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-23 14:58:31 +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-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users_active_half_year,
|
2021-02-23 14:58:31 +00:00
|
|
|
})}{" "}
|
|
|
|
/ {i18n.t("number_of_months", { count: 6 })}
|
2021-01-29 15:10:37 +00:00
|
|
|
</li>
|
|
|
|
<li className="list-inline-item badge badge-secondary">
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_users", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.users,
|
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-23 14:58:31 +00:00
|
|
|
{i18n.t("number_of_communities", {
|
2021-01-29 15:10:37 +00:00
|
|
|
count: counts.communities,
|
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-23 14:58:31 +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-23 14:58:31 +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">
|
2020-09-23 23:01:45 +00:00
|
|
|
<Link className="badge badge-secondary" to="/modlog">
|
2021-02-23 14:58:31 +00:00
|
|
|
{i18n.t("modlog")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
adminButtons() {
|
|
|
|
return (
|
|
|
|
this.canAdmin && (
|
|
|
|
<ul class="list-inline mb-1 text-muted font-weight-bold">
|
|
|
|
<li className="list-inline-item-action">
|
2021-07-17 20:42:55 +00:00
|
|
|
<button
|
|
|
|
class="btn btn-link d-inline-block text-muted"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleEditClick)}
|
2021-02-23 14:58:31 +00:00
|
|
|
aria-label={i18n.t("edit")}
|
|
|
|
data-tippy-content={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>
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-23 22:26:36 +00:00
|
|
|
siteSidebar() {
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="md-div"
|
2020-12-24 01:58:27 +00:00
|
|
|
dangerouslySetInnerHTML={mdToHtml(
|
2021-04-23 22:26:36 +00:00
|
|
|
this.state.siteRes.site_view.site.sidebar
|
2020-12-24 01:58:27 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
|
|
|
return (
|
|
|
|
<div class="main-content-wrapper">
|
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-06 16:15:25 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
{this.selects()}
|
|
|
|
{this.listings()}
|
2021-07-16 19:40:56 +00:00
|
|
|
<Paginator
|
|
|
|
page={this.state.page}
|
|
|
|
onChange={this.handlePageChange}
|
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
listings() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let site = this.state.siteRes.site_view.site;
|
2020-09-06 16:15:25 +00:00
|
|
|
return this.state.dataType == DataType.Post ? (
|
|
|
|
<PostListings
|
|
|
|
posts={this.state.posts}
|
|
|
|
showCommunity
|
|
|
|
removeDuplicates
|
2020-12-24 01:58:27 +00:00
|
|
|
enableDownvotes={site.enable_downvotes}
|
|
|
|
enableNsfw={site.enable_nsfw}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<CommentNodes
|
|
|
|
nodes={commentsToFlatNodes(this.state.comments)}
|
|
|
|
noIndent
|
|
|
|
showCommunity
|
|
|
|
showContext
|
2020-12-24 01:58:27 +00:00
|
|
|
enableDownvotes={site.enable_downvotes}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
selects() {
|
|
|
|
return (
|
|
|
|
<div className="mb-3">
|
|
|
|
<span class="mr-3">
|
|
|
|
<DataTypeSelect
|
|
|
|
type_={this.state.dataType}
|
|
|
|
onChange={this.handleDataTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="mr-3">
|
|
|
|
<ListingTypeSelect
|
|
|
|
type_={this.state.listingType}
|
2021-04-23 21:48:31 +00:00
|
|
|
showLocal={showLocal(this.isoData)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={this.handleListingTypeChange}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
<span class="mr-2">
|
|
|
|
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
|
|
|
|
</span>
|
|
|
|
{this.state.listingType == ListingType.All && (
|
|
|
|
<a
|
|
|
|
href={`/feeds/all.xml?sort=${this.state.sort}`}
|
|
|
|
rel="noopener"
|
|
|
|
title="RSS"
|
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</a>
|
|
|
|
)}
|
2020-11-25 20:19:42 +00:00
|
|
|
{this.state.listingType == ListingType.Local && (
|
|
|
|
<a
|
|
|
|
href={`/feeds/local.xml?sort=${this.state.sort}`}
|
|
|
|
rel="noopener"
|
|
|
|
title="RSS"
|
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
2020-11-25 20:19:42 +00:00
|
|
|
</a>
|
|
|
|
)}
|
2021-03-15 18:09:31 +00:00
|
|
|
{UserService.Instance.localUserView &&
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.listingType == ListingType.Subscribed && (
|
|
|
|
<a
|
|
|
|
href={`/feeds/front/${UserService.Instance.auth}.xml?sort=${this.state.sort}`}
|
|
|
|
title="RSS"
|
|
|
|
rel="noopener"
|
|
|
|
>
|
2021-02-11 20:35:27 +00:00
|
|
|
<Icon icon="rss" classes="text-muted small" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get canAdmin(): boolean {
|
|
|
|
return (
|
2021-03-15 18:09:31 +00:00
|
|
|
UserService.Instance.localUserView &&
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.siteRes.admins
|
2021-03-15 18:09:31 +00:00
|
|
|
.map(a => a.person.id)
|
|
|
|
.includes(UserService.Instance.localUserView.person.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-17 20:42:55 +00:00
|
|
|
handleEditClick(i: Home) {
|
2020-09-06 16:15:25 +00:00
|
|
|
i.state.showEditSite = true;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditCancel() {
|
|
|
|
this.state.showEditSite = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
|
2021-07-18 03:56:33 +00:00
|
|
|
handleShowSubscribedMobile(i: Home) {
|
|
|
|
i.state.showSubscribedMobile = !i.state.showSubscribedMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowTrendingMobile(i: Home) {
|
|
|
|
i.state.showTrendingMobile = !i.state.showTrendingMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowSidebarMobile(i: Home) {
|
|
|
|
i.state.showSidebarMobile = !i.state.showSidebarMobile;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleListingTypeChange(val: ListingType) {
|
|
|
|
this.updateUrl({ listingType: val, page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDataTypeChange(val: DataType) {
|
|
|
|
this.updateUrl({ dataType: DataType[val], page: 1 });
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
if (this.state.dataType == DataType.Post) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let getPostsForm: GetPosts = {
|
2020-09-06 16:15:25 +00:00
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort: this.state.sort,
|
|
|
|
type_: this.state.listingType,
|
2021-03-23 22:58:13 +00:00
|
|
|
saved_only: false,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getPosts(getPostsForm));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
let getCommentsForm: GetComments = {
|
2020-09-06 16:15:25 +00:00
|
|
|
page: this.state.page,
|
|
|
|
limit: fetchLimit,
|
|
|
|
sort: this.state.sort,
|
|
|
|
type_: this.state.listingType,
|
2021-03-23 22:58:13 +00:00
|
|
|
saved_only: false,
|
2020-12-24 22:05:57 +00:00
|
|
|
auth: authField(false),
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getComments(getCommentsForm));
|
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-23 14:58:31 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
2020-09-06 16:15:25 +00:00
|
|
|
return;
|
|
|
|
} else if (msg.reconnect) {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(
|
|
|
|
wsClient.communityJoin({ community_id: 0 })
|
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.fetchData();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetFollowedCommunities) {
|
|
|
|
let data = wsJsonToRes<GetFollowedCommunitiesResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.subscribedCommunities = data.communities;
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.ListCommunities) {
|
|
|
|
let data = wsJsonToRes<ListCommunitiesResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.trendingCommunities = data.communities;
|
|
|
|
this.setState(this.state);
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.EditSite) {
|
|
|
|
let data = wsJsonToRes<SiteResponse>(msg).data;
|
|
|
|
this.state.siteRes.site_view = data.site_view;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.showEditSite = false;
|
|
|
|
this.setState(this.state);
|
2021-02-23 14:58:31 +00:00
|
|
|
toast(i18n.t("site_saved"));
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.GetPosts) {
|
|
|
|
let data = wsJsonToRes<GetPostsResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.posts = data.posts;
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
2021-02-02 18:36:59 +00:00
|
|
|
restoreScrollPosition(this.context);
|
2020-09-06 16:15:25 +00:00
|
|
|
setupTippy();
|
2020-12-24 01:58:27 +00:00
|
|
|
} else if (op == UserOperation.CreatePost) {
|
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-01-24 05:56:00 +00:00
|
|
|
// NSFW check
|
|
|
|
let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw;
|
|
|
|
let nsfwCheck =
|
|
|
|
!nsfw ||
|
|
|
|
(nsfw &&
|
2021-03-15 18:09:31 +00:00
|
|
|
UserService.Instance.localUserView &&
|
|
|
|
UserService.Instance.localUserView.local_user.show_nsfw);
|
2021-01-24 05:56:00 +00:00
|
|
|
|
|
|
|
// Only push these if you're on the first page, and you pass the nsfw check
|
|
|
|
if (this.state.page == 1 && nsfwCheck) {
|
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
|
|
|
if (
|
|
|
|
this.state.subscribedCommunities
|
|
|
|
.map(c => c.community.id)
|
|
|
|
.includes(data.post_view.community.id)
|
|
|
|
) {
|
|
|
|
this.state.posts.unshift(data.post_view);
|
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
|
|
|
} else if (this.state.listingType == ListingType.Local) {
|
|
|
|
// If you're on the local view, only push it if its local
|
|
|
|
if (data.post_view.post.local) {
|
|
|
|
this.state.posts.unshift(data.post_view);
|
|
|
|
notifyPost(data.post_view, this.context.router);
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.posts.unshift(data.post_view);
|
|
|
|
notifyPost(data.post_view, this.context.router);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-01-24 05:56:00 +00:00
|
|
|
this.setState(this.state);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2020-09-25 21:16:41 +00:00
|
|
|
} 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-25 21:16:41 +00:00
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
|
|
|
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.CreatePostLike) {
|
|
|
|
let data = wsJsonToRes<PostResponse>(msg).data;
|
|
|
|
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.AddAdmin) {
|
|
|
|
let data = wsJsonToRes<AddAdminResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.siteRes.admins = data.admins;
|
|
|
|
this.setState(this.state);
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (op == UserOperation.BanPerson) {
|
|
|
|
let data = wsJsonToRes<BanPersonResponse>(msg).data;
|
2020-12-24 01:58:27 +00:00
|
|
|
let found = this.state.siteRes.banned.find(
|
2021-03-15 18:09:31 +00:00
|
|
|
p => (p.person.id = data.person_view.person.id)
|
2020-12-24 01:58:27 +00:00
|
|
|
);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Remove the banned if its found in the list, and the action is an unban
|
|
|
|
if (found && !data.banned) {
|
|
|
|
this.state.siteRes.banned = this.state.siteRes.banned.filter(
|
2021-03-15 18:09:31 +00:00
|
|
|
i => i.person.id !== data.person_view.person.id
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
} else {
|
2021-03-15 18:09:31 +00:00
|
|
|
this.state.siteRes.banned.push(data.person_view);
|
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 = 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) {
|
|
|
|
let data = wsJsonToRes<GetCommentsResponse>(msg).data;
|
2020-09-06 16:15:25 +00:00
|
|
|
this.state.comments = data.comments;
|
|
|
|
this.state.loading = false;
|
|
|
|
this.setState(this.state);
|
|
|
|
} 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
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
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) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
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-09-06 16:15:25 +00:00
|
|
|
// If you're on subscribed, only push it if you're subscribed.
|
|
|
|
if (this.state.listingType == ListingType.Subscribed) {
|
|
|
|
if (
|
|
|
|
this.state.subscribedCommunities
|
2020-12-24 01:58:27 +00:00
|
|
|
.map(c => c.community.id)
|
|
|
|
.includes(data.comment_view.community.id)
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
2020-12-24 01:58:27 +00:00
|
|
|
this.state.comments.unshift(data.comment_view);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
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) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
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) {
|
|
|
|
let data = wsJsonToRes<CommentResponse>(msg).data;
|
|
|
|
createCommentLikeRes(data.comment_view, this.state.comments);
|
2020-09-06 16:15:25 +00:00
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|