Skip to content

Commit f54e4d6

Browse files
authored
refactor(useNotifications): extract getNotifications into function (#981)
* refactor(useNotifications): extract getNotifications into function * fix linting
1 parent c76325a commit f54e4d6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/hooks/useNotifications.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import axios, { type AxiosPromise } from 'axios';
22
import { useCallback, useState } from 'react';
33

44
import type { AccountNotifications, AuthState, SettingsState } from '../types';
@@ -65,24 +65,26 @@ export const useNotifications = (colors: boolean): NotificationsState => {
6565
const fetchNotifications = useCallback(
6666
async (accounts: AuthState, settings: SettingsState) => {
6767
const isGitHubLoggedIn = accounts.token !== null;
68-
const endpointSuffix = `notifications?participating=${settings.participating}`;
68+
69+
function getNotifications(hostname: string, token: string): AxiosPromise {
70+
const endpointSuffix = `notifications?participating=${settings.participating}`;
71+
const url = `${generateGitHubAPIUrl(hostname)}${endpointSuffix}`;
72+
return apiRequestAuth(url, 'GET', token);
73+
}
6974

7075
function getGitHubNotifications() {
7176
if (!isGitHubLoggedIn) {
7277
return;
7378
}
74-
const url = `${generateGitHubAPIUrl(
79+
return getNotifications(
7580
Constants.DEFAULT_AUTH_OPTIONS.hostname,
76-
)}${endpointSuffix}`;
77-
return apiRequestAuth(url, 'GET', accounts.token);
81+
accounts.token,
82+
);
7883
}
7984

8085
function getEnterpriseNotifications() {
8186
return accounts.enterpriseAccounts.map((account) => {
82-
const url = `${generateGitHubAPIUrl(
83-
account.hostname,
84-
)}${endpointSuffix}`;
85-
return apiRequestAuth(url, 'GET', account.token);
87+
return getNotifications(account.hostname, account.token);
8688
});
8789
}
8890

0 commit comments

Comments
 (0)