From 1f646377c35b65b97d6eeebb1e88f6d8307e1ef0 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 29 Jun 2020 23:59:15 +0300 Subject: feat!: create useAuth hook --- src/pages/FeedPage/FeedPage.tsx | 7 ++++--- src/pages/FeedPage/PollSubmission.tsx | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/pages/FeedPage') diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx index 0017275..6561991 100644 --- a/src/pages/FeedPage/FeedPage.tsx +++ b/src/pages/FeedPage/FeedPage.tsx @@ -4,15 +4,16 @@ 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; - user: User | undefined; } -const FeedPage: React.FC = ({ navigate, user }) => { +const FeedPage: React.FC = ({ navigate }) => { const [polls, setPolls] = useState([]); + const { isAuthenticated } = useAuth(); useEffect(() => { get('/feed').then(response => { @@ -28,7 +29,7 @@ const FeedPage: React.FC = ({ navigate, user }) => { return ( <> - {user && } + {isAuthenticated() && } ); diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx index 16c8350..4e06254 100644 --- a/src/pages/FeedPage/PollSubmission.tsx +++ b/src/pages/FeedPage/PollSubmission.tsx @@ -12,9 +12,9 @@ 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 = ({ user, addPoll }) => { +const PollSubmission: React.FC = ({ addPoll }) => { const classes = useStyles(); const [expanded, setExpanded] = useState(false); const [contents, setContents] = useState(emptyContents); + const { user } = useAuth(); const readyToSubmit = contents.left.url && contents.right.url; @@ -47,7 +48,7 @@ const PollSubmission: React.FC = ({ 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 = ({ user, addPoll }) => { - {}} /> + {user && {}} />}
-- cgit v1.2.3