diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 15:35:34 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-29 15:35:34 +0300 |
commit | 0852cbeea6a3872c4a3a4b7dd974db53eb0a85dd (patch) | |
tree | ec37eb3635a44bd8654739f126fa8ba55cb759af | |
parent | 4037868a791c706c4d77d6353e396cb6454995be (diff) | |
download | which-ui-0852cbeea6a3872c4a3a4b7dd974db53eb0a85dd.tar.gz |
show new poll right after submit
-rw-r--r-- | src/pages/FeedPage/FeedPage.tsx | 2 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmission.tsx | 11 | ||||
-rw-r--r-- | src/pages/FeedPage/types.ts | 4 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx index afe2ef7..a7bbbbd 100644 --- a/src/pages/FeedPage/FeedPage.tsx +++ b/src/pages/FeedPage/FeedPage.tsx @@ -22,7 +22,7 @@ const FeedPage: React.FC<PropTypes> = ({ navigate, user }) => { return ( <> - {user && <PollSubmission user={user} />} + {user && <PollSubmission user={user} polls={polls} setPolls={setPolls}/>} <Feed polls={polls} navigate={navigate} /> </> ); diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx index 9a3a042..65e33b6 100644 --- a/src/pages/FeedPage/PollSubmission.tsx +++ b/src/pages/FeedPage/PollSubmission.tsx @@ -4,7 +4,7 @@ import Collapse from '@material-ui/core/Collapse'; import { Button, Card, CardMedia, ClickAwayListener, Divider } from '@material-ui/core'; -import { User } from 'which-types'; +import { User, Poll } from 'which-types'; import PollSubmissionImage from './PollSubmissionImage'; import UserStrip from '../../components/UserStrip/UserStrip'; import { post } from '../../requests'; @@ -13,6 +13,8 @@ import { Contents } from './types'; interface PropTypes{ user: User; + polls: Poll[]; + setPolls: (a:Poll[])=> void; } const useStyles = makeStyles(theme => ({ root: { @@ -36,7 +38,7 @@ const useStyles = makeStyles(theme => ({ } })); -const PollSubmission: React.FC<PropTypes> = ({ user }) => { +const PollSubmission: React.FC<PropTypes> = ({ user , polls, setPolls}) => { const classes = useStyles(); const [expanded, setExpanded] = useState(false); const [contents, setContents] = useState<Contents>({ @@ -54,9 +56,10 @@ const PollSubmission: React.FC<PropTypes> = ({ user }) => { const handleClick = () => { if (expanded) { - if(contents.left?.url && contents.right?.url ) { + if(contents.left.url && contents.right.url ) { post('/polls/', {authorId: user._id, contents}).then(res => { - console.log(res.data); + polls.unshift({...res.data}); + setPolls([...polls]); }); } } diff --git a/src/pages/FeedPage/types.ts b/src/pages/FeedPage/types.ts index a3c95ff..24ace4e 100644 --- a/src/pages/FeedPage/types.ts +++ b/src/pages/FeedPage/types.ts @@ -2,6 +2,6 @@ export interface ImageData { url: string; } export interface Contents { - left?: ImageData; - right?: ImageData; + left: ImageData; + right: ImageData; } |