From b638348cc43ef02523cb617d7bc051213b7b86b2 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 8 Apr 2024 06:28:16 -0400 Subject: [PATCH 1/2] refactor(useNotifications): extract getNotifications into function --- src/hooks/useNotifications.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index d90bb7699..5c4caf11f 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import axios, { AxiosPromise } from 'axios'; import { useCallback, useState } from 'react'; import { AccountNotifications, AuthState, SettingsState } from '../types'; @@ -65,24 +65,26 @@ export const useNotifications = (colors: boolean): NotificationsState => { const fetchNotifications = useCallback( async (accounts: AuthState, settings: SettingsState) => { const isGitHubLoggedIn = accounts.token !== null; - const endpointSuffix = `notifications?participating=${settings.participating}`; + + function getNotifications(hostname: string, token: string): AxiosPromise { + const endpointSuffix = `notifications?participating=${settings.participating}`; + const url = `${generateGitHubAPIUrl(hostname)}${endpointSuffix}`; + return apiRequestAuth(url, 'GET', token); + } function getGitHubNotifications() { if (!isGitHubLoggedIn) { return; } - const url = `${generateGitHubAPIUrl( + return getNotifications( Constants.DEFAULT_AUTH_OPTIONS.hostname, - )}${endpointSuffix}`; - return apiRequestAuth(url, 'GET', accounts.token); + accounts.token, + ); } function getEnterpriseNotifications() { return accounts.enterpriseAccounts.map((account) => { - const url = `${generateGitHubAPIUrl( - account.hostname, - )}${endpointSuffix}`; - return apiRequestAuth(url, 'GET', account.token); + return getNotifications(account.hostname, account.token); }); } From aeb169e6f1fbf4431791c0a88660433f77bda74e Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 8 Apr 2024 09:07:16 -0400 Subject: [PATCH 2/2] fix linting --- src/hooks/useNotifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index 052ba4166..eed25e445 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -1,4 +1,4 @@ -import axios, { AxiosPromise } from 'axios'; +import axios, { type AxiosPromise } from 'axios'; import { useCallback, useState } from 'react'; import type { AccountNotifications, AuthState, SettingsState } from '../types';