Browse Source

预测投票后结果,优化投票操作流畅度

master
hole-thu 3 years ago
parent
commit
21ca1f0ba1
  1. 17
      src/Flows.js

17
src/Flows.js

@ -920,12 +920,21 @@ class FlowItemRow extends PureComponent {
// } // }
do_vote(vote) { 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) => { .then((json) => {
if (json.code !== 0) return; if (json.code !== 0) return;
localStorage['VOTE_RECORD:' + this.state.info.pid] = vote; localStorage['VOTE_RECORD:' + info.pid] = vote;
console.log('resp:', json.data);
console.log('prev info', this.state.info);
this.setState((prev, props) => ({ this.setState((prev, props) => ({
info: Object.assign({}, prev.info, { poll: json.data }), info: Object.assign({}, prev.info, { poll: json.data }),
})); }));

Loading…
Cancel
Save