import React from 'react'; import { useHistory } from 'react-router-dom'; import { Typography, Divider, Grid, Button, Link, useMediaQuery } from '@material-ui/core/'; import { makeStyles, useTheme } from '@material-ui/core/styles'; import GitHubIcon from '@material-ui/icons/GitHub'; import { Rating } from '@material-ui/lab'; import { Feedback } from 'which-types'; import ReviewCard from '../../components/ReviewCard/ReviewCard'; import Image from '../../components/Image/Image'; import ReviewForm from './ReviewForm'; import { useAuth } from '../../hooks/useAuth'; import { useFeedback, usePatchNotes } from '../../hooks/APIClient'; const useStyles = makeStyles(theme => ({ root: { overflow: 'hidden', padding: theme.spacing(0, 2) }, logo: { width: theme.spacing(20), height: theme.spacing(20) }, patchNotes: { whiteSpace: 'pre-wrap' }, score: { fontWeight: 'bold' }, signup: { marginLeft: theme.spacing(2) }, reviews: { [theme.breakpoints.up('md')]: { padding: theme.spacing(0, 10) } } })); const Home: React.FC = () => { const { data: feedbacks } = useFeedback(); const { data: release } = usePatchNotes(); const classes = useStyles(); const history = useHistory(); const { isAuthenticated, user } = useAuth(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const rating = feedbacks?.length ? feedbacks.reduce( (acc: number, feedback: Feedback) => acc + feedback.score, 0 ) / feedbacks.length : 0; const handleLetsGo = () => { history.push('/feed'); }; const handleSignUp = () => { history.push('/registration'); }; const EmailLink = eug-vs@keemail.me; const Reviews = (
{feedbacks?.map((feedback: Feedback) => )}
); const FeedbackSection = feedbacks && feedbacks.findIndex( (feedback: Feedback) => feedback.author._id === user?._id ) >= 0 ? (

You have already left feedback for this version. If you have more to say, please open GitHub issue or contact us directly via email: {EmailLink}. Alternatively, you can just wait for another application patch to come out.

) : ( <>

Here you can share your thougts about Which with us! Note that you can ony leave feedback once per application version (there will be plenty of them later).

{isAuthenticated ? : ( <>

You must be authorized to leave feedback.

)} ); return (
logo {rating !== 0 && } {rating !== 0 && ( User score: {rating.toFixed(1)} )} {isMobile || Reviews} Which one to choose?

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!

Share your minor everyday uncertainties with the whole world and see what others think!

{!isAuthenticated && ( )}
{release && ( {`What's new in ${release?.version}?`}

{release?.description}

)} Leave feedback {FeedbackSection} {isMobile && ( {Reviews} )}
); }; export default Home;