From f9999d6da7752a55ad01f85dce34086c1acbff5a Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Wed, 1 Jul 2020 15:26:08 +0300 Subject: move snack provider to Page component --- src/components/PollCard/PollCard.tsx | 11 +++-------- src/index.tsx | 29 ++++++++++------------------- src/pages/FeedPage/PollSubmission.tsx | 11 +++-------- src/pages/Page.tsx | 19 ++++++++++++++----- 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index ef7391e..12f7198 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -60,16 +60,11 @@ const PollCard: React.FC = ({ initialPoll }) => { const { enqueueSnackbar } = useSnackbar(); const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT); - - const showSnackBar = (message: string) => { - enqueueSnackbar(message, { - variant: 'error' - }); - }; - const handleVote = (which: Which) => { if (vote) { - showSnackBar('You have already voted'); + enqueueSnackbar('You have already voted', { + variant: 'error' + }); return; } post('votes/', { which, pollId: poll._id }).then(response => { diff --git a/src/index.tsx b/src/index.tsx index 0ab06f5..e8fbce1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,7 +5,6 @@ import { CssBaseline } from '@material-ui/core'; import teal from '@material-ui/core/colors/teal'; import 'typeface-roboto'; -import { SnackbarProvider } from 'notistack'; import Header from './components/Header/Header'; import ScrollTopArrow from './components/ScrollTopArrow/ScrollTopArrow'; import Page from './pages/Page'; @@ -24,24 +23,16 @@ const theme = createMuiTheme({ const App: React.FC = () => { return ( - - - - - -
- - - - - - + + + + +
+ + + + + ); }; diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx index 3088279..b067914 100644 --- a/src/pages/FeedPage/PollSubmission.tsx +++ b/src/pages/FeedPage/PollSubmission.tsx @@ -48,18 +48,13 @@ const PollSubmission: React.FC = ({ addPoll }) => { setExpanded(false); }; - const showSnackBar = (message: string) => { - enqueueSnackbar(message, { - variant: 'success' - }); - }; - - const handleClick = () => { if (expanded && readyToSubmit) { post('/polls/', { contents }).then(response => { addPoll(response.data); - showSnackBar('Your poll has been successfully created!'); + enqueueSnackbar('Your poll has been successfully created!', { + variant: 'success' + }); }); setContents({ ...emptyContents }); } diff --git a/src/pages/Page.tsx b/src/pages/Page.tsx index 6d4315e..f6353b2 100644 --- a/src/pages/Page.tsx +++ b/src/pages/Page.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; +import { SnackbarProvider } from 'notistack'; import ProfilePage from './ProfilePage/ProfilePage'; import FeedPage from './FeedPage/FeedPage'; import AuthPage from './AuthPage/AuthPage'; @@ -18,11 +19,19 @@ const Page: React.FC = () => { const classes = useStyles(); return ( -
- { page.prefix === 'profile' && } - { page.prefix === 'feed' && } - { page.prefix === 'auth' && } -
+ +
+ { page.prefix === 'profile' && } + { page.prefix === 'feed' && } + { page.prefix === 'auth' && } +
+
); }; -- cgit v1.2.3