diff options
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/FeedPage/FeedPage.tsx | 10 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmission.tsx | 12 | ||||
-rw-r--r-- | src/pages/FeedPage/PollSubmissionImage.tsx | 5 | ||||
-rw-r--r-- | src/pages/HomePage/HomePage.tsx | 144 | ||||
-rw-r--r-- | src/pages/NotificationsPage/NotificationsPage.tsx | 23 | ||||
-rw-r--r-- | src/pages/Page.tsx | 39 | ||||
-rw-r--r-- | src/pages/ProfilePage/ProfilePage.tsx | 6 |
7 files changed, 220 insertions, 19 deletions
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx index d29103a..0b7d44a 100644 --- a/src/pages/FeedPage/FeedPage.tsx +++ b/src/pages/FeedPage/FeedPage.tsx @@ -1,12 +1,12 @@ import React, { useState, useEffect } from 'react'; import { Poll } from 'which-types'; +import { Container } from '@material-ui/core/'; import Feed from '../../components/Feed/Feed'; import { get } from '../../requests'; import PollSubmission from './PollSubmission'; import { useAuth } from '../../hooks/useAuth'; - const FeedPage: React.FC = () => { const [polls, setPolls] = useState<Poll[]>([]); const { isAuthenticated } = useAuth(); @@ -19,15 +19,15 @@ const FeedPage: React.FC = () => { const addPoll = (poll: Poll): void => { polls.unshift(poll); - setPolls([...polls]); + setPolls([]); + setPolls(polls); }; - return ( - <> + <Container maxWidth="sm" disableGutters> {isAuthenticated() && <PollSubmission addPoll={addPoll} />} <Feed polls={polls} /> - </> + </Container> ); }; diff --git a/src/pages/FeedPage/PollSubmission.tsx b/src/pages/FeedPage/PollSubmission.tsx index 18f029c..347eecc 100644 --- a/src/pages/FeedPage/PollSubmission.tsx +++ b/src/pages/FeedPage/PollSubmission.tsx @@ -8,6 +8,7 @@ import { Divider } from '@material-ui/core'; import { Poll, Which } from 'which-types'; +import { useSnackbar } from 'notistack'; import PollSubmissionImage from './PollSubmissionImage'; import UserStrip from '../../components/UserStrip/UserStrip'; import { post } from '../../requests'; @@ -20,6 +21,9 @@ interface PropTypes{ const useStyles = makeStyles(theme => ({ root: { + marginBottom: theme.spacing(4) + }, + images: { height: theme.spacing(50), display: 'flex' } @@ -34,6 +38,7 @@ const PollSubmission: React.FC<PropTypes> = ({ addPoll }) => { const classes = useStyles(); const [expanded, setExpanded] = useState(false); const [contents, setContents] = useState<Contents>(emptyContents); + const { enqueueSnackbar } = useSnackbar(); const { user } = useAuth(); const readyToSubmit = contents.left.url && contents.right.url; @@ -50,6 +55,9 @@ const PollSubmission: React.FC<PropTypes> = ({ addPoll }) => { if (expanded && readyToSubmit) { post('/polls/', { contents }).then(response => { addPoll(response.data); + enqueueSnackbar('Your poll has been successfully created!', { + variant: 'success' + }); }); setContents({ ...emptyContents }); } @@ -58,11 +66,11 @@ const PollSubmission: React.FC<PropTypes> = ({ addPoll }) => { return ( <ClickAwayListener onClickAway={handleClickAway}> - <Card> + <Card className={classes.root}> <Collapse in={expanded} timeout="auto" unmountOnExit> {user && <UserStrip user={user} info="" />} <Divider /> - <div className={classes.root}> + <div className={classes.images}> <PollSubmissionImage url={contents.left.url} setUrl={setUrl('left')} /> <PollSubmissionImage url={contents.right.url} setUrl={setUrl('right')} /> </div> diff --git a/src/pages/FeedPage/PollSubmissionImage.tsx b/src/pages/FeedPage/PollSubmissionImage.tsx index a8ec437..8835989 100644 --- a/src/pages/FeedPage/PollSubmissionImage.tsx +++ b/src/pages/FeedPage/PollSubmissionImage.tsx @@ -28,6 +28,9 @@ const useStyles = makeStyles({ display: 'flex', justifyContent: 'center', alignItems: 'center' + }, + text: { + textAlign: 'center' } }); @@ -56,7 +59,7 @@ const PollSubmissionImage: React.FC<PropTypes> = ({ url, setUrl }) => { const Upload = ( <> <CloudUploadIcon fontSize="large" color="primary" /> - <Typography variant="h5"> Upload an image </Typography> + <Typography variant="h5" className={classes.text}> Upload an image </Typography> </> ); diff --git a/src/pages/HomePage/HomePage.tsx b/src/pages/HomePage/HomePage.tsx new file mode 100644 index 0000000..f00289a --- /dev/null +++ b/src/pages/HomePage/HomePage.tsx @@ -0,0 +1,144 @@ +import React, { useState, useEffect } from 'react'; +import { + Typography, + Divider, + Grid, + Button, + Link +} from '@material-ui/core/'; +import { makeStyles } from '@material-ui/core/styles'; +import TrendingUpIcon from '@material-ui/icons/TrendingUp'; +import { Rating } from '@material-ui/lab'; +import { Feedback } from 'which-types'; + +import { useNavigate } from '../../hooks/useNavigate'; +import { useAuth } from '../../hooks/useAuth'; +import { get } from '../../requests'; + +const useStyles = makeStyles(theme => ({ + root: { + overflow: 'hidden', + padding: theme.spacing(0, 2) + }, + logo: { + width: theme.spacing(20), + height: theme.spacing(20) + }, + score: { + fontWeight: 'bold' + }, + signup: { + marginLeft: theme.spacing(2) + } +})); + +const HomePage: React.FC = () => { + const [feedbacks, setFeedbacks] = useState<Feedback[]>([]); + const classes = useStyles(); + const { navigate } = useNavigate(); + const { isAuthenticated } = useAuth(); + + const rating = feedbacks.length && feedbacks.reduce( + (acc: number, feedback: Feedback) => acc + feedback.score, + 0 + ) / feedbacks.length; + + useEffect(() => { + get('/feedback').then(response => { + setFeedbacks(response.data); + }); + }, []); + + const handleLetsGo = () => { + navigate('feed'); + }; + + const handleSignUp = () => { + navigate('auth'); + }; + + const GithubLink = <Link href="https://github.com/which-ecosystem">GitHub</Link>; + const TypescriptLink = <Link href="https://www.typescriptlang.org/">Typescript</Link>; + const ReactLink = <Link href="https://reactjs.org/">React</Link>; + const FeathersLink = <Link href="https://feathersjs.com">Feathers</Link>; + const MUILink = <Link href="https://material-ui.com">Material-UI</Link>; + + return ( + <div className={classes.root}> + <Grid container spacing={4}> + <Grid item xs={12} md={4}> + <Grid container direction="column" spacing={1} alignItems="center"> + <Grid item> + <img src={`${process.env.PUBLIC_URL}/which-logo-512.png`} alt="logo" className={classes.logo} /> + </Grid> + <Grid item> + <Rating value={rating} readOnly size="large" /> + </Grid> + <Grid item> + <Typography variant="h5" className={classes.score}> + User score: {rating.toFixed(1)} + </Typography> + </Grid> + </Grid> + </Grid> + <Grid item xs={12} md={5}> + <Grid container direction="column" spacing={6}> + <Grid item> + <Typography variant="h4"> Which one to choose? </Typography> + <Divider /> + <Typography> + <p> + Have you ever found yourself stuck between two options, not being able to choose any? + This is exactly the problem we are going to solve! + </p> + <p>Share your minor everyday uncertainties with the whole world and see what others think!</p> + <Button variant="contained" color="primary" size="large" onClick={handleLetsGo}> + {'let\'s go!'} + </Button> + {!isAuthenticated() && ( + <Button + variant="outlined" + color="primary" + size="large" + className={classes.signup} + onClick={handleSignUp} + > + sign up + </Button> + )} + </Typography> + </Grid> + <Grid item> + <Typography variant="h4"> About the project </Typography> + <Divider /> + <Typography> + <p> + The project is written in {TypescriptLink} and features {ReactLink}, {FeathersLink}, and {MUILink}. + It is currently open-source and you can visit our {GithubLink} (make sure to star our repositories)! + </p> + <p> + We encourage any developer to check it out. Feel free to open issues and create Pull Requests! + </p> + <p> + All the development process is being tracked on the KanBan board (thanks GitHub). + You can always check it to see what is the current state of the project. + </p> + <Button + variant="outlined" + color="primary" + startIcon={<TrendingUpIcon />} + href="https://github.com/orgs/which-ecosystem/projects/1" + > + track our progress + </Button> + </Typography> + </Grid> + </Grid> + </Grid> + </Grid> + </div> + ); +}; + +export default HomePage; + diff --git a/src/pages/NotificationsPage/NotificationsPage.tsx b/src/pages/NotificationsPage/NotificationsPage.tsx new file mode 100644 index 0000000..3c39ba3 --- /dev/null +++ b/src/pages/NotificationsPage/NotificationsPage.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import { Typography } from '@material-ui/core'; + +const useStyles = makeStyles(theme => ({ + root: { + marginTop: theme.spacing(40), + textAlign: 'center' + } +})); + +const NotificationsPage: React.FC = () => { + const classes = useStyles(); + + return ( + <Typography variant="h4" className={classes.root}> + Sorry, this page is being constructed yet. + </Typography> + ); +}; + +export default NotificationsPage; + diff --git a/src/pages/Page.tsx b/src/pages/Page.tsx index 6d4315e..56d7372 100644 --- a/src/pages/Page.tsx +++ b/src/pages/Page.tsx @@ -1,28 +1,49 @@ import React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import { makeStyles, useTheme } from '@material-ui/core/styles'; +import { useMediaQuery } from '@material-ui/core'; +import { SnackbarProvider } from 'notistack'; + import ProfilePage from './ProfilePage/ProfilePage'; import FeedPage from './FeedPage/FeedPage'; import AuthPage from './AuthPage/AuthPage'; +import HomePage from './HomePage/HomePage'; +import NotificationsPage from './NotificationsPage/NotificationsPage'; import { useNavigate } from '../hooks/useNavigate'; + const useStyles = makeStyles(theme => ({ root: { - width: theme.spacing(75), - marginTop: theme.spacing(15), - margin: '0 auto' + [theme.breakpoints.down('sm')]: { + margin: theme.spacing(2, 0, 12, 0) + }, + [theme.breakpoints.up('md')]: { + margin: theme.spacing(15, 5, 8, 5) + } } })); const Page: React.FC = () => { const { page } = useNavigate(); const classes = useStyles(); + const theme = useTheme(); + const isMobile = useMediaQuery(theme.breakpoints.down('sm')); return ( - <div className={classes.root}> - { page.prefix === 'profile' && <ProfilePage />} - { page.prefix === 'feed' && <FeedPage /> } - { page.prefix === 'auth' && <AuthPage /> } - </div> + <SnackbarProvider + maxSnack={3} + anchorOrigin={{ + vertical: isMobile ? 'top' : 'bottom', + horizontal: 'right' + }} + > + <div className={classes.root}> + { page.prefix === 'home' && <HomePage />} + { page.prefix === 'profile' && <ProfilePage />} + { page.prefix === 'feed' && <FeedPage /> } + { page.prefix === 'auth' && <AuthPage /> } + { page.prefix === 'notifications' && <NotificationsPage /> } + </div> + </SnackbarProvider> ); }; diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx index 82e5cd8..ba4db7d 100644 --- a/src/pages/ProfilePage/ProfilePage.tsx +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import { User, Poll } from 'which-types'; +import { Container } from '@material-ui/core'; import ProfileInfo from './ProfileInfo'; import Feed from '../../components/Feed/Feed'; @@ -24,6 +25,7 @@ const ProfilePage: React.FC = () => { setUserInfo(response.data); }); get(`/profiles/${id}`).then(response => { + setPolls([]); setPolls(response.data); setTotalVotes(response.data.reduce( (total: number, current: Poll) => { @@ -37,7 +39,7 @@ const ProfilePage: React.FC = () => { }, [navigate, page, user]); return ( - <> + <Container maxWidth="sm" disableGutters> <ProfileInfo userInfo={userInfo} setUserInfo={setUserInfo} @@ -46,7 +48,7 @@ const ProfilePage: React.FC = () => { loading={isLoading} /> <Feed polls={[...polls]} /> - </> + </Container> ); }; |