Skip to content

Commit 6e8a461

Browse files
fix(notifications): truncate X post attachment titles in notification list (#5867)
1 parent 3f7eed4 commit 6e8a461

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

packages/shared/src/components/notifications/NotificationItem.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const NotificationOptionsButton = ({
9090
});
9191
};
9292

93-
const Icon = (): ReactElement => {
93+
const Icon = (): ReactElement | null => {
9494
if (!notification) {
9595
return null;
9696
}
@@ -109,7 +109,7 @@ const NotificationOptionsButton = ({
109109

110110
const label = useMemo((): string => {
111111
if (!notification) {
112-
return null;
112+
return '';
113113
}
114114

115115
if (isFetching) {
@@ -120,6 +120,10 @@ const NotificationOptionsButton = ({
120120
preferences[0]?.status === NotificationPreferenceStatus.Muted;
121121
const copy = notificationMutingCopy[notification?.type];
122122

123+
if (!copy) {
124+
return '';
125+
}
126+
123127
return isMuted ? copy.unmute : copy.mute;
124128
}, [notification, preferences, isFetching]);
125129
const options = [{ icon: <Icon />, label, action: onItemClick }];
@@ -145,7 +149,7 @@ const NotificationOptionsButton = ({
145149
);
146150
};
147151

148-
function NotificationItem(props: NotificationItemProps): ReactElement {
152+
function NotificationItem(props: NotificationItemProps): ReactElement | null {
149153
const {
150154
icon,
151155
type,
@@ -165,7 +169,7 @@ function NotificationItem(props: NotificationItemProps): ReactElement {
165169
isReady,
166170
title: memoizedTitle,
167171
description: memoizedDescription,
168-
} = useObjectPurify({ title, description });
172+
} = useObjectPurify({ title, description: description ?? '' });
169173
const router = useRouter();
170174
const isClickable = !notificationTypeNotClickable[type];
171175

@@ -281,6 +285,7 @@ function NotificationItem(props: NotificationItemProps): ReactElement {
281285
<NotificationItemAttachment
282286
key={attachment}
283287
title={attachment}
288+
notificationType={type}
284289
{...restAttachmentProps}
285290
/>
286291
))}

packages/shared/src/components/notifications/NotificationItemAttachment.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import type { ReactElement } from 'react';
22
import React from 'react';
3+
import classNames from 'classnames';
34
import type { NotificationAttachment } from '../../graphql/notifications';
45
import { NotificationAttachmentType } from '../../graphql/notifications';
56
import { IconSize } from '../Icon';
67
import { CardCover } from '../cards/common/CardCover';
8+
import { NotificationType } from './utils';
9+
10+
interface NotificationItemAttachmentProps extends NotificationAttachment {
11+
notificationType?: NotificationType;
12+
}
13+
14+
const truncatedNotificationTypes = new Set([
15+
NotificationType.SourcePostAdded,
16+
NotificationType.UserPostAdded,
17+
NotificationType.SquadPostAdded,
18+
]);
719

820
function NotificationItemAttachment({
921
image,
1022
title,
1123
type,
12-
}: NotificationAttachment): ReactElement {
24+
notificationType,
25+
}: NotificationItemAttachmentProps): ReactElement {
1326
return (
1427
<div className="mt-2 flex flex-row items-center rounded-16 border border-border-subtlest-tertiary p-4">
1528
<div>
@@ -25,7 +38,16 @@ function NotificationItemAttachment({
2538
videoProps={{ size: IconSize.XLarge }}
2639
/>
2740
</div>
28-
<span className="ml-4 flex-1 break-words typo-callout">{title}</span>
41+
<span
42+
className={classNames(
43+
'ml-4 flex-1 break-words typo-callout',
44+
notificationType &&
45+
truncatedNotificationTypes.has(notificationType) &&
46+
'multi-truncate line-clamp-3',
47+
)}
48+
>
49+
{title}
50+
</span>
2951
</div>
3052
);
3153
}

0 commit comments

Comments
 (0)