BanFromCommunityResponse,
BanPersonResponse,
BlockPersonResponse,
- CommentNode as CommentNodeI,
CommentReportResponse,
CommentResponse,
CommentSortType,
GetPost,
GetPostResponse,
GetSiteResponse,
- ListingType,
PostReportResponse,
PostResponse,
PostView,
PurgeItemResponse,
Search,
SearchResponse,
- SearchType,
- SortType,
UserOperation,
wsJsonToRes,
wsUserOp,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next";
-import { CommentViewType, InitialFetchRequest } from "../../interfaces";
+import {
+ CommentNodeI,
+ CommentViewType,
+ InitialFetchRequest,
+} from "../../interfaces";
import { UserService, WebSocketService } from "../../services";
import {
buildCommentsTree,
postId: getIdFromProps(this.props),
commentId: getCommentIdFromProps(this.props),
commentTree: [],
- commentSort: CommentSortType[CommentSortType.Hot],
+ commentSort: "Hot",
commentViewType: CommentViewType.Tree,
scrolled: false,
loading: true,
parent_id: this.state.commentId,
max_depth: commentTreeMaxDepth,
sort: this.state.commentSort,
- type_: ListingType.All,
+ type_: "All",
saved_only: false,
auth,
};
if (q) {
let form: Search = {
q,
- type_: SearchType.Url,
- sort: SortType.TopAll,
- listing_type: ListingType.All,
+ type_: "Url",
+ sort: "TopAll",
+ listing_type: "All",
page: 1,
limit: trendingFetchLimit,
auth: myAuth(false),
let commentsForm: GetComments = {
max_depth: commentTreeMaxDepth,
- sort: CommentSortType.Hot,
- type_: ListingType.All,
+ sort: "Hot",
+ type_: "All",
saved_only: false,
auth,
};
<div className="btn-group btn-group-toggle flex-wrap mr-3 mb-2">
<label
className={`btn btn-outline-secondary pointer ${
- CommentSortType[this.state.commentSort] === CommentSortType.Hot &&
- "active"
+ this.state.commentSort === "Hot" && "active"
}`}
>
{i18n.t("hot")}
<input
type="radio"
- value={CommentSortType.Hot}
- checked={this.state.commentSort === CommentSortType.Hot}
+ value={"Hot"}
+ checked={this.state.commentSort === "Hot"}
onChange={linkEvent(this, this.handleCommentSortChange)}
/>
</label>
<label
className={`btn btn-outline-secondary pointer ${
- CommentSortType[this.state.commentSort] === CommentSortType.Top &&
- "active"
+ this.state.commentSort === "Top" && "active"
}`}
>
{i18n.t("top")}
<input
type="radio"
- value={CommentSortType.Top}
- checked={this.state.commentSort === CommentSortType.Top}
+ value={"Top"}
+ checked={this.state.commentSort === "Top"}
onChange={linkEvent(this, this.handleCommentSortChange)}
/>
</label>
<label
className={`btn btn-outline-secondary pointer ${
- CommentSortType[this.state.commentSort] === CommentSortType.New &&
- "active"
+ this.state.commentSort === "New" && "active"
}`}
>
{i18n.t("new")}
<input
type="radio"
- value={CommentSortType.New}
- checked={this.state.commentSort === CommentSortType.New}
+ value={"New"}
+ checked={this.state.commentSort === "New"}
onChange={linkEvent(this, this.handleCommentSortChange)}
/>
</label>
<label
className={`btn btn-outline-secondary pointer ${
- CommentSortType[this.state.commentSort] === CommentSortType.Old &&
- "active"
+ this.state.commentSort === "Old" && "active"
}`}
>
{i18n.t("old")}
<input
type="radio"
- value={CommentSortType.Old}
- checked={this.state.commentSort === CommentSortType.Old}
+ value={"Old"}
+ checked={this.state.commentSort === "Old"}
onChange={linkEvent(this, this.handleCommentSortChange)}
/>
</label>
handleCommentSortChange(i: Post, event: any) {
i.setState({
- commentSort: CommentSortType[event.target.value],
+ commentSort: event.target.value as CommentSortType,
commentViewType: CommentViewType.Tree,
commentsRes: undefined,
postRes: undefined,
if (comments) {
i.setState({
commentViewType: Number(event.target.value),
- commentSort: CommentSortType.New,
+ commentSort: "New",
commentTree: buildCommentsTree(comments, !!i.state.commentId),
});
}
data.recipient_ids.length == 0 &&
!creatorBlocked &&
postRes &&
+ data.comment_view.post.id == postRes.post_view.post.id &&
commentsRes
) {
commentsRes.comments.unshift(data.comment_view);
op == UserOperation.SavePost
) {
let data = wsJsonToRes<PostResponse>(msg);
- let pv = this.state.postRes?.post_view;
- if (pv) {
- pv = data.post_view;
+ let res = this.state.postRes;
+ if (res) {
+ res.post_view = data.post_view;
this.setState(this.state);
setupTippy();
}
} else if (op == UserOperation.BanFromCommunity) {
let data = wsJsonToRes<BanFromCommunityResponse>(msg);
- let postRes = this.state.postRes;
- if (postRes) {
- if (postRes.post_view.creator.id == data.person_view.person.id) {
- postRes.post_view.creator_banned_from_community = data.banned;
+ let res = this.state.postRes;
+ if (res) {
+ if (res.post_view.creator.id == data.person_view.person.id) {
+ res.post_view.creator_banned_from_community = data.banned;
}
}
this.setState(this.state);
} else if (op == UserOperation.AddModToCommunity) {
let data = wsJsonToRes<AddModToCommunityResponse>(msg);
- let postRes = this.state.postRes;
- if (postRes) {
- postRes.moderators = data.moderators;
+ let res = this.state.postRes;
+ if (res) {
+ res.moderators = data.moderators;
this.setState(this.state);
}
} else if (op == UserOperation.BanPerson) {
.filter(c => c.creator.id == data.person_view.person.id)
.forEach(c => (c.creator.banned = data.banned));
- let postRes = this.state.postRes;
- if (postRes) {
- if (postRes.post_view.creator.id == data.person_view.person.id) {
- postRes.post_view.creator.banned = data.banned;
+ let res = this.state.postRes;
+ if (res) {
+ if (res.post_view.creator.id == data.person_view.person.id) {
+ res.post_view.creator.banned = data.banned;
}
}
this.setState(this.state);
} else if (op == UserOperation.Search) {
let data = wsJsonToRes<SearchResponse>(msg);
let xPosts = data.posts.filter(
- p => p.post.id != Number(this.props.match.params.id)
+ p => p.post.ap_id != this.state.postRes?.post_view.post.ap_id
);
this.setState({ crossPosts: xPosts.length > 0 ? xPosts : undefined });
} else if (op == UserOperation.LeaveAdmin) {
this.setState({ siteRes: data });
} else if (op == UserOperation.TransferCommunity) {
let data = wsJsonToRes<GetCommunityResponse>(msg);
- let postRes = this.state.postRes;
- if (postRes) {
- postRes.community_view = data.community_view;
- postRes.post_view.community = data.community_view.community;
- postRes.moderators = data.moderators;
+ let res = this.state.postRes;
+ if (res) {
+ res.community_view = data.community_view;
+ res.post_view.community = data.community_view.community;
+ res.moderators = data.moderators;
this.setState(this.state);
}
} else if (op == UserOperation.BlockPerson) {