From e5ffbb1b961dda45c1db9ff66c03a0d6ec3d5fe1 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sat, 26 May 2018 17:15:01 +0300 Subject: [PATCH] revert "remove requesting updated comment after voting" due to UI freezing --- web/app/components/comment/comment.jsx | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index 7dbc1d39..97aaf800 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -193,17 +193,19 @@ export default class Comment extends Component { if (scoreIncreased) return; - const newScore = score + 1; - this.setState({ scoreIncreased: !scoreDecreased, scoreDecreased: false, - score: newScore, + score: score + 1, }); - store.replaceComment(Object.assign({}, this.props.data, { score: newScore })); - - this.votingPromise = this.votingPromise.then(() => api.vote({ id, url, value: 1 })); + this.votingPromise = this.votingPromise + .then(() => { + return api.vote({ id, url, value: 1 }) + .then(() => { + api.getComment({ id }).then(comment => store.replaceComment(comment)); + }); + }); } decreaseScore() { @@ -212,17 +214,19 @@ export default class Comment extends Component { if (scoreDecreased) return; - const newScore = score - 1; - this.setState({ scoreDecreased: !scoreIncreased, scoreIncreased: false, - score: newScore, + score: score - 1, }); - store.replaceComment(Object.assign({}, this.props.data, { score: newScore })); - - this.votingPromise = this.votingPromise.then(() => api.vote({ id, url, value: -1 })); + this.votingPromise = this.votingPromise + .then(() => { + return api.vote({ id, url, value: -1 }) + .then(() => { + api.getComment({ id }).then(comment => store.replaceComment(comment)); + }); + }); } onReply(...rest) {