Skip to content
Merged
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
20 changes: 11 additions & 9 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios, { type AxiosPromise } from 'axios';
import { useCallback, useState } from 'react';

import type { AccountNotifications, AuthState, SettingsState } from '../types';
Expand Down Expand Up @@ -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);
});
}

Expand Down