aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-07-03 17:26:17 +0300
committereug-vs <eug-vs@keemail.me>2020-07-03 17:29:56 +0300
commitc65aa75ba0b88721b32541c6d2cc2acb2a641bcb (patch)
tree2adab17fc75db78037d8bc6949568692ef10007a /src/components
parent2e7f7610169391c78d852caea73190e5d8c0b978 (diff)
downloadwhich-ui-c65aa75ba0b88721b32541c6d2cc2acb2a641bcb.tar.gz
fix: place like immediately not awaiting response
Diffstat (limited to 'src/components')
-rw-r--r--src/components/PollCard/PollCard.tsx17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 12f7198..6cdd777 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -62,16 +62,21 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll }) => {
const handleVote = (which: Which) => {
if (vote) {
- enqueueSnackbar('You have already voted', {
+ enqueueSnackbar('You have already voted in this poll', {
variant: 'error'
});
- return;
- }
- post('votes/', { which, pollId: poll._id }).then(response => {
+ } else {
+ const newVote = ({ which, pollId: poll._id });
+ post('votes/', newVote);
poll.contents[which].votes += 1;
- poll.vote = response.data;
+ poll.vote = {
+ _id: '',
+ authorId: '',
+ createdAt: new Date(),
+ ...newVote
+ };
setPoll({ ...poll });
- });
+ }
};
const handleLeft = () => handleVote('left');