aboutsummaryrefslogtreecommitdiff
path: root/src/components/PollCard/PollCard.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-10 11:12:06 +0300
committereug-vs <eug-vs@keemail.me>2020-08-10 11:12:06 +0300
commitcab8de5c6b246e1aa1376fa2b8666f09b44b6469 (patch)
tree5e6c1105455bf3aadd1b987680a2814d8ce6ef07 /src/components/PollCard/PollCard.tsx
parent08e9e3abb9830b6c46f46aacb6a40ba32c4c665f (diff)
downloadwhich-ui-cab8de5c6b246e1aa1376fa2b8666f09b44b6469.tar.gz
refator: Feed -> PollList
Diffstat (limited to 'src/components/PollCard/PollCard.tsx')
-rw-r--r--src/components/PollCard/PollCard.tsx18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 2378945..689e872 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import {
Card,
@@ -14,7 +14,8 @@ import { post } from '../../requests';
import { useAuth } from '../../hooks/useAuth';
interface PropTypes {
- initialPoll: Poll;
+ poll: Poll;
+ setPoll: (poll: Poll) => void;
}
const DATE_FORMAT = {
@@ -49,8 +50,7 @@ const useStyles = makeStyles(theme => ({
}
}));
-const PollCard: React.FC<PropTypes> = ({ initialPoll }) => {
- const [poll, setPoll] = useState<Poll>(initialPoll);
+const PollCard: React.FC<PropTypes> = ({ poll, setPoll }) => {
const classes = useStyles();
const { author, contents: { left, right }, vote } = poll;
const { enqueueSnackbar } = useSnackbar();
@@ -68,15 +68,17 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll }) => {
});
} else {
const newVote = ({ which, pollId: poll._id });
- post('votes/', newVote);
- poll.contents[which].votes += 1;
- poll.vote = {
+ const newPoll = { ...poll };
+ newPoll.contents[which].votes += 1;
+ newPoll.vote = {
_id: '',
authorId: '',
createdAt: new Date(),
...newVote
};
- setPoll({ ...poll });
+ setPoll(newPoll);
+
+ post('votes/', newVote);
}
};