summaryrefslogtreecommitdiffstats
path: root/ui/src/components/user.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-02-08 23:20:11 -0500
committerDessalines <tyhou13@gmx.com>2020-02-08 23:20:11 -0500
commit56cd103209605471b27aa5a854cc3b051f2a65f5 (patch)
tree704e96abe61a6481fe9243b4b4d33271f785e960 /ui/src/components/user.tsx
parent8baa483c8907945921d962be9b34cad824c2e294 (diff)
Fixing some technical debt. Fixes #524
Diffstat (limited to 'ui/src/components/user.tsx')
-rw-r--r--ui/src/components/user.tsx48
1 files changed, 15 insertions, 33 deletions
diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx
index effc9e1d..e2df15e1 100644
--- a/ui/src/components/user.tsx
+++ b/ui/src/components/user.tsx
@@ -32,6 +32,11 @@ import {
languages,
showAvatars,
toast,
+ editCommentRes,
+ saveCommentRes,
+ createCommentLikeRes,
+ createPostLikeFindRes,
+ commentsToFlatNodes,
} from '../utils';
import { PostListing } from './post-listing';
import { SortSelect } from './sort-select';
@@ -316,13 +321,11 @@ export class User extends Component<any, UserState> {
comments() {
return (
<div>
- {this.state.comments.map(comment => (
- <CommentNodes
- nodes={[{ comment: comment }]}
- admins={this.state.admins}
- noIndent
- />
- ))}
+ <CommentNodes
+ nodes={commentsToFlatNodes(this.state.comments)}
+ admins={this.state.admins}
+ noIndent
+ />
</div>
);
}
@@ -1032,18 +1035,8 @@ export class User extends Component<any, UserState> {
this.setState(this.state);
} else if (res.op == UserOperation.EditComment) {
let data = res.data as CommentResponse;
-
- let found = this.state.comments.find(c => c.id == data.comment.id);
- if (found) {
- found.content = data.comment.content;
- found.updated = data.comment.updated;
- found.removed = data.comment.removed;
- found.deleted = data.comment.deleted;
- found.upvotes = data.comment.upvotes;
- found.downvotes = data.comment.downvotes;
- found.score = data.comment.score;
- this.setState(this.state);
- }
+ editCommentRes(data, this.state.comments);
+ this.setState(this.state);
} else if (res.op == UserOperation.CreateComment) {
let data = res.data as CommentResponse;
if (
@@ -1054,26 +1047,15 @@ export class User extends Component<any, UserState> {
}
} else if (res.op == UserOperation.SaveComment) {
let data = res.data as CommentResponse;
- let found = this.state.comments.find(c => c.id == data.comment.id);
- found.saved = data.comment.saved;
+ saveCommentRes(data, this.state.comments);
this.setState(this.state);
} else if (res.op == UserOperation.CreateCommentLike) {
let data = res.data as CommentResponse;
- let found: Comment = this.state.comments.find(
- c => c.id === data.comment.id
- );
- found.score = data.comment.score;
- found.upvotes = data.comment.upvotes;
- found.downvotes = data.comment.downvotes;
- if (data.comment.my_vote !== null) found.my_vote = data.comment.my_vote;
+ createCommentLikeRes(data, this.state.comments);
this.setState(this.state);
} else if (res.op == UserOperation.CreatePostLike) {
let data = res.data as PostResponse;
- let found = this.state.posts.find(c => c.id == data.post.id);
- found.my_vote = data.post.my_vote;
- found.score = data.post.score;
- found.upvotes = data.post.upvotes;
- found.downvotes = data.post.downvotes;
+ createPostLikeFindRes(data, this.state.posts);
this.setState(this.state);
} else if (res.op == UserOperation.BanUser) {
let data = res.data as BanUserResponse;