getDataTypeFromProps,
getPageFromProps,
getSortTypeFromProps,
+ isPostBlocked,
notifyPost,
+ nsfwCheck,
postToCommentSortType,
relTags,
restoreScrollPosition,
// Only fetch the data if coming from another route
if (this.isoData.path == this.context.router.route.match.url) {
- this.state.communityRes = Some(
- this.isoData.routeData[0] as GetCommunityResponse
- );
+ this.state = {
+ ...this.state,
+ communityRes: Some(this.isoData.routeData[0] as GetCommunityResponse),
+ };
let postsRes = Some(this.isoData.routeData[1] as GetPostsResponse);
let commentsRes = Some(this.isoData.routeData[2] as GetCommentsResponse);
- postsRes.match({
- some: pvs => (this.state.posts = pvs.posts),
- none: void 0,
- });
- commentsRes.match({
- some: cvs => (this.state.comments = cvs.comments),
- none: void 0,
- });
+ if (postsRes.isSome()) {
+ this.state = { ...this.state, posts: postsRes.unwrap().posts };
+ }
+
+ if (commentsRes.isSome()) {
+ this.state = { ...this.state, comments: commentsRes.unwrap().comments };
+ }
- this.state.communityLoading = false;
- this.state.postsLoading = false;
- this.state.commentsLoading = false;
+ this.state = {
+ ...this.state,
+ communityLoading: false,
+ postsLoading: false,
+ commentsLoading: false,
+ };
} else {
this.fetchCommunity();
this.fetchData();
get documentTitle(): string {
return this.state.communityRes.match({
some: res =>
- this.state.siteRes.site_view.match({
- some: siteView =>
- `${res.community_view.community.title} - ${siteView.site.name}`,
- none: "",
- }),
+ `${res.community_view.community.title} - ${this.state.siteRes.site_view.site.name}`,
none: "",
});
}
render() {
+ // For some reason, this returns an empty vec if it matches the site langs
+ let communityLangs = this.state.communityRes.map(r => {
+ let langs = r.discussion_languages;
+ if (langs.length == 0) {
+ return this.state.siteRes.all_languages.map(l => l.id);
+ } else {
+ return langs;
+ }
+ });
+
return (
- <div class="container">
+ <div className="container-lg">
{this.state.communityLoading ? (
<h5>
<Spinner large />
image={res.community_view.community.icon}
/>
- <div class="row">
- <div class="col-12 col-md-8">
+ <div className="row">
+ <div className="col-12 col-md-8">
{this.communityInfo()}
- <div class="d-block d-md-none">
+ <div className="d-block d-md-none">
<button
- class="btn btn-secondary d-inline-block mb-2 mr-3"
+ className="btn btn-secondary d-inline-block mb-2 mr-3"
onClick={linkEvent(this, this.handleShowSidebarMobile)}
>
{i18n.t("sidebar")}{" "}
admins={this.state.siteRes.admins}
online={res.online}
enableNsfw={enableNsfw(this.state.siteRes)}
+ editable
+ allLanguages={this.state.siteRes.all_languages}
+ siteLanguages={
+ this.state.siteRes.discussion_languages
+ }
+ communityLanguages={communityLangs}
/>
{!res.community_view.community.local &&
res.site.match({
onChange={this.handlePageChange}
/>
</div>
- <div class="d-none d-md-block col-md-4">
+ <div className="d-none d-md-block col-md-4">
<Sidebar
community_view={res.community_view}
moderators={res.moderators}
admins={this.state.siteRes.admins}
online={res.online}
enableNsfw={enableNsfw(this.state.siteRes)}
+ editable
+ allLanguages={this.state.siteRes.all_languages}
+ siteLanguages={this.state.siteRes.discussion_languages}
+ communityLanguages={communityLangs}
/>
{!res.community_view.community.local &&
res.site.match({
removeDuplicates
enableDownvotes={enableDownvotes(this.state.siteRes)}
enableNsfw={enableNsfw(this.state.siteRes)}
+ allLanguages={this.state.siteRes.all_languages}
+ siteLanguages={this.state.siteRes.discussion_languages}
/>
)
) : this.state.commentsLoading ? (
moderators={this.state.communityRes.map(r => r.moderators)}
admins={Some(this.state.siteRes.admins)}
maxCommentsShown={None}
+ allLanguages={this.state.siteRes.all_languages}
+ siteLanguages={this.state.siteRes.discussion_languages}
/>
);
}
.map(r => r.community_view.community)
.match({
some: community => (
- <div class="mb-2">
+ <div className="mb-2">
<BannerIconHeader banner={community.banner} icon={community.icon} />
- <h5 class="mb-0 overflow-wrap-anywhere">{community.title}</h5>
+ <h5 className="mb-0 overflow-wrap-anywhere">{community.title}</h5>
<CommunityLink
community={community}
realLink
communityRSSUrl(r.community_view.community.actor_id, this.state.sort)
);
return (
- <div class="mb-3">
- <span class="mr-3">
+ <div className="mb-3">
+ <span className="mr-3">
<DataTypeSelect
type_={this.state.dataType}
onChange={this.handleDataTypeChange}
/>
</span>
- <span class="mr-2">
+ <span className="mr-2">
<SortSelect sort={this.state.sort} onChange={this.handleSortChange} />
</span>
{communityRss.match({
}
handleShowSidebarMobile(i: Community) {
- i.state.showSidebarMobile = !i.state.showSidebarMobile;
- i.setState(i.state);
+ i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
}
updateUrl(paramUpdates: UrlParams) {
this.fetchData();
} else if (op == UserOperation.GetCommunity) {
let data = wsJsonToRes<GetCommunityResponse>(msg, GetCommunityResponse);
- this.state.communityRes = Some(data);
- this.state.communityLoading = false;
- this.setState(this.state);
+ this.setState({ communityRes: Some(data), communityLoading: false });
// TODO why is there no auth in this form?
WebSocketService.Instance.send(
wsClient.communityJoin({
) {
let data = wsJsonToRes<CommunityResponse>(msg, CommunityResponse);
this.state.communityRes.match({
- some: res => (res.community_view = data.community_view),
+ some: res => {
+ res.community_view = data.community_view;
+ res.discussion_languages = data.discussion_languages;
+ },
none: void 0,
});
this.setState(this.state);
this.setState(this.state);
} else if (op == UserOperation.GetPosts) {
let data = wsJsonToRes<GetPostsResponse>(msg, GetPostsResponse);
- this.state.posts = data.posts;
- this.state.postsLoading = false;
- this.setState(this.state);
+ this.setState({ posts: data.posts, postsLoading: false });
restoreScrollPosition(this.context);
setupTippy();
} else if (
op == UserOperation.DeletePost ||
op == UserOperation.RemovePost ||
op == UserOperation.LockPost ||
- op == UserOperation.StickyPost ||
+ op == UserOperation.FeaturePost ||
op == UserOperation.SavePost
) {
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
this.setState(this.state);
} else if (op == UserOperation.CreatePost) {
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
- this.state.posts.unshift(data.post_view);
+
+ let showPostNotifs = UserService.Instance.myUserInfo
+ .map(m => m.local_user_view.local_user.show_new_post_notifs)
+ .unwrapOr(false);
+
+ // Only push these if you're on the first page, you pass the nsfw check, and it isn't blocked
+ //
if (
- UserService.Instance.myUserInfo
- .map(m => m.local_user_view.local_user.show_new_post_notifs)
- .unwrapOr(false)
+ this.state.page == 1 &&
+ nsfwCheck(data.post_view) &&
+ !isPostBlocked(data.post_view)
) {
- notifyPost(data.post_view, this.context.router);
+ this.state.posts.unshift(data.post_view);
+ if (showPostNotifs) {
+ notifyPost(data.post_view, this.context.router);
+ }
+ this.setState(this.state);
}
- this.setState(this.state);
} else if (op == UserOperation.CreatePostLike) {
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
createPostLikeFindRes(data.post_view, this.state.posts);
this.setState(this.state);
} else if (op == UserOperation.GetComments) {
let data = wsJsonToRes<GetCommentsResponse>(msg, GetCommentsResponse);
- this.state.comments = data.comments;
- this.state.commentsLoading = false;
- this.setState(this.state);
+ this.setState({ comments: data.comments, commentsLoading: false });
} else if (
op == UserOperation.EditComment ||
op == UserOperation.DeleteComment ||