blob: 65619913589347ec172c00fd4814f59c53556a08 (
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
|
import React, { useState, useEffect } from 'react';
import { Poll, User } from 'which-types';
import Feed from '../../components/Feed/Feed';
import { get } from '../../requests';
import PollSubmission from './PollSubmission';
import { useAuth } from '../../hooks/useAuth';
interface PropTypes {
navigate: (prefix: string, id: string) => void;
}
const FeedPage: React.FC<PropTypes> = ({ navigate }) => {
const [polls, setPolls] = useState<Poll[]>([]);
const { isAuthenticated } = useAuth();
useEffect(() => {
get('/feed').then(response => {
setPolls(response.data);
});
}, []);
const addPoll = (poll: Poll): void => {
polls.unshift(poll);
setPolls([...polls]);
};
return (
<>
{isAuthenticated() && <PollSubmission addPoll={addPoll} />}
<Feed polls={polls} navigate={navigate} />
</>
);
};
export default FeedPage;
|