diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-10 20:14:46 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-10 20:14:46 +0300 |
commit | e92ebe01e3a33dcc75b5e5ffd8d29933a2cf17df (patch) | |
tree | b2e42abf21addfcfb0e25e87dcf253105c340427 /src/Feed | |
parent | 8b4f8e55962690145834866edd64d45b87b3a545 (diff) | |
download | which-ui-e92ebe01e3a33dcc75b5e5ffd8d29933a2cf17df.tar.gz |
feat: integrate Feed component with backend
Diffstat (limited to 'src/Feed')
-rw-r--r-- | src/Feed/Feed.tsx | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/Feed/Feed.tsx b/src/Feed/Feed.tsx index 33e6d03..51a3c4c 100644 --- a/src/Feed/Feed.tsx +++ b/src/Feed/Feed.tsx @@ -1,30 +1,41 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Poll } from '../types'; import PollCard from '../PollCard/PollCard'; +import { get } from '../requests'; interface PropTypes { - polls: Poll[], + page: string; } -const usedStyles = makeStyles(theme => ({ - feed: { +const useStyles = makeStyles(theme => ({ + root: { position: 'relative', maxWidth: theme.spacing(75), margin: '0 auto' } })); -const Feed: React.FC<PropTypes> = ({ polls }) => { - const classes = usedStyles(); +const Feed: React.FC<PropTypes> = ({ page }) => { + const [polls, setPolls] = useState<Poll[]>([]); + const classes = useStyles(); + + let endpoint: string; + if (page === 'feed') endpoint = '/polls'; + else if (page === 'profile') endpoint = '/profile'; + + useEffect(() => { + get(endpoint).then(response => { + setPolls(response.data); + }); + }, []); return ( - <div className={classes.feed}> - { - polls.map(poll => <PollCard poll={poll} />) - } + <div className={classes.root}> + {polls.map(poll => <PollCard poll={poll} />)} </div> ); }; export default Feed; + |