File tree Expand file tree Collapse file tree 3 files changed +15
-13
lines changed Expand file tree Collapse file tree 3 files changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { ipcRenderer } from 'electron';
8
8
import React , { useCallback , useContext , useMemo } from 'react' ;
9
9
import { useNavigate , useLocation } from 'react-router-dom' ;
10
10
11
+ import { getNotificationCount } from '../utils/notifications' ;
11
12
import { Logo } from '../components/Logo' ;
12
13
import { AppContext } from '../context/App' ;
13
14
import { Constants } from '../utils/constants' ;
@@ -33,10 +34,7 @@ export const Sidebar: React.FC = () => {
33
34
} , [ ] ) ;
34
35
35
36
const notificationsCount = useMemo ( ( ) => {
36
- return notifications . reduce (
37
- ( memo , account ) => memo + account . notifications . length ,
38
- 0 ,
39
- ) ;
37
+ return getNotificationCount ( notifications ) ;
40
38
} , [ notifications ] ) ;
41
39
42
40
const footerButtonClasses =
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { AccountNotifications } from '../components/AccountNotifications';
4
4
import { AllRead } from '../components/AllRead' ;
5
5
import { AppContext } from '../context/App' ;
6
6
import { Oops } from '../components/Oops' ;
7
+ import { getNotificationCount } from '../utils/notifications' ;
7
8
8
9
export const NotificationsRoute : React . FC = ( props ) => {
9
10
const { notifications, requestFailed } = useContext ( AppContext ) ;
@@ -12,11 +13,10 @@ export const NotificationsRoute: React.FC = (props) => {
12
13
( ) => notifications . length > 1 ,
13
14
[ notifications ] ,
14
15
) ;
15
- const notificationsCount = useMemo (
16
- ( ) =>
17
- notifications . reduce ( ( memo , acc ) => memo + acc . notifications . length , 0 ) ,
18
- [ notifications ] ,
19
- ) ;
16
+ const notificationsCount = useMemo ( ( ) => {
17
+ return getNotificationCount ( notifications ) ;
18
+ } , [ notifications ] ) ;
19
+
20
20
const hasNotifications = useMemo (
21
21
( ) => notificationsCount > 0 ,
22
22
[ notificationsCount ] ,
Original file line number Diff line number Diff line change @@ -6,14 +6,18 @@ import { Notification } from '../typesGithub';
6
6
import { AccountNotifications , SettingsState , AuthState } from '../types' ;
7
7
8
8
export const setTrayIconColor = ( notifications : AccountNotifications [ ] ) => {
9
- const allNotificationsCount = notifications . reduce (
10
- ( memo , acc ) => memo + acc . notifications . length ,
11
- 0 ,
12
- ) ;
9
+ const allNotificationsCount = getNotificationCount ( notifications ) ;
13
10
14
11
updateTrayIcon ( allNotificationsCount ) ;
15
12
} ;
16
13
14
+ export function getNotificationCount ( notifications : AccountNotifications [ ] ) {
15
+ return notifications . reduce (
16
+ ( memo , acc ) => memo + acc . notifications . length ,
17
+ 0 ,
18
+ ) ;
19
+ }
20
+
17
21
export const triggerNativeNotifications = (
18
22
previousNotifications : AccountNotifications [ ] ,
19
23
newNotifications : AccountNotifications [ ] ,
You can’t perform that action at this time.
0 commit comments