Skip to content

Commit 7a8cdf4

Browse files
authored
refactor(group): isGroupByDate helper util (#2496)
Signed-off-by: Adam Setch <[email protected]>
1 parent 065a8c0 commit 7a8cdf4

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/renderer/components/notifications/NotificationHeader.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import type { FC, MouseEvent } from 'react';
33
import { Stack } from '@primer/react';
44

55
import { useAppContext } from '../../context/App';
6-
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
6+
import { type GitifyNotification, Opacity, Size } from '../../types';
77
import { cn } from '../../utils/cn';
88
import { openRepository } from '../../utils/links';
9+
import { isGroupByDate } from '../../utils/notifications/group';
910
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';
1011

1112
interface NotificationHeaderProps {
@@ -23,10 +24,8 @@ export const NotificationHeader: FC<NotificationHeaderProps> = ({
2324
? `#${notification.subject.number}`
2425
: '';
2526

26-
const groupByDate = settings.groupBy === GroupBy.DATE;
27-
2827
return (
29-
groupByDate && (
28+
isGroupByDate(settings) && (
3029
<div className="py-0.5">
3130
<Stack align="center" direction="horizontal" gap="condensed">
3231
<button

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { BellSlashIcon, CheckIcon, ReadIcon } from '@primer/octicons-react';
44
import { Stack, Text, Tooltip } from '@primer/react';
55

66
import { useAppContext } from '../../context/App';
7-
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
7+
import { type GitifyNotification, Opacity, Size } from '../../types';
88
import { cn } from '../../utils/cn';
99
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
1010
import { openNotification } from '../../utils/links';
11+
import { isGroupByDate } from '../../utils/notifications/group';
1112
import { createNotificationHandler } from '../../utils/notifications/handlers';
1213
import { HoverButton } from '../primitives/HoverButton';
1314
import { HoverGroup } from '../primitives/HoverGroup';
@@ -68,8 +69,6 @@ export const NotificationRow: FC<NotificationRowProps> = ({
6869
const notificationNumber = handler.formattedNotificationNumber(notification);
6970
const notificationTitle = handler.formattedNotificationTitle(notification);
7071

71-
const groupByDate = settings.groupBy === GroupBy.DATE;
72-
7372
const isNotificationRead = !notification.unread;
7473

7574
return (
@@ -125,7 +124,7 @@ export const NotificationRow: FC<NotificationRowProps> = ({
125124
className={cn(
126125
'text-xxs ml-auto mr-2',
127126
Opacity.READ,
128-
(groupByDate || !settings.showNumber) && 'hidden',
127+
(isGroupByDate(settings) || !settings.showNumber) && 'hidden',
129128
)}
130129
>
131130
{notificationNumber}

src/renderer/utils/notifications/group.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@ import { GroupBy } from '../../types';
55
import {
66
getFlattenedNotificationsByRepo,
77
groupNotificationsByRepository,
8+
isGroupByDate,
89
isGroupByRepository,
910
} from './group';
1011

1112
describe('renderer/utils/notifications/group.ts', () => {
13+
describe('isGroupByDate', () => {
14+
it('returns true when groupBy is DATE', () => {
15+
const settings = { ...mockSettings, groupBy: GroupBy.DATE };
16+
expect(isGroupByDate(settings)).toBe(true);
17+
});
18+
19+
it('returns false when groupBy is REPOSITORY', () => {
20+
const settings = { ...mockSettings, groupBy: GroupBy.REPOSITORY };
21+
expect(isGroupByDate(settings)).toBe(false);
22+
});
23+
});
24+
1225
describe('isGroupByRepository', () => {
1326
it('returns true when groupBy is REPOSITORY', () => {
1427
const settings = { ...mockSettings, groupBy: GroupBy.REPOSITORY };

src/renderer/utils/notifications/group.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { GitifyNotification, SettingsState } from '../../types';
22

3+
/**
4+
* Returns true when settings say to group by date.
5+
*/
6+
export function isGroupByDate(settings: SettingsState) {
7+
return settings.groupBy === 'DATE';
8+
}
9+
310
/**
411
* Returns true when settings say to group by repository.
512
*/

0 commit comments

Comments
 (0)