|
1 |
| -import axios from 'axios'; |
| 1 | +import axios, { type AxiosPromise } from 'axios'; |
2 | 2 | import { useCallback, useState } from 'react';
|
3 | 3 |
|
4 | 4 | import type { AccountNotifications, AuthState, SettingsState } from '../types';
|
@@ -65,24 +65,26 @@ export const useNotifications = (colors: boolean): NotificationsState => {
|
65 | 65 | const fetchNotifications = useCallback(
|
66 | 66 | async (accounts: AuthState, settings: SettingsState) => {
|
67 | 67 | 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 | + } |
69 | 74 |
|
70 | 75 | function getGitHubNotifications() {
|
71 | 76 | if (!isGitHubLoggedIn) {
|
72 | 77 | return;
|
73 | 78 | }
|
74 |
| - const url = `${generateGitHubAPIUrl( |
| 79 | + return getNotifications( |
75 | 80 | Constants.DEFAULT_AUTH_OPTIONS.hostname,
|
76 |
| - )}${endpointSuffix}`; |
77 |
| - return apiRequestAuth(url, 'GET', accounts.token); |
| 81 | + accounts.token, |
| 82 | + ); |
78 | 83 | }
|
79 | 84 |
|
80 | 85 | function getEnterpriseNotifications() {
|
81 | 86 | 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); |
86 | 88 | });
|
87 | 89 | }
|
88 | 90 |
|
|
0 commit comments