diff --git a/src/components/practicePage/PageMenu/SocialLinks.js b/src/components/practicePage/PageMenu/SocialLinks.js index c3b6974..5584484 100644 --- a/src/components/practicePage/PageMenu/SocialLinks.js +++ b/src/components/practicePage/PageMenu/SocialLinks.js @@ -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: { @@ -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) => ( -)); +); 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) => { @@ -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 ( <> - - - - Like - - - - - + - + Share{" "} @@ -102,12 +88,12 @@ export default function SocialLinks(props) { - + - + - - + + - + - + @@ -145,4 +134,4 @@ export default function SocialLinks(props) { ); -} \ No newline at end of file +} diff --git a/src/components/practicePage/PageMenu/__tests__/SocialLinks.js b/src/components/practicePage/PageMenu/__tests__/SocialLinks.js deleted file mode 100644 index 48632ab..0000000 --- a/src/components/practicePage/PageMenu/__tests__/SocialLinks.js +++ /dev/null @@ -1,55 +0,0 @@ -import React from "react"; -import {cleanup, fireEvent, render, waitFor} from "@testing-library/react"; -import "@testing-library/jest-dom/extend-expect"; -import {MockedProvider} from "@apollo/react-testing"; -import SocialLinks from "../SocialLinks"; -import {LIKE_PRACTICE} from "../../../../graphql"; - -afterEach(cleanup); - -const mockProps = { - practiceId: "aFak3ID4y0U", - upvotes: 42, -} - -it("modifies upvotes when mutation is run", async () => { - let practiceLiked = false; - const likedPractice = { - data: { - updatePractice: { - __typename: "updatePracticePayload", - practice: { - __typename: "Practice", - id: "aFak3ID4y0U", - upvotes: 43, - }, - }, - }, - }; - - const apolloMocks = [ - { - request: { - query: LIKE_PRACTICE, - variables: { - practiceId: "aFak3ID4y0U", - upvotes: 43, - }, - }, - result: () => { - practiceLiked = true; - return likedPractice; - }, - }, - ]; - - const {getByTestId} = render( - - - - ); - - expect(getByTestId("heartIcon")); - fireEvent.click(getByTestId("heartIcon")); - await waitFor(() => expect(practiceLiked).toBe(true)); -}); diff --git a/src/components/shared/Collection/index.js b/src/components/shared/Collection/index.js index f34ddf0..243c3bd 100644 --- a/src/components/shared/Collection/index.js +++ b/src/components/shared/Collection/index.js @@ -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 ( @@ -25,14 +28,25 @@ const Collection = (props) => { py={props.alignment} > {props.children} - - {props.upvotes}{" "} - + {upvoteNotClicked ? ( + + {props.upvotes}{" "} + + ) : ( + + {props.upvotes}{" "} + + )} + { ); -} +}; export default Collection;