diff options
author | Dessalines <tyhou13@gmx.com> | 2020-01-23 19:17:42 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-01-23 19:17:42 -0500 |
commit | ac1d5f2b86b0816cc9b5794dc6c38a38365ed839 (patch) | |
tree | bedaab04ca797113990e5702cad36f5e34e9e6e8 /ui/src/components/search.tsx | |
parent | 39d1fb4450cb418d9c11b31ea99484c2a177fab6 (diff) | |
parent | b45c83682c187737b092080e83ba741c39cfa695 (diff) |
Done merging http-api and private_message
Diffstat (limited to 'ui/src/components/search.tsx')
-rw-r--r-- | ui/src/components/search.tsx | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index d2280cb2..18b5d341 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -14,10 +14,11 @@ import { SearchType, CreatePostLikeResponse, CommentResponse, + WebSocketJsonResponse, } from '../interfaces'; import { WebSocketService } from '../services'; import { - msgOp, + wsJsonToRes, fetchLimit, routeSearchTypeToEnum, routeSortTypeToEnum, @@ -48,7 +49,6 @@ export class Search extends Component<any, SearchState> { sort: this.getSortTypeFromProps(this.props), page: this.getPageFromProps(this.props), searchResponse: { - op: null, type_: null, posts: [], comments: [], @@ -401,7 +401,6 @@ export class Search extends Component<any, SearchState> { return ( <div> {res && - res.op && res.posts.length == 0 && res.comments.length == 0 && res.communities.length == 0 && @@ -477,44 +476,44 @@ export class Search extends Component<any, SearchState> { ); } - parseMessage(msg: any) { + parseMessage(msg: WebSocketJsonResponse) { console.log(msg); - let op: UserOperation = msgOp(msg); - if (msg.error) { + let res = wsJsonToRes(msg); + if (res.error) { toast(i18n.t(msg.error), 'danger'); return; - } else if (op == UserOperation.Search) { - let res: SearchResponse = msg; - this.state.searchResponse = res; + } else if (res.op == UserOperation.Search) { + let data = res.data as SearchResponse; + this.state.searchResponse = data; this.state.loading = false; document.title = `${i18n.t('search')} - ${this.state.q} - ${ WebSocketService.Instance.site.name }`; window.scrollTo(0, 0); this.setState(this.state); - } else if (op == UserOperation.CreateCommentLike) { - let res: CommentResponse = msg; + } else if (res.op == UserOperation.CreateCommentLike) { + let data = res.data as CommentResponse; let found: Comment = this.state.searchResponse.comments.find( - c => c.id === res.comment.id + c => c.id === data.comment.id ); - found.score = res.comment.score; - found.upvotes = res.comment.upvotes; - found.downvotes = res.comment.downvotes; - if (res.comment.my_vote !== null) { - found.my_vote = res.comment.my_vote; + 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; } this.setState(this.state); - } else if (op == UserOperation.CreatePostLike) { - let res: CreatePostLikeResponse = msg; + } else if (res.op == UserOperation.CreatePostLike) { + let data = res.data as CreatePostLikeResponse; let found = this.state.searchResponse.posts.find( - c => c.id == res.post.id + c => c.id == data.post.id ); - found.my_vote = res.post.my_vote; - found.score = res.post.score; - found.upvotes = res.post.upvotes; - found.downvotes = res.post.downvotes; + found.my_vote = data.post.my_vote; + found.score = data.post.score; + found.upvotes = data.post.upvotes; + found.downvotes = data.post.downvotes; this.setState(this.state); } } |