diff options
author | Dessalines <tyhou13@gmx.com> | 2020-02-08 23:20:11 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-02-08 23:20:11 -0500 |
commit | 56cd103209605471b27aa5a854cc3b051f2a65f5 (patch) | |
tree | 704e96abe61a6481fe9243b4b4d33271f785e960 /ui/src/components/main.tsx | |
parent | 8baa483c8907945921d962be9b34cad824c2e294 (diff) |
Fixing some technical debt. Fixes #524
Diffstat (limited to 'ui/src/components/main.tsx')
-rw-r--r-- | ui/src/components/main.tsx | 71 |
1 files changed, 19 insertions, 52 deletions
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 92434360..99b1618d 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -45,6 +45,12 @@ import { getPageFromProps, getSortTypeFromProps, getDataTypeFromProps, + editCommentRes, + saveCommentRes, + createCommentLikeRes, + createPostLikeFindRes, + editPostFindRes, + commentsToFlatNodes, } from '../utils'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -400,17 +406,11 @@ export class Main extends Component<any, MainState> { return this.state.dataType == DataType.Post ? ( <PostListings posts={this.state.posts} showCommunity removeDuplicates /> ) : ( - this.state.comments.map(comment => ( - <div class="row"> - <div class="col-12"> - <CommentNodes - nodes={[{ comment: comment }]} - noIndent - showCommunity - /> - </div> - </div> - )) + <CommentNodes + nodes={commentsToFlatNodes(this.state.comments)} + noIndent + showCommunity + /> ); } @@ -625,28 +625,12 @@ export class Main extends Component<any, MainState> { this.setState(this.state); } else if (res.op == UserOperation.EditPost) { let data = res.data as PostResponse; - let found = this.state.posts.find(c => c.id == data.post.id); - if (found) { - found.url = data.post.url; - found.name = data.post.name; - found.nsfw = data.post.nsfw; - - this.setState(this.state); - } + editPostFindRes(data, this.state.posts); + 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); - if (found) { - found.score = data.post.score; - found.upvotes = data.post.upvotes; - found.downvotes = data.post.downvotes; - if (data.post.my_vote !== null) { - found.my_vote = data.post.my_vote; - found.upvoteLoading = false; - found.downvoteLoading = false; - } - this.setState(this.state); - } + createPostLikeFindRes(data, this.state.posts); + this.setState(this.state); } else if (res.op == UserOperation.AddAdmin) { let data = res.data as AddAdminResponse; this.state.siteRes.admins = data.admins; @@ -676,18 +660,8 @@ export class Main extends Component<any, MainState> { 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; @@ -709,18 +683,11 @@ export class Main extends Component<any, MainState> { } } 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); } } |