From 21ca1f0ba11cad0c068a4075f0c3e3db555e5890 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Mon, 5 Sep 2022 21:40:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E6=B5=8B=E6=8A=95=E7=A5=A8=E5=90=8E?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8A=95=E7=A5=A8?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=B5=81=E7=95=85=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Flows.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Flows.js b/src/Flows.js index 6dfbcf5..039485c 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -920,12 +920,21 @@ class FlowItemRow extends PureComponent { // } do_vote(vote) { - API.add_vote(vote, this.state.info.pid, this.props.token) + const { info } = this.state; + let current_poll = info.poll; + current_poll.vote = vote; + current_poll.answers.forEach((ans) => { + 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:' + this.state.info.pid] = vote; - console.log('resp:', json.data); - console.log('prev info', this.state.info); + localStorage['VOTE_RECORD:' + info.pid] = vote; this.setState((prev, props) => ({ info: Object.assign({}, prev.info, { poll: json.data }), }));