Migrated ShlinkApiClient from axios to fetch

This commit is contained in:
Alejandro Celaya
2022-11-13 16:57:16 +01:00
parent ba48104c5c
commit 16bee43f12
5 changed files with 58 additions and 46 deletions

View File

@@ -1,4 +1,3 @@
import { AxiosInstance } from 'axios';
import { hasServerData, ServerWithId } from '../../servers/data';
import { GetState } from '../../container/types';
import { ShlinkApiClient } from './ShlinkApiClient';
@@ -16,14 +15,14 @@ const getSelectedServerFromState = (getState: GetState): ServerWithId => {
return selectedServer;
};
export const buildShlinkApiClient = (axios: AxiosInstance) => (getStateOrSelectedServer: GetState | ServerWithId) => {
export const buildShlinkApiClient = (fetch: typeof window.fetch) => (getStateOrSelectedServer: GetState | ServerWithId) => {
const { url, apiKey } = isGetState(getStateOrSelectedServer)
? getSelectedServerFromState(getStateOrSelectedServer)
: getStateOrSelectedServer;
const clientKey = `${url}_${apiKey}`;
if (!apiClients[clientKey]) {
apiClients[clientKey] = new ShlinkApiClient(axios, url, apiKey);
apiClients[clientKey] = new ShlinkApiClient(fetch, url, apiKey);
}
return apiClients[clientKey];