-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Tom Richards <[email protected]>
- Loading branch information
1 parent
7630d6d
commit 28165b1
Showing
5 changed files
with
64 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useMutation } from "@apollo/client"; | ||
import { css } from "@emotion/react"; | ||
import { neutral } from "@guardian/source-foundations"; | ||
import { SvgStar, SvgStarOutline } from "@guardian/source-react-components"; | ||
import React from "react"; | ||
import { gqlSetIsStarred } from "../../gql"; | ||
|
||
export const STARRED_CONTROL_CLASS_NAME = "starred-control"; | ||
|
||
interface StarredControlProps { | ||
itemId: string; | ||
isStarred: boolean; | ||
} | ||
|
||
export const StarredControl = ({ itemId, isStarred }: StarredControlProps) => { | ||
const [setIsStarred] = useMutation(gqlSetIsStarred); | ||
const toggleIsStarred = () => { | ||
//TODO consider modal here to confirm (in both directions) | ||
setIsStarred({ variables: { itemId, isStarred: !isStarred } }); | ||
}; | ||
return ( | ||
<button | ||
onClick={toggleIsStarred} | ||
title={isStarred ? "Unstar" : "Star"} | ||
className={STARRED_CONTROL_CLASS_NAME} | ||
css={css` | ||
// :hover in ItemDisplay controls display | ||
border-radius: 50%; | ||
border: none; | ||
width: 24px; | ||
height: 24px; | ||
padding: 2px; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: ${neutral[86]}; | ||
} | ||
`} | ||
> | ||
{isStarred ? <SvgStar /> : <SvgStarOutline />} | ||
</button> | ||
); | ||
}; |