diff options
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 11 | ||||
-rw-r--r-- | src/index.tsx | 29 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmission.tsx | 11 | ||||
-rw-r--r-- | 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<PropTypes> = ({ 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 ( - <SnackbarProvider - maxSnack={3} - anchorOrigin={{ - vertical: 'bottom', - horizontal: 'right' - }} - > - <NavigationProvider> - <AuthProvider> - <ThemeProvider theme={theme}> - <CssBaseline /> - <Header /> - <Page /> - <ScrollTopArrow /> - </ThemeProvider> - </AuthProvider> - </NavigationProvider> - </SnackbarProvider> + <NavigationProvider> + <AuthProvider> + <ThemeProvider theme={theme}> + <CssBaseline /> + <Header /> + <Page /> + <ScrollTopArrow /> + </ThemeProvider> + </AuthProvider> + </NavigationProvider> ); }; 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<PropTypes> = ({ 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 ( - <div className={classes.root}> - { page.prefix === 'profile' && <ProfilePage />} - { page.prefix === 'feed' && <FeedPage /> } - { page.prefix === 'auth' && <AuthPage /> } - </div> + <SnackbarProvider + maxSnack={3} + anchorOrigin={{ + vertical: 'bottom', + horizontal: 'right' + }} + > + <div className={classes.root}> + { page.prefix === 'profile' && <ProfilePage />} + { page.prefix === 'feed' && <FeedPage /> } + { page.prefix === 'auth' && <AuthPage /> } + </div> + </SnackbarProvider> ); }; |