aboutsummaryrefslogtreecommitdiff
path: root/src/Feed/Feed.tsx
blob: d7bfce17e50fcd3b1c186aa51fcfa3d4b5d83977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 {
  page: string;
}

const useStyles = makeStyles(theme => ({
  root: {
    position: 'relative',
    maxWidth: theme.spacing(75),
    margin: '0 auto'
  }
}));

const Feed: React.FC<PropTypes> = ({ page }) => {
  const [polls, setPolls] = useState<Poll[]>([]);
  const classes = useStyles();

  let endpoint = '/polls';
  // TODO: Make this work
  if (page === 'feed') endpoint = '/polls';

  useEffect(() => {
    get(endpoint).then(response => {
      setPolls(response.data);
    });
  }, [endpoint]);

  return (
    <div className={classes.root}>
      {polls.map(poll => <PollCard poll={poll} key={poll._id} />)}
    </div>
  );
};

export default Feed;