summaryrefslogtreecommitdiffstats
path: root/ui/src/components/search.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/search.tsx
parent8baa483c8907945921d962be9b34cad824c2e294 (diff)
Fixing some technical debt. Fixes #524
Diffstat (limited to 'ui/src/components/search.tsx')
-rw-r--r--ui/src/components/search.tsx37
1 files changed, 10 insertions, 27 deletions
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx
index 3acb7167..3fd2f467 100644
--- a/ui/src/components/search.tsx
+++ b/ui/src/components/search.tsx
@@ -25,6 +25,9 @@ import {
pictshareAvatarThumbnail,
showAvatars,
toast,
+ createCommentLikeRes,
+ createPostLikeFindRes,
+ commentsToFlatNodes,
} from '../utils';
import { PostListing } from './post-listing';
import { SortSelect } from './sort-select';
@@ -294,15 +297,11 @@ export class Search extends Component<any, SearchState> {
comments() {
return (
- <>
- {this.state.searchResponse.comments.map(comment => (
- <div class="row">
- <div class="col-12">
- <CommentNodes nodes={[{ comment: comment }]} locked noIndent />
- </div>
- </div>
- ))}
- </>
+ <CommentNodes
+ nodes={commentsToFlatNodes(this.state.searchResponse.comments)}
+ locked
+ noIndent
+ />
);
}
@@ -474,27 +473,11 @@ export class Search extends Component<any, SearchState> {
this.setState(this.state);
} else if (res.op == UserOperation.CreateCommentLike) {
let data = res.data as CommentResponse;
- let found: Comment = this.state.searchResponse.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;
- found.upvoteLoading = false;
- found.downvoteLoading = false;
- }
+ createCommentLikeRes(data, this.state.searchResponse.comments);
this.setState(this.state);
} else if (res.op == UserOperation.CreatePostLike) {
let data = res.data as PostResponse;
- let found = this.state.searchResponse.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.searchResponse.posts);
this.setState(this.state);
}
}