-
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.
WIP Modal hover check on starred messages
Co-Authored-By: Tom Richards <[email protected]>
- Loading branch information
1 parent
f8cb883
commit 9a36de2
Showing
4 changed files
with
64 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,71 @@ | ||
import { useMutation } from "@apollo/client"; | ||
import { css } from "@emotion/react"; | ||
import { neutral } from "@guardian/source-foundations"; | ||
import { neutral, space } from "@guardian/source-foundations"; | ||
import { SvgStar, SvgStarOutline } from "@guardian/source-react-components"; | ||
import React from "react"; | ||
import { Item } from "shared/graphql/graphql"; | ||
import { composer } from "../../colours"; | ||
import { gqlSetIsStarred } from "../../gql"; | ||
import { useConfirmModal } from "../modal"; | ||
import { scrollbarsCss } from "../styling"; | ||
|
||
export const STARRED_CONTROL_CLASS_NAME = "starred-control"; | ||
|
||
interface StarredControlProps { | ||
itemId: string; | ||
isStarred: boolean; | ||
item: Item; | ||
} | ||
|
||
export const StarredControl = ({ itemId, isStarred }: StarredControlProps) => { | ||
export const StarredControl = ({ | ||
item: { id, isStarred, message }, | ||
}: StarredControlProps) => { | ||
const [setIsStarred] = useMutation(gqlSetIsStarred); | ||
const [confirmModalElement, confirm] = useConfirmModal( | ||
<React.Fragment> | ||
<div> | ||
Are you sure you want | ||
<br /> to <strong>{isStarred ? "unstar" : "star"}</strong> this item? | ||
</div> | ||
<div | ||
css={css` | ||
padding: ${space[2]}px; | ||
font-style: italic; | ||
max-height: 55px; | ||
overflow-y: auto; | ||
${scrollbarsCss(composer.primary["100"])} | ||
`} | ||
> | ||
{message} | ||
</div> | ||
</React.Fragment> | ||
); | ||
const toggleIsStarred = () => { | ||
//TODO consider modal here to confirm (in both directions) | ||
setIsStarred({ variables: { itemId, isStarred: !isStarred } }); | ||
confirm().then((isConfirmed) => { | ||
isConfirmed && | ||
setIsStarred({ variables: { itemId: id, 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> | ||
<div> | ||
{confirmModalElement} | ||
<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> | ||
</div> | ||
); | ||
}; |
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