Skip to content

Commit caff503

Browse files
authored
fix: regression in delay notification state behavior (#1241)
1 parent e671125 commit caff503

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

src/components/NotificationRow.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,35 @@ describe('components/NotificationRow.tsx', () => {
350350
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
351351
});
352352

353+
it('should open a notification in the browser - delay notification setting enabled', () => {
354+
const removeNotificationFromState = jest.fn();
355+
356+
const props = {
357+
notification: mockSingleNotification,
358+
account: mockGitHubCloudAccount,
359+
};
360+
361+
render(
362+
<AppContext.Provider
363+
value={{
364+
settings: {
365+
...mockSettings,
366+
markAsDoneOnOpen: false,
367+
delayNotificationState: true,
368+
},
369+
removeNotificationFromState,
370+
auth: mockAuth,
371+
}}
372+
>
373+
<NotificationRow {...props} />
374+
</AppContext.Provider>,
375+
);
376+
377+
fireEvent.click(screen.getByRole('main'));
378+
expect(links.openNotification).toHaveBeenCalledTimes(1);
379+
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
380+
});
381+
353382
it('should open a notification in the browser - key down', () => {
354383
const removeNotificationFromState = jest.fn();
355384

src/components/NotificationRow.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
4545
unsubscribeNotification,
4646
} = useContext(AppContext);
4747
const [animateExit, setAnimateExit] = useState(false);
48+
const [showAsRead, setShowAsRead] = useState(false);
4849

4950
const handleNotification = useCallback(() => {
50-
setAnimateExit(true);
51+
setAnimateExit(!settings.delayNotificationState);
52+
setShowAsRead(settings.delayNotificationState);
53+
5154
openNotification(notification);
5255

5356
if (settings.markAsDoneOnOpen) {
@@ -102,6 +105,7 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
102105
'group flex border-b border-gray-100 bg-white px-3 py-2 hover:bg-gray-100 dark:border-gray-darker dark:bg-gray-dark dark:text-white dark:hover:bg-gray-darker',
103106
animateExit &&
104107
'translate-x-full opacity-0 transition duration-[350ms] ease-in-out',
108+
showAsRead && 'opacity-50 dark:opacity-50',
105109
)}
106110
>
107111
<div
@@ -218,7 +222,8 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
218222
className="h-full hover:text-green-500 focus:outline-none"
219223
title="Mark as Done"
220224
onClick={() => {
221-
setAnimateExit(true);
225+
setAnimateExit(!settings.delayNotificationState);
226+
setShowAsRead(settings.delayNotificationState);
222227
markNotificationDone(notification);
223228
}}
224229
>
@@ -239,7 +244,8 @@ export const NotificationRow: FC<IProps> = ({ notification }) => {
239244
className="h-full hover:text-green-500 focus:outline-none"
240245
title="Mark as Read"
241246
onClick={() => {
242-
setAnimateExit(true);
247+
setAnimateExit(!settings.delayNotificationState);
248+
setShowAsRead(settings.delayNotificationState);
243249
markNotificationRead(notification);
244250
}}
245251
>

src/context/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
122122
settings.participating,
123123
settings.showBots,
124124
settings.detailedNotifications,
125+
settings.delayNotificationState,
125126
auth.accounts.length,
126127
]);
127128

src/styles/gitify.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ export const BUTTON_CLASS_NAME =
33

44
export const BUTTON_SIDEBAR_CLASS_NAME =
55
'flex justify-evenly items-center bg-transparent border-0 w-full text-sm text-white my-1 py-2 cursor-pointer hover:text-gray-500 focus:outline-none disabled:text-gray-500 disabled:cursor-default';
6-
7-
export const READ_NOTIFICATION_CLASS_NAME = 'opacity-50 dark:opacity-50';

src/utils/remove-notification.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { mockSingleAccountNotifications } from '../__mocks__/notifications-mocks';
22
import { mockSettings } from '../__mocks__/state-mocks';
3-
import { READ_NOTIFICATION_CLASS_NAME } from '../styles/gitify';
43
import { mockSingleNotification } from './api/__mocks__/response-mocks';
54
import { removeNotification } from './remove-notification';
65

@@ -17,11 +16,7 @@ describe('utils/remove-notification.ts', () => {
1716
expect(result[0].notifications.length).toBe(0);
1817
});
1918

20-
it('should set notification as opaque if delayNotificationState enabled', () => {
21-
const mockElement = document.createElement('div');
22-
mockElement.id = mockSingleAccountNotifications[0].notifications[0].id;
23-
jest.spyOn(document, 'getElementById').mockReturnValue(mockElement);
24-
19+
it('should skip notification removal if delay state enabled', () => {
2520
expect(mockSingleAccountNotifications[0].notifications.length).toBe(1);
2621

2722
const result = removeNotification(
@@ -31,9 +26,5 @@ describe('utils/remove-notification.ts', () => {
3126
);
3227

3328
expect(result[0].notifications.length).toBe(1);
34-
expect(document.getElementById).toHaveBeenCalledWith(
35-
mockSingleAccountNotifications[0].notifications[0].id,
36-
);
37-
expect(mockElement.className).toContain(READ_NOTIFICATION_CLASS_NAME);
3829
});
3930
});

src/utils/remove-notification.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { READ_NOTIFICATION_CLASS_NAME } from '../styles/gitify';
21
import type { AccountNotifications, SettingsState } from '../types';
32
import type { Notification } from '../typesGitHub';
43
import { getAccountUUID } from './auth/utils';
@@ -9,8 +8,6 @@ export const removeNotification = (
98
notifications: AccountNotifications[],
109
): AccountNotifications[] => {
1110
if (settings.delayNotificationState) {
12-
const notificationRow = document.getElementById(notification.id);
13-
notificationRow.className += ` ${READ_NOTIFICATION_CLASS_NAME}`;
1411
return notifications;
1512
}
1613

0 commit comments

Comments
 (0)