aboutsummaryrefslogtreecommitdiff
path: root/src/pages/FeedPage
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/FeedPage')
-rw-r--r--src/pages/FeedPage/FeedPage.tsx15
-rw-r--r--src/pages/FeedPage/PollSubmission.tsx11
-rw-r--r--src/pages/FeedPage/PollSubmissionImage.tsx2
3 files changed, 13 insertions, 15 deletions
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx
index 0017275..d29103a 100644
--- a/src/pages/FeedPage/FeedPage.tsx
+++ b/src/pages/FeedPage/FeedPage.tsx
@@ -1,18 +1,15 @@
import React, { useState, useEffect } from 'react';
-import { Poll, User } from 'which-types';
+import { Poll } 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;
- user: User | undefined;
-}
-
-const FeedPage: React.FC<PropTypes> = ({ navigate, user }) => {
+const FeedPage: React.FC = () => {
const [polls, setPolls] = useState<Poll[]>([]);
+ const { isAuthenticated } = useAuth();
useEffect(() => {
get('/feed').then(response => {
@@ -28,8 +25,8 @@ const FeedPage: React.FC<PropTypes> = ({ navigate, user }) => {
return (
<>
- {user && <PollSubmission user={user} addPoll={addPoll} />}
- <Feed polls={polls} navigate={navigate} />
+ {isAuthenticated() && <PollSubmission addPoll={addPoll} />}
+ <Feed polls={polls} />
</>
);
};
diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx
index 16c8350..18f029c 100644
--- a/src/pages/FeedPage/PollSubmission.tsx
+++ b/src/pages/FeedPage/PollSubmission.tsx
@@ -7,14 +7,14 @@ import {
ClickAwayListener,
Divider
} from '@material-ui/core';
-import { User, Poll, Which } from 'which-types';
+import { Poll, Which } from 'which-types';
import PollSubmissionImage from './PollSubmissionImage';
import UserStrip from '../../components/UserStrip/UserStrip';
import { post } from '../../requests';
import { Contents } from './types';
+import { useAuth } from '../../hooks/useAuth';
interface PropTypes{
- user: User;
addPoll: (poll: Poll) => void;
}
@@ -30,10 +30,11 @@ const emptyContents: Contents = {
right: { url: '' }
};
-const PollSubmission: React.FC<PropTypes> = ({ user, addPoll }) => {
+const PollSubmission: React.FC<PropTypes> = ({ addPoll }) => {
const classes = useStyles();
const [expanded, setExpanded] = useState(false);
const [contents, setContents] = useState<Contents>(emptyContents);
+ const { user } = useAuth();
const readyToSubmit = contents.left.url && contents.right.url;
@@ -47,7 +48,7 @@ const PollSubmission: React.FC<PropTypes> = ({ user, addPoll }) => {
const handleClick = () => {
if (expanded && readyToSubmit) {
- post('/polls/', { authorId: user._id, contents }).then(response => {
+ post('/polls/', { contents }).then(response => {
addPoll(response.data);
});
setContents({ ...emptyContents });
@@ -59,7 +60,7 @@ const PollSubmission: React.FC<PropTypes> = ({ user, addPoll }) => {
<ClickAwayListener onClickAway={handleClickAway}>
<Card>
<Collapse in={expanded} timeout="auto" unmountOnExit>
- <UserStrip user={user} info="" navigate={() => {}} />
+ {user && <UserStrip user={user} info="" />}
<Divider />
<div className={classes.root}>
<PollSubmissionImage url={contents.left.url} setUrl={setUrl('left')} />
diff --git a/src/pages/FeedPage/PollSubmissionImage.tsx b/src/pages/FeedPage/PollSubmissionImage.tsx
index 8d82d45..e2ffad3 100644
--- a/src/pages/FeedPage/PollSubmissionImage.tsx
+++ b/src/pages/FeedPage/PollSubmissionImage.tsx
@@ -41,7 +41,7 @@ const PollSubmissionImage: React.FC<PropTypes> = ({ url, setUrl }) => {
if (!isModalOpen) {
if (url) setUrl('');
else setIsModalOpen(!isModalOpen);
- };
+ }
};
const handleMouseEnter = (): void => {