diff options
author | ilyayudovin <46264063+ilyayudovin@users.noreply.github.com> | 2020-06-11 04:25:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-11 04:25:24 +0300 |
commit | f0f192e09993eedc2c9596bcdb520a96f5cfacdb (patch) | |
tree | b94e8c0841521a50628574899f9a7ad5f5c7cf0c /src/Feed | |
parent | 9473f8836bc65d1e0ea87607def54b86d719bbc8 (diff) | |
parent | b85725ec0fd5088a619a20d2a6370b1f4a38cc22 (diff) | |
download | which-ui-f0f192e09993eedc2c9596bcdb520a96f5cfacdb.tar.gz |
Merge pull request #24 from ilyayudovin/requests
Configure requests and integrate Feed component
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; + |