@selfcommunity/react-ui 0.7.0-alpha.353 → 0.7.0-alpha.354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,17 +79,14 @@ function PollObject(props) {
79
79
  setVotes((prevVotes) => prevVotes + 1);
80
80
  }
81
81
  else {
82
- let isVoted = false;
83
82
  setChoices((prevChoices) => {
84
- return prevChoices.map((choice) => {
85
- isVoted = isVoted || choice.voted;
86
- return Object.assign({}, choice, {
87
- voted: choice.id === id ? true : false,
88
- vote_count: choice.id === id ? choice.vote_count + 1 : choice.vote_count > 0 && choice.voted ? choice.vote_count - 1 : choice.vote_count
89
- });
83
+ const updatedChoices = prevChoices.map((choice) => {
84
+ return Object.assign(Object.assign({}, choice), { voted: choice.id === id, vote_count: choice.id === id ? choice.vote_count + 1 : choice.vote_count > 0 && choice.voted ? choice.vote_count - 1 : choice.vote_count });
90
85
  });
86
+ const newVotes = updatedChoices.reduce((totalVotes, choice) => totalVotes + choice.vote_count, 0);
87
+ setVotes(newVotes);
88
+ return updatedChoices;
91
89
  });
92
- !isVoted && setVotes((prevVotes) => prevVotes + 1);
93
90
  }
94
91
  };
95
92
  /**
@@ -77,17 +77,14 @@ export default function PollObject(props) {
77
77
  setVotes((prevVotes) => prevVotes + 1);
78
78
  }
79
79
  else {
80
- let isVoted = false;
81
80
  setChoices((prevChoices) => {
82
- return prevChoices.map((choice) => {
83
- isVoted = isVoted || choice.voted;
84
- return Object.assign({}, choice, {
85
- voted: choice.id === id ? true : false,
86
- vote_count: choice.id === id ? choice.vote_count + 1 : choice.vote_count > 0 && choice.voted ? choice.vote_count - 1 : choice.vote_count
87
- });
81
+ const updatedChoices = prevChoices.map((choice) => {
82
+ return Object.assign(Object.assign({}, choice), { voted: choice.id === id, vote_count: choice.id === id ? choice.vote_count + 1 : choice.vote_count > 0 && choice.voted ? choice.vote_count - 1 : choice.vote_count });
88
83
  });
84
+ const newVotes = updatedChoices.reduce((totalVotes, choice) => totalVotes + choice.vote_count, 0);
85
+ setVotes(newVotes);
86
+ return updatedChoices;
89
87
  });
90
- !isVoted && setVotes((prevVotes) => prevVotes + 1);
91
88
  }
92
89
  };
93
90
  /**