From f586337f7819b16579c6a2c67f24bffe4614c2be Mon Sep 17 00:00:00 2001 From: hole-thu Date: Wed, 21 Sep 2022 17:17:41 +0800 Subject: [PATCH] fix: poll --- src/Flows.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Flows.js b/src/Flows.js index 039485c..dd684bd 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -927,22 +927,25 @@ class FlowItemRow extends PureComponent { if (ans.option === vote) ans.votes += 1; }); - this.setState({ - info: Object.assign({}, info, { poll: current_poll }), - }); - - API.add_vote(vote, info.pid, this.props.token) - .then((json) => { - if (json.code !== 0) return; - localStorage['VOTE_RECORD:' + info.pid] = vote; - this.setState((prev, props) => ({ - info: Object.assign({}, prev.info, { poll: json.data }), - })); - }) - .catch((e) => { - console.error(e); - alert('投票失败'); - }); + this.setState( + { + info: Object.assign({}, info, { poll: current_poll }), + }, + () => { + API.add_vote(vote, info.pid, this.props.token) + .then((json) => { + if (json.code !== 0) return; + localStorage['VOTE_RECORD:' + info.pid] = vote; + this.setState((prev, props) => ({ + info: Object.assign({}, prev.info, { poll: json.data }), + })); + }) + .catch((e) => { + console.error(e); + alert('投票失败'); + }); + }, + ); } load_replies(callback, update_count = true) {