diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index ff2558c0b..b322f0fe2 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -37,7 +37,7 @@ interface IProps { export const NotificationRow: FC = ({ notification, hostname }) => { const { settings, - auth: accounts, + auth, removeNotificationFromState, markNotificationRead, markNotificationDone, @@ -46,7 +46,7 @@ export const NotificationRow: FC = ({ notification, hostname }) => { } = useContext(AppContext); const openNotification = useCallback(() => { - openInBrowser(notification, accounts); + openInBrowser(notification, auth); if (settings.markAsDoneOnOpen) { markNotificationDone(notification.id, hostname); @@ -54,7 +54,7 @@ export const NotificationRow: FC = ({ notification, hostname }) => { // no need to mark as read, github does it by default when opening it removeNotificationFromState(settings, notification.id, hostname); } - }, [notifications, notification, accounts, settings]); // notifications required here to prevent weird state issues + }, [notifications, notification, auth, settings]); // notifications required here to prevent weird state issues const unsubscribeFromThread = (event: MouseEvent) => { // Don't trigger onClick of parent element. diff --git a/src/context/App.tsx b/src/context/App.tsx index a3b829006..789188467 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -79,7 +79,7 @@ interface AppContextState { export const AppContext = createContext>({}); export const AppProvider = ({ children }: { children: ReactNode }) => { - const [accounts, setAccounts] = useState(defaultAuth); + const [auth, setAuth] = useState(defaultAuth); const [settings, setSettings] = useState(defaultSettings); const { fetchNotifications, @@ -104,17 +104,17 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { // biome-ignore lint/correctness/useExhaustiveDependencies: We only want fetchNotifications to be called for certain account or setting changes. useEffect(() => { - fetchNotifications(accounts, settings); + fetchNotifications(auth, settings); }, [ settings.participating, settings.showBots, settings.detailedNotifications, - accounts.token, - accounts.enterpriseAccounts.length, + auth.token, + auth.enterpriseAccounts.length, ]); useInterval(() => { - fetchNotifications(accounts, settings); + fetchNotifications(auth, settings); }, Constants.FETCH_INTERVAL); // biome-ignore lint/correctness/useExhaustiveDependencies: We need to update tray title when settings or notifications changes. @@ -136,34 +136,34 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const newSettings = { ...settings, [name]: value }; setSettings(newSettings); - saveState({ auth: accounts, settings: newSettings }); + saveState({ auth, settings: newSettings }); }, - [accounts, settings], + [auth, settings], ); const isLoggedIn = useMemo(() => { - return !!accounts.token || accounts.enterpriseAccounts.length > 0; - }, [accounts]); + return !!auth.token || auth.enterpriseAccounts.length > 0; + }, [auth]); const login = useCallback(async () => { const { authCode } = await authGitHub(); const { token } = await getToken(authCode); const hostname = Constants.DEFAULT_AUTH_OPTIONS.hostname; const user = await getUserData(token, hostname); - const updatedAccounts = addAccount(accounts, token, hostname, user); - setAccounts(updatedAccounts); - saveState({ auth: updatedAccounts, settings }); - }, [accounts, settings]); + const updatedAuth = addAccount(auth, token, hostname, user); + setAuth(updatedAuth); + saveState({ auth: updatedAuth, settings }); + }, [auth, settings]); const loginEnterprise = useCallback( async (data: AuthOptions) => { const { authOptions, authCode } = await authGitHub(data); const { token, hostname } = await getToken(authCode, authOptions); - const updatedAccounts = addAccount(accounts, token, hostname); - setAccounts(updatedAccounts); - saveState({ auth: updatedAccounts, settings }); + const updatedAuth = addAccount(auth, token, hostname); + setAuth(updatedAuth); + saveState({ auth: updatedAuth, settings }); }, - [accounts, settings], + [auth, settings], ); const validateToken = useCallback( @@ -171,15 +171,15 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { await headNotifications(hostname, token); const user = await getUserData(token, hostname); - const updatedAccounts = addAccount(accounts, token, hostname, user); - setAccounts(updatedAccounts); + const updatedAccounts = addAccount(auth, token, hostname, user); + setAuth(updatedAccounts); saveState({ auth: updatedAccounts, settings }); }, - [accounts, settings], + [auth, settings], ); const logout = useCallback(() => { - setAccounts(defaultAuth); + setAuth(defaultAuth); clearState(); }, []); @@ -187,7 +187,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const existing = loadState(); if (existing.auth) { - setAccounts({ ...defaultAuth, ...existing.auth }); + setAuth({ ...defaultAuth, ...existing.auth }); } if (existing.settings) { @@ -197,44 +197,44 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { }, []); const fetchNotificationsWithAccounts = useCallback( - async () => await fetchNotifications(accounts, settings), - [accounts, settings, notifications], + async () => await fetchNotifications(auth, settings), + [auth, settings, notifications], ); const markNotificationReadWithAccounts = useCallback( async (id: string, hostname: string) => - await markNotificationRead(accounts, settings, id, hostname), - [accounts, notifications], + await markNotificationRead(auth, settings, id, hostname), + [auth, notifications], ); const markNotificationDoneWithAccounts = useCallback( async (id: string, hostname: string) => - await markNotificationDone(accounts, settings, id, hostname), - [accounts, notifications], + await markNotificationDone(auth, settings, id, hostname), + [auth, notifications], ); const unsubscribeNotificationWithAccounts = useCallback( async (id: string, hostname: string) => - await unsubscribeNotification(accounts, settings, id, hostname), - [accounts, notifications], + await unsubscribeNotification(auth, settings, id, hostname), + [auth, notifications], ); const markRepoNotificationsWithAccounts = useCallback( async (repoSlug: string, hostname: string) => - await markRepoNotifications(accounts, settings, repoSlug, hostname), - [accounts, notifications], + await markRepoNotifications(auth, settings, repoSlug, hostname), + [auth, notifications], ); const markRepoNotificationsDoneWithAccounts = useCallback( async (repoSlug: string, hostname: string) => - await markRepoNotificationsDone(accounts, settings, repoSlug, hostname), - [accounts, notifications], + await markRepoNotificationsDone(auth, settings, repoSlug, hostname), + [auth, notifications], ); return ( { - const { - auth: accounts, - settings, - updateSetting, - logout, - } = useContext(AppContext); + const { auth, settings, updateSetting, logout } = useContext(AppContext); const navigate = useNavigate(); const [appVersion, setAppVersion] = useState(null); @@ -301,7 +296,7 @@ export const SettingsRoute: FC = () => { className={footerButtonClass} title="Login with Personal Access Token" onClick={loginWithPersonalAccessToken} - hidden={isPersonalAccessTokenLoggedIn(accounts)} + hidden={isPersonalAccessTokenLoggedIn(auth)} > @@ -312,7 +307,7 @@ export const SettingsRoute: FC = () => { className={footerButtonClass} title="Login with OAuth App" onClick={loginWithOAuthApp} - hidden={isOAuthAppLoggedIn(accounts)} + hidden={isOAuthAppLoggedIn(auth)} >