@@ -8,6 +8,7 @@ import { apiRequestAuth } from '../utils/api-requests';
8
8
import {
9
9
getEnterpriseAccountToken ,
10
10
generateGitHubAPIUrl ,
11
+ isEnterpriseHost ,
11
12
} from '../utils/helpers' ;
12
13
import { removeNotification } from '../utils/remove-notification' ;
13
14
import {
@@ -19,6 +20,7 @@ import { removeNotifications } from '../utils/remove-notifications';
19
20
20
21
interface NotificationsState {
21
22
notifications : AccountNotifications [ ] ;
23
+ removeNotificationFromState : ( id : string , hostname : string ) => void ;
22
24
fetchNotifications : (
23
25
accounts : AuthState ,
24
26
settings : SettingsState ,
@@ -109,7 +111,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
109
111
]
110
112
: [ ...enterpriseNotifications ] ;
111
113
112
- if ( ! colors ) {
114
+ if ( colors === false ) {
113
115
setNotifications ( data ) ;
114
116
triggerNativeNotifications (
115
117
notifications ,
@@ -134,9 +136,9 @@ export const useNotifications = (colors: boolean): NotificationsState => {
134
136
) {
135
137
return notification ;
136
138
}
137
- const isEnterprise =
138
- accountNotifications . hostname !==
139
- Constants . DEFAULT_AUTH_OPTIONS . hostname ;
139
+ const isEnterprise = isEnterpriseHost (
140
+ accountNotifications . hostname ,
141
+ ) ;
140
142
const token = isEnterprise
141
143
? getEnterpriseAccountToken (
142
144
accountNotifications . hostname ,
@@ -196,7 +198,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
196
198
async ( accounts , id , hostname ) => {
197
199
setIsFetching ( true ) ;
198
200
199
- const isEnterprise = hostname !== Constants . DEFAULT_AUTH_OPTIONS . hostname ;
201
+ const isEnterprise = isEnterpriseHost ( hostname ) ;
200
202
const token = isEnterprise
201
203
? getEnterpriseAccountToken ( hostname , accounts . enterpriseAccounts )
202
204
: accounts . token ;
@@ -229,7 +231,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
229
231
async ( accounts , id , hostname ) => {
230
232
setIsFetching ( true ) ;
231
233
232
- const isEnterprise = hostname !== Constants . DEFAULT_AUTH_OPTIONS . hostname ;
234
+ const isEnterprise = isEnterpriseHost ( hostname ) ;
233
235
const token = isEnterprise
234
236
? getEnterpriseAccountToken ( hostname , accounts . enterpriseAccounts )
235
237
: accounts . token ;
@@ -262,7 +264,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
262
264
async ( accounts , id , hostname ) => {
263
265
setIsFetching ( true ) ;
264
266
265
- const isEnterprise = hostname !== Constants . DEFAULT_AUTH_OPTIONS . hostname ;
267
+ const isEnterprise = isEnterpriseHost ( hostname ) ;
266
268
const token = isEnterprise
267
269
? getEnterpriseAccountToken ( hostname , accounts . enterpriseAccounts )
268
270
: accounts . token ;
@@ -288,7 +290,7 @@ export const useNotifications = (colors: boolean): NotificationsState => {
288
290
async ( accounts , repoSlug , hostname ) => {
289
291
setIsFetching ( true ) ;
290
292
291
- const isEnterprise = hostname !== Constants . DEFAULT_AUTH_OPTIONS . hostname ;
293
+ const isEnterprise = isEnterpriseHost ( hostname ) ;
292
294
const token = isEnterprise
293
295
? getEnterpriseAccountToken ( hostname , accounts . enterpriseAccounts )
294
296
: accounts . token ;
@@ -360,11 +362,26 @@ export const useNotifications = (colors: boolean): NotificationsState => {
360
362
[ notifications ] ,
361
363
) ;
362
364
365
+ const removeNotificationFromState = useCallback (
366
+ ( id , hostname ) => {
367
+ const updatedNotifications = removeNotification (
368
+ id ,
369
+ notifications ,
370
+ hostname ,
371
+ ) ;
372
+
373
+ setNotifications ( updatedNotifications ) ;
374
+ setTrayIconColor ( updatedNotifications ) ;
375
+ } ,
376
+ [ notifications ] ,
377
+ ) ;
378
+
363
379
return {
364
380
isFetching,
365
381
requestFailed,
366
382
notifications,
367
383
384
+ removeNotificationFromState,
368
385
fetchNotifications,
369
386
markNotification,
370
387
markNotificationDone,
0 commit comments