Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 40 additions & 51 deletions src/components/practicePage/PageMenu/SocialLinks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import { EmailShareButton, TwitterShareButton, LinkedinShareButton, PinterestShareButton, RedditShareButton, FacebookShareButton } from "react-share";
import { FacebookIcon, RedditIcon, PinterestIcon, TwitterIcon, MoreItemsIcon, NounLoveIcon, LinkedInIcon, EmailIcon } from "../../../assets/icons";
import { useMutation } from "@apollo/react-hooks";
import { LIKE_PRACTICE } from "../../../graphql/";
import { Typography, Grid, IconButton, Popover } from '@material-ui/core';
import {
EmailShareButton,
TwitterShareButton,
LinkedinShareButton,
PinterestShareButton,
RedditShareButton,
FacebookShareButton,
} from "react-share";
import {
FacebookIcon,
RedditIcon,
PinterestIcon,
TwitterIcon,
MoreItemsIcon,
LinkedInIcon,
EmailIcon,
} from "../../../assets/icons";
import { Typography, Grid, IconButton, Popover } from "@material-ui/core";

const useStyles = makeStyles((theme) => ({
root: {
Expand All @@ -21,35 +34,27 @@ const useStyles = makeStyles((theme) => ({
borderColor: theme.palette.primary.main,
borderStyle: "solid",
textAlign: "center",
padding: theme.spacing(2,4),
padding: theme.spacing(2, 4),
},
}));

const StyledPopover = ((props) =>(
const StyledPopover = (props) => (
<Popover
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right',
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}{...props}
vertical: "top",
horizontal: "right",
}}
{...props}
/>
));
);

export default function SocialLinks(props) {
const classes = useStyles();

const [likePractice] = useMutation(LIKE_PRACTICE);
const handleLike = () => {
const originalLikes = props.upvotes;
const newUpvotes = originalLikes + 1;
likePractice({
variables: {practiceId: props.practiceId, upvotes: newUpvotes},
});
};

const [anchorEl, setAnchorEl] = React.useState(null);

const handleClick = (event) => {
Expand All @@ -61,32 +66,13 @@ export default function SocialLinks(props) {
};

const open = Boolean(anchorEl);
const id = open ? 'simple-popover' : undefined;
const id = open ? "simple-popover" : undefined;

return (
<>
<Grid
container
direction="row"
className={classes.root}
spacing={1}
>
<Grid item xs={3}>
<Typography
className={classes.url}
variant="overline"
>
Like
</Typography>
<IconButton onClick={handleLike} data-testid={"heartIcon"}>
<NounLoveIcon/>
</IconButton>
</Grid>
<Grid container direction="row" className={classes.root} spacing={1}>
<Grid item>
<Typography
className={classes.url}
variant="overline"
>
<Typography className={classes.url} variant="overline">
Share{" "}
</Typography>
</Grid>
Expand All @@ -102,12 +88,12 @@ export default function SocialLinks(props) {
</Grid>
<Grid item>
<LinkedinShareButton url={window.location.href}>
<LinkedInIcon/>
<LinkedInIcon />
</LinkedinShareButton>
</Grid>
<Grid item>
<IconButton aria-describedby={id} onClick={handleClick}>
<MoreItemsIcon/>
<MoreItemsIcon />
</IconButton>
<StyledPopover
id={id}
Expand All @@ -125,18 +111,21 @@ export default function SocialLinks(props) {
spacing={2}
>
<Grid item>
<PinterestShareButton url={window.location.href} media={props.coverImage}>
<PinterestIcon/>
<PinterestShareButton
url={window.location.href}
media={props.coverImage}
>
<PinterestIcon />
</PinterestShareButton>
</Grid>
<Grid item>
<RedditShareButton url={window.location.href}>
<RedditIcon/>
<RedditIcon />
</RedditShareButton>
</Grid>
<Grid item>
<FacebookShareButton url={window.location.href}>
<FacebookIcon/>
<FacebookIcon />
</FacebookShareButton>
</Grid>
</Grid>
Expand All @@ -145,4 +134,4 @@ export default function SocialLinks(props) {
</Grid>
</>
);
}
}
55 changes: 0 additions & 55 deletions src/components/practicePage/PageMenu/__tests__/SocialLinks.js

This file was deleted.

34 changes: 24 additions & 10 deletions src/components/shared/Collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import { AmaIcon, CameraIcon, FilledHeartIcon } from "../../../assets/icons";
import { useMutation } from "@apollo/react-hooks";
import { LIKE_PRACTICE } from "../../../graphql/";

import { Box } from '@material-ui/core';
import { Box } from "@material-ui/core";
import OplTypography from "../components/OplTypography";

const Collection = (props) => {
const [likePractice] = useMutation(LIKE_PRACTICE);

const [upvoteNotClicked, setUpvoteNotClicked] = React.useState(true);

const handleLike = () => {
const originalLikes = props.upvotes;
const newUpvotes = originalLikes + 1;
likePractice({
variables: { practiceId: props.practiceId, upvotes: newUpvotes },
});
setUpvoteNotClicked(false);
};

return (
Expand All @@ -25,14 +28,25 @@ const Collection = (props) => {
py={props.alignment}
>
{props.children}
<OplTypography
fontWeight="bold"
variant="subtitle1"
data-testid="heartIcon"
onClick={handleLike}
>
<FilledHeartIcon fill={props.fill} /> {props.upvotes}{" "}
</OplTypography>
{upvoteNotClicked ? (
<OplTypography
fontWeight="bold"
variant="subtitle1"
data-testid="heartIcon"
onClick={handleLike}
>
<FilledHeartIcon fill={props.fill} /> {props.upvotes}{" "}
</OplTypography>
) : (
<OplTypography
fontWeight="bold"
variant="subtitle1"
data-testid="heartIcon"
>
<FilledHeartIcon fill="#DDDDDD"/> {props.upvotes}{" "}
</OplTypography>
)}

<OplTypography
fontWeight="bold"
variant="subtitle1"
Expand All @@ -50,6 +64,6 @@ const Collection = (props) => {
</OplTypography>
</Box>
);
}
};

export default Collection;