Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const Sidebar: FC = () => {

<SidebarButton
title={`${notificationsCount} Unread Notifications`}
metric={notificationsCount}
metric={isLoggedIn ? notificationsCount : null}
icon={BellIcon}
onClick={() => openGitHubNotifications(primaryAccountHostname)}
/>
Expand Down
12 changes: 4 additions & 8 deletions src/components/__snapshots__/Sidebar.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ interface AppContextState {
notifications: AccountNotifications[];
status: Status;
globalError: GitifyError;
removeAccountNotifications: (account: Account) => Promise<void>;
fetchNotifications: () => Promise<void>;
markNotificationRead: (notification: Notification) => Promise<void>;
markNotificationDone: (notification: Notification) => Promise<void>;
Expand All @@ -120,6 +121,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
const [auth, setAuth] = useState<AuthState>(defaultAuth);
const [settings, setSettings] = useState<SettingsState>(defaultSettings);
const {
removeAccountNotifications,
fetchNotifications,
notifications,
globalError,
Expand All @@ -130,7 +132,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
markRepoNotificationsRead,
markRepoNotificationsDone,
} = useNotifications();

getNotificationCount;
useEffect(() => {
restoreSettings();
}, []);
Expand Down Expand Up @@ -239,6 +241,10 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {

const logoutFromAccount = useCallback(
async (account: Account) => {
// Remove notifications for account
removeAccountNotifications(account);

// Remove from auth state
const updatedAuth = removeAccount(auth, account);
setAuth(updatedAuth);
saveState({ auth: updatedAuth, settings });
Expand Down
18 changes: 18 additions & 0 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useState } from 'react';
import type {
Account,
AccountNotifications,
GitifyError,
GitifyState,
Expand All @@ -24,6 +25,7 @@ import { removeNotifications } from '../utils/remove-notifications';

interface NotificationsState {
notifications: AccountNotifications[];
removeAccountNotifications: (account: Account) => Promise<void>;
fetchNotifications: (state: GitifyState) => Promise<void>;
markNotificationRead: (
state: GitifyState,
Expand Down Expand Up @@ -57,6 +59,21 @@ export const useNotifications = (): NotificationsState => {
[],
);

const removeAccountNotifications = useCallback(
async (account: Account) => {
setStatus('loading');

const updatedNotifications = notifications.filter(
(notification) => notification.account !== account,
);

setNotifications(updatedNotifications);
setTrayIconColor(updatedNotifications);
setStatus('success');
},
[notifications],
);

const fetchNotifications = useCallback(
async (state: GitifyState) => {
setStatus('loading');
Expand Down Expand Up @@ -243,6 +260,7 @@ export const useNotifications = (): NotificationsState => {
globalError,
notifications,

removeAccountNotifications,
fetchNotifications,
markNotificationRead,
markNotificationDone,
Expand Down