Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
XCircleIcon,
} from '@primer/octicons-react';
import { ipcRenderer } from 'electron';
import React, { useCallback, useContext, useMemo } from 'react';
import React, { useCallback, useContext } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';

import { getNotificationCount } from '../utils/notifications';
import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
import { Constants } from '../utils/constants';
Expand All @@ -32,12 +33,7 @@ export const Sidebar: React.FC = () => {
ipcRenderer.send('app-quit');
}, []);

const notificationsCount = useMemo(() => {
return notifications.reduce(
(memo, account) => memo + account.notifications.length,
0,
);
}, [notifications]);
const notificationsCount = getNotificationCount(notifications);

const footerButtonClasses =
'flex justify-evenly items-center bg-transparent border-0 w-full text-sm text-white my-1 py-2 cursor-pointer hover:text-gray-500 focus:outline-none';
Expand Down
8 changes: 3 additions & 5 deletions src/routes/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AccountNotifications } from '../components/AccountNotifications';
import { AllRead } from '../components/AllRead';
import { AppContext } from '../context/App';
import { Oops } from '../components/Oops';
import { getNotificationCount } from '../utils/notifications';

export const NotificationsRoute: React.FC = (props) => {
const { notifications, requestFailed } = useContext(AppContext);
Expand All @@ -12,11 +13,8 @@ export const NotificationsRoute: React.FC = (props) => {
() => notifications.length > 1,
[notifications],
);
const notificationsCount = useMemo(
() =>
notifications.reduce((memo, acc) => memo + acc.notifications.length, 0),
[notifications],
);
const notificationsCount = getNotificationCount(notifications);

const hasNotifications = useMemo(
() => notificationsCount > 0,
[notificationsCount],
Expand Down
10 changes: 8 additions & 2 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import { Notification } from '../typesGithub';
import { AccountNotifications, SettingsState, AuthState } from '../types';

export const setTrayIconColor = (notifications: AccountNotifications[]) => {
const allNotificationsCount = getNotificationCount(notifications);

updateTrayIcon(allNotificationsCount);
};

export function getNotificationCount(notifications: AccountNotifications[]) {
const allNotificationsCount = notifications.reduce(
(memo, acc) => memo + acc.notifications.length,
0,
);

updateTrayIcon(allNotificationsCount);
};
return allNotificationsCount;
}

export const triggerNativeNotifications = (
previousNotifications: AccountNotifications[],
Expand Down