From c65aa75ba0b88721b32541c6d2cc2acb2a641bcb Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 3 Jul 2020 17:26:17 +0300 Subject: fix: place like immediately not awaiting response --- src/components/PollCard/PollCard.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/components') 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 = ({ 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'); -- cgit v1.2.3