Skip to content

Commit 13a019e

Browse files
committed
feat: migrate to RelativeTime component
Signed-off-by: Adam Setch <[email protected]>
1 parent 5000c7a commit 13a019e

File tree

3 files changed

+8
-67
lines changed

3 files changed

+8
-67
lines changed

src/renderer/components/notifications/NotificationFooter.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import type { FC, MouseEvent } from 'react';
22

33
import { FeedPersonIcon, MarkGithubIcon } from '@primer/octicons-react';
4-
import { Avatar } from '@primer/react';
4+
import { Avatar, RelativeTime } from '@primer/react';
55

66
import { IconColor, Opacity, Size } from '../../types';
77
import type { Notification } from '../../typesGitHub';
88
import { cn } from '../../utils/cn';
9-
import {
10-
formatNotificationUpdatedAt,
11-
isNonHumanUser,
12-
} from '../../utils/helpers';
9+
import { isNonHumanUser } from '../../utils/helpers';
1310
import { openUserProfile } from '../../utils/links';
1411
import { formatReason } from '../../utils/reason';
1512
import { Pills } from './Pills';
@@ -23,11 +20,6 @@ export const NotificationFooter: FC<INotificationFooter> = ({
2320
}: INotificationFooter) => {
2421
const reason = formatReason(notification.reason);
2522

26-
const updatedAt = formatNotificationUpdatedAt(notification);
27-
const updatedLabel = notification.subject.user
28-
? `${notification.subject.user.login} updated ${updatedAt}`
29-
: `Updated ${updatedAt}`;
30-
3123
return (
3224
<div className="flex flex-wrap items-center gap-1">
3325
{notification.subject.user ? (
@@ -53,17 +45,12 @@ export const NotificationFooter: FC<INotificationFooter> = ({
5345
)}
5446
</>
5547
)}
56-
<span
57-
className={cn('text-xs capitalize', Opacity.MEDIUM)}
58-
title={reason.description}
59-
>
60-
{reason.title}
61-
</span>
62-
<span
63-
className={cn('text-xs capitalize', Opacity.MEDIUM)}
64-
title={updatedLabel}
65-
>
66-
{updatedAt}
48+
<span className={cn('text-xs', Opacity.MEDIUM)}>
49+
<span className={'capitalize'} title={reason.description}>
50+
{reason.title}
51+
</span>
52+
<span></span>
53+
<RelativeTime datetime={notification.updated_at} />
6754
</span>
6855
<Pills notification={notification} />
6956
</div>

src/renderer/utils/helpers.test.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import * as apiRequests from './api/request';
1818

1919
import {
2020
formatForDisplay,
21-
formatNotificationUpdatedAt,
2221
generateGitHubWebUrl,
2322
generateNotificationReferrerId,
2423
getChevronDetails,
@@ -534,38 +533,6 @@ describe('renderer/utils/helpers.ts', () => {
534533
'Not Planned Issue',
535534
);
536535
});
537-
538-
describe('formatNotificationUpdatedAt', () => {
539-
it('should use updated_at if last_read_at is null', () => {
540-
const notification = {
541-
...mockSingleNotification,
542-
last_read_at: null,
543-
updated_at: '2021-06-23T17:00:00Z',
544-
};
545-
546-
expect(formatNotificationUpdatedAt(notification)).toContain('ago');
547-
});
548-
549-
it('should return empty if all dates are null', () => {
550-
const notification = {
551-
...mockSingleNotification,
552-
last_read_at: null,
553-
updated_at: null,
554-
};
555-
556-
expect(formatNotificationUpdatedAt(notification)).toBe('');
557-
});
558-
559-
it('should return empty if unable to parse dates', () => {
560-
const notification = {
561-
...mockSingleNotification,
562-
last_read_at: 'not an iso date',
563-
updated_at: 'not an iso date',
564-
};
565-
566-
expect(formatNotificationUpdatedAt(notification)).toBe('');
567-
});
568-
});
569536
});
570537

571538
describe('getChevronDetails', () => {

src/renderer/utils/helpers.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
ChevronLeftIcon,
44
ChevronRightIcon,
55
} from '@primer/octicons-react';
6-
import { formatDistanceToNowStrict, parseISO } from 'date-fns';
76

87
import { logError, logWarn } from '../../shared/logger';
98
import type { Chevron, Hostname, Link } from '../types';
@@ -187,18 +186,6 @@ export function formatForDisplay(text: string[]): string {
187186
});
188187
}
189188

190-
export function formatNotificationUpdatedAt(
191-
notification: Notification,
192-
): string {
193-
try {
194-
return formatDistanceToNowStrict(parseISO(notification.updated_at), {
195-
addSuffix: true,
196-
});
197-
} catch (e) {}
198-
199-
return '';
200-
}
201-
202189
export function getChevronDetails(
203190
hasNotifications: boolean,
204191
isVisible: boolean,

0 commit comments

Comments
 (0)