Skip to content

Commit 9c2248c

Browse files
authored
feat: delay notification removal (#1092)
* feat: delay notification removal * feat: delay notification removal * feat: delay notification removal * feat: delay notification removal * chore: remove comment
1 parent c5b33a9 commit 9c2248c

File tree

14 files changed

+305
-34
lines changed

14 files changed

+305
-34
lines changed

src/__mocks__/mock-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export const mockSettings: SettingsState = {
1818
detailedNotifications: false,
1919
markAsDoneOnOpen: false,
2020
showAccountHostname: false,
21+
delayNotificationState: false,
2122
};

src/components/NotificationRow.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
4747
markNotificationDone(notification.id, hostname);
4848
} else {
4949
// no need to mark as read, github does it by default when opening it
50-
removeNotificationFromState(notification.id, hostname);
50+
removeNotificationFromState(settings, notification.id, hostname);
5151
}
5252
}, [notifications, notification, accounts, settings]); // notifications required here to prevent weird state issues
5353

@@ -84,7 +84,10 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
8484
]);
8585

8686
return (
87-
<div className="flex space-x-3 py-2 px-3 bg-white dark:bg-gray-dark dark:text-white hover:bg-gray-100 dark:hover:bg-gray-darker border-b border-gray-100 dark:border-gray-darker group">
87+
<div
88+
id={notification.id}
89+
className="flex space-x-3 py-2 px-3 bg-white dark:bg-gray-dark dark:text-white hover:bg-gray-100 dark:hover:bg-gray-darker border-b border-gray-100 dark:border-gray-darker group"
90+
>
8891
<div
8992
className={`flex justify-center items-center w-5 ${iconColor}`}
9093
title={notificationTitle}

src/components/__snapshots__/NotificationRow.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context/App.test.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ describe('context/App.tsx', () => {
131131

132132
expect(markNotificationReadMock).toHaveBeenCalledTimes(1);
133133
expect(markNotificationReadMock).toHaveBeenCalledWith(
134-
{ enterpriseAccounts: [], token: null, user: null },
134+
{
135+
enterpriseAccounts: [],
136+
token: null,
137+
user: null,
138+
},
139+
mockSettings,
135140
'123-456',
136141
'github.com',
137142
);
@@ -160,6 +165,7 @@ describe('context/App.tsx', () => {
160165
expect(markNotificationDoneMock).toHaveBeenCalledTimes(1);
161166
expect(markNotificationDoneMock).toHaveBeenCalledWith(
162167
{ enterpriseAccounts: [], token: null, user: null },
168+
mockSettings,
163169
'123-456',
164170
'github.com',
165171
);
@@ -188,6 +194,7 @@ describe('context/App.tsx', () => {
188194
expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1);
189195
expect(unsubscribeNotificationMock).toHaveBeenCalledWith(
190196
{ enterpriseAccounts: [], token: null, user: null },
197+
mockSettings,
191198
'123-456',
192199
'github.com',
193200
);
@@ -221,6 +228,7 @@ describe('context/App.tsx', () => {
221228
expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1);
222229
expect(markRepoNotificationsMock).toHaveBeenCalledWith(
223230
{ enterpriseAccounts: [], token: null, user: null },
231+
mockSettings,
224232
'gitify-app/notifications-test',
225233
'github.com',
226234
);
@@ -325,6 +333,7 @@ describe('context/App.tsx', () => {
325333
detailedNotifications: false,
326334
markAsDoneOnOpen: false,
327335
showAccountHostname: false,
336+
delayNotificationState: false,
328337
},
329338
);
330339
});
@@ -369,6 +378,7 @@ describe('context/App.tsx', () => {
369378
detailedNotifications: false,
370379
markAsDoneOnOpen: false,
371380
showAccountHostname: false,
381+
delayNotificationState: false,
372382
},
373383
);
374384
});

src/context/App.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const defaultSettings: SettingsState = {
4444
detailedNotifications: false,
4545
markAsDoneOnOpen: false,
4646
showAccountHostname: false,
47+
delayNotificationState: false,
4748
};
4849

4950
interface AppContextState {
@@ -57,7 +58,11 @@ interface AppContextState {
5758
notifications: AccountNotifications[];
5859
status: Status;
5960
errorDetails: GitifyError;
60-
removeNotificationFromState: (id: string, hostname: string) => void;
61+
removeNotificationFromState: (
62+
settings: SettingsState,
63+
id: string,
64+
hostname: string,
65+
) => void;
6166
fetchNotifications: () => Promise<void>;
6267
markNotificationRead: (id: string, hostname: string) => Promise<void>;
6368
markNotificationDone: (id: string, hostname: string) => Promise<void>;
@@ -199,31 +204,31 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
199204

200205
const markNotificationReadWithAccounts = useCallback(
201206
async (id: string, hostname: string) =>
202-
await markNotificationRead(accounts, id, hostname),
207+
await markNotificationRead(accounts, settings, id, hostname),
203208
[accounts, notifications],
204209
);
205210

206211
const markNotificationDoneWithAccounts = useCallback(
207212
async (id: string, hostname: string) =>
208-
await markNotificationDone(accounts, id, hostname),
213+
await markNotificationDone(accounts, settings, id, hostname),
209214
[accounts, notifications],
210215
);
211216

212217
const unsubscribeNotificationWithAccounts = useCallback(
213218
async (id: string, hostname: string) =>
214-
await unsubscribeNotification(accounts, id, hostname),
219+
await unsubscribeNotification(accounts, settings, id, hostname),
215220
[accounts, notifications],
216221
);
217222

218223
const markRepoNotificationsWithAccounts = useCallback(
219224
async (repoSlug: string, hostname: string) =>
220-
await markRepoNotifications(accounts, repoSlug, hostname),
225+
await markRepoNotifications(accounts, settings, repoSlug, hostname),
221226
[accounts, notifications],
222227
);
223228

224229
const markRepoNotificationsDoneWithAccounts = useCallback(
225230
async (repoSlug: string, hostname: string) =>
226-
await markRepoNotificationsDone(accounts, repoSlug, hostname),
231+
await markRepoNotificationsDone(accounts, settings, repoSlug, hostname),
227232
[accounts, notifications],
228233
);
229234

0 commit comments

Comments
 (0)