Skip to content

Commit b294532

Browse files
Add starred controls to UI
Co-Authored-By: Tom Richards <19289579+twrichards@users.noreply.github.com>
1 parent 7630d6d commit b294532

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

client/src/app.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ import { getAgateFontFaceIfApplicable } from "../fontNormaliser";
4545
import { Global } from "@emotion/react";
4646
import { TourStateProvider } from "./tour/tourState";
4747
import { demoMentionableUsers, demoUser } from "./tour/tourConstants";
48-
import {
49-
STARRED_MESSAGES_HTML_TAG,
50-
StarredMessagesPortal,
51-
} from "./starred/starredMessages";
48+
import { STARRED_MESSAGES_HTML_TAG } from "./starred/starredMessages";
5249

5350
const PRESELECT_PINBOARD_HTML_TAG = "pinboard-preselect";
5451
const PRESET_UNREAD_NOTIFICATIONS_COUNT_HTML_TAG = "pinboard-bubble-preset";

client/src/itemDisplay.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import Pencil from "../icons/pencil.svg";
2424
import { ITEM_HOVER_MENU_CLASS_NAME, ItemHoverMenu } from "./itemHoverMenu";
2525
import { EditItem } from "./editItem";
2626
import { Reply } from "./reply";
27+
import {
28+
StarredControl,
29+
STARRED_CONTROL_CLASS_NAME,
30+
} from "./starred/starredControl";
2731

2832
interface ItemDisplayProps {
2933
item: Item | PendingItem;
@@ -107,10 +111,16 @@ export const ItemDisplay = ({
107111
${agateSans.small({ lineHeight: "tight" })};
108112
color: ${palette.neutral[7]};
109113
overflow-wrap: anywhere;
114+
.${STARRED_CONTROL_CLASS_NAME} {
115+
display: ${item.isStarred ? "block" : "none"};
116+
}
110117
&:hover {
111118
.${ITEM_HOVER_MENU_CLASS_NAME} {
112119
display: flex;
113120
}
121+
.${STARRED_CONTROL_CLASS_NAME} {
122+
display: block;
123+
}
114124
}
115125
`}
116126
>
@@ -140,6 +150,15 @@ export const ItemDisplay = ({
140150
</React.Fragment>
141151
)}
142152
</div>
153+
<div
154+
css={css`
155+
position: absolute;
156+
margin-top: 5px;
157+
margin-left: 2px;
158+
`}
159+
>
160+
<StarredControl itemId={item.id} isStarred={item.isStarred} />
161+
</div>
143162
<div
144163
css={css`
145164
margin-left: ${space[9] - 4}px;

client/src/itemHoverMenu.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { css } from "@emotion/react";
22
import React, { useContext, useEffect } from "react";
33
import { palette, space } from "@guardian/source-foundations";
4-
import { SvgStar, SvgStarOutline } from "@guardian/source-react-components";
54
import ReplyIcon from "../icons/reply.svg";
65
import PencilIcon from "../icons/pencil.svg";
76
import BinIcon from "../icons/bin.svg";
87
import { useConfirmModal } from "./modal";
98
import { scrollbarsCss } from "./styling";
109
import { composer } from "../colours";
1110
import { useMutation } from "@apollo/client";
12-
import { gqlDeleteItem, gqlSetIsStarred } from "../gql";
11+
import { gqlDeleteItem } from "../gql";
1312
import { Item } from "shared/graphql/graphql";
1413
import { PINBOARD_TELEMETRY_TYPE, TelemetryContext } from "./types/Telemetry";
1514
import { useTourProgress } from "./tour/tourState";
@@ -56,12 +55,6 @@ export const ItemHoverMenu = ({
5655
</React.Fragment>
5756
);
5857

59-
const isStarred = item.isStarred;
60-
const [setIsStarred] = useMutation(gqlSetIsStarred);
61-
const toggleIsStarred = () => {
62-
setIsStarred({ variables: { itemId: item.id, isStarred: !isStarred } });
63-
};
64-
6558
useEffect(
6659
() => setMaybeDeleteItemModalElement(deleteConfirmModalElement),
6760
[deleteConfirmModalElement]
@@ -145,12 +138,6 @@ export const ItemHoverMenu = ({
145138
}
146139
`}
147140
>
148-
<button
149-
onClick={toggleIsStarred}
150-
title={isStarred ? "Unstar" : "Star"}
151-
>
152-
{isStarred ? <SvgStar /> : <SvgStarOutline />}
153-
</button>
154141
<button onClick={() => setMaybeReplyingToItemId(item.id)} title="Reply">
155142
<ReplyIcon />
156143
</button>

client/src/scrollableItems.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ export const ScrollableItems = ({
301301
item.claimedByEmail,
302302
item.editHistory,
303303
item.deletedAt,
304+
item.isStarred,
304305
"pending" in item,
305306
userLookup,
306307
lastItemSeenByUsersForItemIDLookup,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useMutation } from "@apollo/client";
2+
import { css } from "@emotion/react";
3+
import { neutral } from "@guardian/source-foundations";
4+
import { SvgStar, SvgStarOutline } from "@guardian/source-react-components";
5+
import React from "react";
6+
import { gqlSetIsStarred } from "../../gql";
7+
8+
export const STARRED_CONTROL_CLASS_NAME = "starred-control";
9+
10+
interface StarredControlProps {
11+
itemId: string;
12+
isStarred: boolean;
13+
}
14+
15+
export const StarredControl = ({ itemId, isStarred }: StarredControlProps) => {
16+
const [setIsStarred] = useMutation(gqlSetIsStarred);
17+
const toggleIsStarred = () => {
18+
setIsStarred({ variables: { itemId, isStarred: !isStarred } });
19+
};
20+
return (
21+
<button
22+
onClick={toggleIsStarred}
23+
title={isStarred ? "Unstar" : "Star"}
24+
className={STARRED_CONTROL_CLASS_NAME}
25+
css={css`
26+
// :hover in ItemDisplay controls display
27+
border-radius: 50%;
28+
border: none;
29+
width: 24px;
30+
height: 24px;
31+
padding: 2px;
32+
cursor: pointer;
33+
&:hover {
34+
background-color: ${neutral[86]};
35+
}
36+
`}
37+
>
38+
{isStarred ? <SvgStar /> : <SvgStarOutline />}
39+
</button>
40+
);
41+
};

0 commit comments

Comments
 (0)