Skip to content

Commit ecd725d

Browse files
authored
feat: mark notification as read to allow transition effects time (#1389)
* feat: mark notification as read to allow transition effects time * feat: remove unused removeNotificationFromState
1 parent 69d82ab commit ecd725d

File tree

5 files changed

+11
-83
lines changed

5 files changed

+11
-83
lines changed

src/components/NotificationRow.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('components/NotificationRow.tsx', () => {
8282

8383
describe('notification interactions', () => {
8484
it('should open a notification in the browser - click', () => {
85-
const removeNotificationFromState = jest.fn();
85+
const markNotificationRead = jest.fn();
8686

8787
const props = {
8888
notification: mockSingleNotification,
@@ -93,7 +93,7 @@ describe('components/NotificationRow.tsx', () => {
9393
<AppContext.Provider
9494
value={{
9595
settings: { ...mockSettings, markAsDoneOnOpen: false },
96-
removeNotificationFromState,
96+
markNotificationRead,
9797
auth: mockAuth,
9898
}}
9999
>
@@ -103,11 +103,11 @@ describe('components/NotificationRow.tsx', () => {
103103

104104
fireEvent.click(screen.getByRole('main'));
105105
expect(links.openNotification).toHaveBeenCalledTimes(1);
106-
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
106+
expect(markNotificationRead).toHaveBeenCalledTimes(1);
107107
});
108108

109109
it('should open a notification in the browser - delay notification setting enabled', () => {
110-
const removeNotificationFromState = jest.fn();
110+
const markNotificationRead = jest.fn();
111111

112112
const props = {
113113
notification: mockSingleNotification,
@@ -122,7 +122,7 @@ describe('components/NotificationRow.tsx', () => {
122122
markAsDoneOnOpen: false,
123123
delayNotificationState: true,
124124
},
125-
removeNotificationFromState,
125+
markNotificationRead,
126126
auth: mockAuth,
127127
}}
128128
>
@@ -132,11 +132,11 @@ describe('components/NotificationRow.tsx', () => {
132132

133133
fireEvent.click(screen.getByRole('main'));
134134
expect(links.openNotification).toHaveBeenCalledTimes(1);
135-
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
135+
expect(markNotificationRead).toHaveBeenCalledTimes(1);
136136
});
137137

138138
it('should open a notification in the browser - key down', () => {
139-
const removeNotificationFromState = jest.fn();
139+
const markNotificationRead = jest.fn();
140140

141141
const props = {
142142
notification: mockSingleNotification,
@@ -147,7 +147,7 @@ describe('components/NotificationRow.tsx', () => {
147147
<AppContext.Provider
148148
value={{
149149
settings: { ...mockSettings, markAsDoneOnOpen: false },
150-
removeNotificationFromState,
150+
markNotificationRead,
151151
auth: mockAuth,
152152
}}
153153
>
@@ -157,7 +157,7 @@ describe('components/NotificationRow.tsx', () => {
157157

158158
fireEvent.click(screen.getByRole('main'));
159159
expect(links.openNotification).toHaveBeenCalledTimes(1);
160-
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
160+
expect(markNotificationRead).toHaveBeenCalledTimes(1);
161161
});
162162

163163
it('should open a notification in browser & mark it as done', () => {

src/components/NotificationRow.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const NotificationRow: FC<INotificationRow> = ({
3434
}: INotificationRow) => {
3535
const {
3636
settings,
37-
removeNotificationFromState,
3837
markNotificationRead,
3938
markNotificationDone,
4039
unsubscribeNotification,
@@ -51,15 +50,9 @@ export const NotificationRow: FC<INotificationRow> = ({
5150
if (settings.markAsDoneOnOpen) {
5251
markNotificationDone(notification);
5352
} else {
54-
// no need to mark as read, github does it by default when opening it
55-
removeNotificationFromState(settings, notification);
53+
markNotificationRead(notification);
5654
}
57-
}, [
58-
notification,
59-
markNotificationDone,
60-
removeNotificationFromState,
61-
settings,
62-
]);
55+
}, [notification, markNotificationDone, markNotificationRead, settings]);
6356

6457
const unsubscribeFromThread = (event: MouseEvent<HTMLElement>) => {
6558
// Don't trigger onClick of parent element.

src/context/App.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ interface AppContextState {
102102
notifications: AccountNotifications[];
103103
status: Status;
104104
errorDetails: GitifyError;
105-
removeNotificationFromState: (
106-
settings: SettingsState,
107-
notification: Notification,
108-
) => void;
109105
fetchNotifications: () => Promise<void>;
110106
markNotificationRead: (notification: Notification) => Promise<void>;
111107
markNotificationDone: (notification: Notification) => Promise<void>;
@@ -129,7 +125,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
129125
notifications,
130126
errorDetails,
131127
status,
132-
removeNotificationFromState,
133128
markNotificationRead,
134129
markNotificationDone,
135130
unsubscribeNotification,
@@ -317,7 +312,6 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
317312
notifications,
318313
status,
319314
errorDetails,
320-
removeNotificationFromState,
321315
fetchNotifications: fetchNotificationsWithAccounts,
322316
markNotificationRead: markNotificationReadWithAccounts,
323317
markNotificationDone: markNotificationDoneWithAccounts,

src/hooks/useNotifications.test.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -297,45 +297,6 @@ describe('hooks/useNotifications.ts', () => {
297297
});
298298
});
299299

300-
describe('removeNotificationFromState', () => {
301-
it('should remove a notification from state', async () => {
302-
const notifications = [
303-
{ id: 1, title: 'This is a notification.' },
304-
{ id: 2, title: 'This is another one.' },
305-
];
306-
307-
nock('https://api.github.com')
308-
.get('/notifications?participating=false')
309-
.reply(200, notifications);
310-
311-
nock('https://github.gitify.io/api/v3')
312-
.get('/notifications?participating=false')
313-
.reply(200, notifications);
314-
315-
const { result } = renderHook(() => useNotifications());
316-
317-
act(() => {
318-
result.current.fetchNotifications({
319-
...mockState,
320-
settings: { ...mockSettings, detailedNotifications: false },
321-
});
322-
});
323-
324-
await waitFor(() => {
325-
expect(result.current.status).toBe('success');
326-
});
327-
328-
act(() => {
329-
result.current.removeNotificationFromState(
330-
mockSettings,
331-
result.current.notifications[0].notifications[0],
332-
);
333-
});
334-
335-
expect(result.current.notifications[0].notifications.length).toBe(1);
336-
});
337-
});
338-
339300
describe('markNotificationRead', () => {
340301
it('should mark a notification as read with success', async () => {
341302
nock('https://api.github.com/')

src/hooks/useNotifications.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
AccountNotifications,
44
GitifyError,
55
GitifyState,
6-
SettingsState,
76
Status,
87
} from '../types';
98
import type { Notification } from '../typesGitHub';
@@ -25,10 +24,6 @@ import { removeNotifications } from '../utils/remove-notifications';
2524

2625
interface NotificationsState {
2726
notifications: AccountNotifications[];
28-
removeNotificationFromState: (
29-
settings: SettingsState,
30-
notification: Notification,
31-
) => void;
3227
fetchNotifications: (state: GitifyState) => Promise<void>;
3328
markNotificationRead: (
3429
state: GitifyState,
@@ -226,26 +221,11 @@ export const useNotifications = (): NotificationsState => {
226221
[notifications, markNotificationDone],
227222
);
228223

229-
const removeNotificationFromState = useCallback(
230-
(settings: SettingsState, notification: Notification) => {
231-
const updatedNotifications = removeNotification(
232-
settings,
233-
notification,
234-
notifications,
235-
);
236-
237-
setNotifications(updatedNotifications);
238-
setTrayIconColor(updatedNotifications);
239-
},
240-
[notifications],
241-
);
242-
243224
return {
244225
status,
245226
errorDetails,
246227
notifications,
247228

248-
removeNotificationFromState,
249229
fetchNotifications,
250230
markNotificationRead,
251231
markNotificationDone,

0 commit comments

Comments
 (0)