diff options
Diffstat (limited to 'src/components/PollCard')
| -rw-r--r-- | src/components/PollCard/PollCard.tsx | 60 | 
1 files changed, 24 insertions, 36 deletions
| diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 40f5fd7..d3b4fc2 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -3,13 +3,12 @@ import { makeStyles } from '@material-ui/core/styles';  import {    Card,    CardActionArea, -  CardMedia, -  Avatar, -  CardHeader +  CardMedia  } from '@material-ui/core/';  import { Which, Poll } from 'which-types';  import PercentageBar from './PercentageBar'; +import UserStrip from '../UserStrip/UserStrip';  import { post } from '../../requests';  interface PropTypes { @@ -17,6 +16,14 @@ interface PropTypes {    navigate: (prefix: string, id: string) => void;  } +const DATE_FORMAT = { +  month: 'long', +  day: 'numeric', +  year: 'numeric', +  hour: '2-digit', +  minute: '2-digit' +}; +  const useStyles = makeStyles(theme => ({    root: {      maxWidth: theme.spacing(75), @@ -30,18 +37,19 @@ const useStyles = makeStyles(theme => ({    imagesBlock: {      display: 'flex'    }, -  avatar: { -    cursor: 'pointer' -  },    rateLine: {      position: 'relative',      width: '100%',      height: theme.spacing(2), -    backgroundColor: theme.palette.primary.light +    backgroundColor: theme.palette.primary.light, +    transitionDuration: '0.5s' +  }, +  highlight: { +    backgroundColor: `${theme.palette.primary.main} !important`    },    fillRateLine: {      height: theme.spacing(2), -    backgroundColor: theme.palette.primary.main, +    backgroundColor: theme.palette.primary.light,      transitionDuration: '0.5s'    }  })); @@ -50,10 +58,7 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => {    const [poll, setPoll] = useState<Poll>(initialPoll);    const classes = useStyles();    const { author, contents: { left, right }, userChoice } = poll; - -  const handleNavigate = () => { -    navigate('profile', poll.author._id); -  }; +  const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT);    const vote = (which: Which) => {      if (userChoice) return; @@ -68,50 +73,33 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => {    const handleRight = () => vote('right');    const leftPercentage = Math.round(100 * (left.votes / (left.votes + right.votes))); +  const rightPercentage = 100 - leftPercentage; -  const percentage = { -    left: leftPercentage, -    right: 100 - leftPercentage -  };    const dominant: Which = left.votes >= right.votes ? 'left' : 'right';    return (      <Card className={classes.root}> -      <CardHeader -        avatar={( -          <Avatar -            aria-label="avatar" -            src={author.avatarUrl} -            alt={author.username[0].toUpperCase()} -            onClick={handleNavigate} -            className={classes.avatar} -          /> -        )} -        title={author.username} -      /> +      <UserStrip user={author} info={date} navigate={navigate} />        <div className={classes.imagesBlock}>          <CardActionArea onDoubleClick={handleLeft}>            <CardMedia              className={classes.images}              image={left.url}            /> -          <PercentageBar value={percentage.left} which="left" like={userChoice === 'left'} /> +          <PercentageBar value={leftPercentage} which="left" like={userChoice === 'left'} />          </CardActionArea>          <CardActionArea onDoubleClick={handleRight}>            <CardMedia              className={classes.images}              image={right.url}            /> -          <PercentageBar value={percentage.right} which="right" like={userChoice === 'right'} /> +          <PercentageBar value={rightPercentage} which="right" like={userChoice === 'right'} />          </CardActionArea>        </div> -      <div className={classes.rateLine}> +      <div className={`${classes.rateLine} ${dominant === 'right' ? classes.highlight : ''}`}>          <div -          className={classes.fillRateLine} -          style={{ -            width: `${percentage[dominant]}%`, -            float: dominant -          }} +          className={`${classes.fillRateLine} ${dominant === 'left' ? classes.highlight : ''}`} +          style={{ width: `${leftPercentage}%` }}          />        </div>      </Card> | 
