Skip to content

Commit

Permalink
WIP Modal hover check on starred messages
Browse files Browse the repository at this point in the history
Co-Authored-By: Tom Richards <[email protected]>
  • Loading branch information
frederickobrien and twrichards committed Nov 10, 2023
1 parent f8cb883 commit 9a36de2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
2 changes: 1 addition & 1 deletion client/src/itemDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const ItemDisplay = ({
margin-left: 2px;
`}
>
<StarredControl itemId={item.id} isStarred={item.isStarred} />
<StarredControl item={item} />
</div>
)}
<div
Expand Down
2 changes: 1 addition & 1 deletion client/src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useConfirmModal = (
<ModalBackground />
<div
css={css`
position: absolute;
position: fixed;
left: ${space[2]}px;
right: ${space[2]}px;
bottom: 30px;
Expand Down
79 changes: 54 additions & 25 deletions client/src/starred/starredControl.tsx
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>
);
};
14 changes: 8 additions & 6 deletions client/src/starred/starredMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ const StarredItemDisplay = ({
}) => {
const user = userLookup?.[item.userEmail];
const userDisplayName = user
? `${user.firstName} ${user.lastName}`
? `${user.firstName} ${user.lastName}` // TODO: Non-breaking space
: item.userEmail;
return (
<div
css={css`
display: flex;
align-items: flex-end;
gap: ${space[1]}px;
color: ${neutral[20]};
cursor: ${maybeScrollToItem ? "pointer" : "initial"};
position: relative;
Expand All @@ -54,6 +51,7 @@ const StarredItemDisplay = ({
css={css`
color: ${neutral[0]};
${agateSans.medium()};
white-space: pre-line;
`}
>
{item.message}
Expand Down Expand Up @@ -87,6 +85,9 @@ const StarredMessages = ({
border-radius: 6px;
background-color: ${pinboard[800]};
margin-bottom: 20px;
display: flex;
flex-direction: column;
gap: ${space[3]}px;
`}
>
{maybeStarredMessages.length === 0 && (
Expand All @@ -102,8 +103,9 @@ const StarredMessages = ({
</strong>
<br />
Click here to open Pinboard, then simply send a message and then
click the <SvgStar size="xsmall" /> to the left of your message. You
can also star other&apos;s messages if you think they&apos;re
click the <SvgStar size="xsmall" /> to the left of your message.
<br />
You can also star other&apos;s messages if you think they&apos;re
important.
</span>
)}
Expand Down

0 comments on commit 9a36de2

Please sign in to comment.