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';
88import React , { useCallback , useContext , useMemo } from 'react' ;
99import { useNavigate , useLocation } from 'react-router-dom' ;
1010
11+ import { getNotificationCount } from '../utils/notifications' ;
1112import { Logo } from '../components/Logo' ;
1213import { AppContext } from '../context/App' ;
1314import { Constants } from '../utils/constants' ;
@@ -33,10 +34,7 @@ export const Sidebar: React.FC = () => {
3334 } , [ ] ) ;
3435
3536 const notificationsCount = useMemo ( ( ) => {
36- return notifications . reduce (
37- ( memo , account ) => memo + account . notifications . length ,
38- 0 ,
39- ) ;
37+ return getNotificationCount ( notifications ) ;
4038 } , [ notifications ] ) ;
4139
4240 const footerButtonClasses =
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { AccountNotifications } from '../components/AccountNotifications';
44import { AllRead } from '../components/AllRead' ;
55import { AppContext } from '../context/App' ;
66import { Oops } from '../components/Oops' ;
7+ import { getNotificationCount } from '../utils/notifications' ;
78
89export const NotificationsRoute : React . FC = ( props ) => {
910 const { notifications, requestFailed } = useContext ( AppContext ) ;
@@ -12,11 +13,10 @@ export const NotificationsRoute: React.FC = (props) => {
1213 ( ) => notifications . length > 1 ,
1314 [ notifications ] ,
1415 ) ;
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+
2020 const hasNotifications = useMemo (
2121 ( ) => notificationsCount > 0 ,
2222 [ notificationsCount ] ,
Original file line number Diff line number Diff line change @@ -6,14 +6,18 @@ import { Notification } from '../typesGithub';
66import { AccountNotifications , SettingsState , AuthState } from '../types' ;
77
88export const setTrayIconColor = ( notifications : AccountNotifications [ ] ) => {
9- const allNotificationsCount = notifications . reduce (
10- ( memo , acc ) => memo + acc . notifications . length ,
11- 0 ,
12- ) ;
9+ const allNotificationsCount = getNotificationCount ( notifications ) ;
1310
1411 updateTrayIcon ( allNotificationsCount ) ;
1512} ;
1613
14+ export function getNotificationCount ( notifications : AccountNotifications [ ] ) {
15+ return notifications . reduce (
16+ ( memo , acc ) => memo + acc . notifications . length ,
17+ 0 ,
18+ ) ;
19+ }
20+
1721export const triggerNativeNotifications = (
1822 previousNotifications : AccountNotifications [ ] ,
1923 newNotifications : AccountNotifications [ ] ,
You can’t perform that action at this time.
0 commit comments