Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { FC, MouseEvent } from 'react';
import { Stack } from '@primer/react';

import { useAppContext } from '../../context/App';
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
import { type GitifyNotification, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { openRepository } from '../../utils/links';
import { isGroupByDate } from '../../utils/notifications/group';
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';

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

const groupByDate = settings.groupBy === GroupBy.DATE;

return (
groupByDate && (
isGroupByDate(settings) && (
<div className="py-0.5">
<Stack align="center" direction="horizontal" gap="condensed">
<button
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/components/notifications/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { BellSlashIcon, CheckIcon, ReadIcon } from '@primer/octicons-react';
import { Stack, Text, Tooltip } from '@primer/react';

import { useAppContext } from '../../context/App';
import { type GitifyNotification, GroupBy, Opacity, Size } from '../../types';
import { type GitifyNotification, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
import { openNotification } from '../../utils/links';
import { isGroupByDate } from '../../utils/notifications/group';
import { createNotificationHandler } from '../../utils/notifications/handlers';
import { HoverButton } from '../primitives/HoverButton';
import { HoverGroup } from '../primitives/HoverGroup';
Expand Down Expand Up @@ -68,8 +69,6 @@ export const NotificationRow: FC<NotificationRowProps> = ({
const notificationNumber = handler.formattedNotificationNumber(notification);
const notificationTitle = handler.formattedNotificationTitle(notification);

const groupByDate = settings.groupBy === GroupBy.DATE;

const isNotificationRead = !notification.unread;

return (
Expand Down Expand Up @@ -125,7 +124,7 @@ export const NotificationRow: FC<NotificationRowProps> = ({
className={cn(
'text-xxs ml-auto mr-2',
Opacity.READ,
(groupByDate || !settings.showNumber) && 'hidden',
(isGroupByDate(settings) || !settings.showNumber) && 'hidden',
)}
>
{notificationNumber}
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/utils/notifications/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import { GroupBy } from '../../types';
import {
getFlattenedNotificationsByRepo,
groupNotificationsByRepository,
isGroupByDate,
isGroupByRepository,
} from './group';

describe('renderer/utils/notifications/group.ts', () => {
describe('isGroupByDate', () => {
it('returns true when groupBy is DATE', () => {
const settings = { ...mockSettings, groupBy: GroupBy.DATE };
expect(isGroupByDate(settings)).toBe(true);
});

it('returns false when groupBy is REPOSITORY', () => {
const settings = { ...mockSettings, groupBy: GroupBy.REPOSITORY };
expect(isGroupByDate(settings)).toBe(false);
});
});

describe('isGroupByRepository', () => {
it('returns true when groupBy is REPOSITORY', () => {
const settings = { ...mockSettings, groupBy: GroupBy.REPOSITORY };
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/utils/notifications/group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { GitifyNotification, SettingsState } from '../../types';

/**
* Returns true when settings say to group by date.
*/
export function isGroupByDate(settings: SettingsState) {
return settings.groupBy === 'DATE';
}

/**
* Returns true when settings say to group by repository.
*/
Expand Down