Skip to content

Commit 78e7735

Browse files
committed
feat(notifications): Allow notification panel items to behave as link to notifications
1 parent 21298cf commit 78e7735

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/notifications/NotificationsPanel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// @flow
22

3-
import { getNotificationIcon } from "./helpers";
43
import moment from "moment";
54
import { NotificationsPanelComponents as NPC } from "./styled";
65
import React from "react";
76
import { translate } from "../locales";
87
import { ClickAwayListener, Typography } from "@material-ui/core";
8+
import { getNotificationIcon, getNotificationLink } from "./helpers";
99

1010
type Props = {
1111
handleClose: Function,
@@ -23,7 +23,12 @@ export const NotificationsPanel = ({ handleClose, notifications }: Props) => {
2323
</NPC.Header>
2424
<NPC.Body>
2525
{notifications.map(n => (
26-
<NPC.Item key={n.created_at} onClick={handleClose}>
26+
<NPC.Item
27+
target="_blank"
28+
href={getNotificationLink(n)}
29+
key={n.created_at}
30+
onClick={handleClose}
31+
>
2732
{getNotificationIcon(n.notification_type)}
2833
<div aria-label="NotificationItem">
2934
<Typography variant="body2">{n.data.topic_title}</Typography>

src/notifications/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Link from "@material-ui/icons/Link";
1313
import Loyalty from "@material-ui/icons/Loyalty";
1414
import Mail from "@material-ui/icons/Mail";
1515
import Person from "@material-ui/icons/Person";
16+
import { prependDiscourseUrl } from "../common/helpers";
1617
import React from "react";
1718
import Reply from "@material-ui/icons/Reply";
1819

@@ -62,6 +63,16 @@ const iconsMapping = {
6263
[notificationTypes[16]]: AddComment,
6364
};
6465

66+
export const getNotificationLink = (notification: Notification) => {
67+
if (!notification.topic_id || !notification.post_number) {
68+
return "#";
69+
}
70+
71+
return prependDiscourseUrl(
72+
`/t/${notification.topic_id}/${notification.post_number}`
73+
);
74+
};
75+
6576
export const getNotificationTypeName = (
6677
notificationType: string | number
6778
): string => {

src/notifications/styled.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ const NotificationsPanelHeader = styled.div`
4747
padding: 0 0.625rem;
4848
`;
4949

50-
const NotificationsPanelItem = styled.div`
50+
const NotificationsPanelItem = styled.a`
5151
align-items: center;
5252
border-bottom: 1px solid ${grey[400]};
5353
display: flex;
5454
padding: 0.625rem 1.875rem 0.625rem 0.625rem;
55+
text-decoration: none;
5556
5657
&:last-of-type {
5758
border-bottom: none;

0 commit comments

Comments
 (0)