Replace axios with fetch

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-05-11 23:37:37 +02:00
parent 2f57d0a5bd
commit f3165877f2
144 changed files with 1146 additions and 2754 deletions

View File

@ -2,7 +2,7 @@ import { useEffect } from 'react';
import type { Location } from 'soapbox/types/history';
const LOCAL_STORAGE_REDIRECT_KEY = 'soapbox:redirect-uri';
const LOCAL_STORAGE_REDIRECT_KEY = 'plfe:redirect-uri';
const cacheCurrentUrl = (location: Location) => {
const actualUrl = encodeURIComponent(`${location.pathname}${location.search}`);

View File

@ -22,7 +22,7 @@ export const federationRestrictionsDisclosed = (state: RootState): boolean => {
};
/**
* Determine whether Soapbox is running in standalone mode.
* Determine whether pl-fe is running in standalone mode.
* Standalone mode runs separately from any backend and can login anywhere.
*/
export const isStandalone = (state: RootState): boolean => {

23
src/utils/url.ts Normal file
View File

@ -0,0 +1,23 @@
import queryString from 'query-string';
// Adapted from Axios https://github.com/axios/axios/blob/v1.x/lib/core/buildFullPath.js
const isAbsoluteURL = (url: string) => /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
const combineURLs = (baseURL: string, relativeURL: string) => relativeURL
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
: baseURL;
const buildFullPath = (requestedURL: string, baseURL?: string, params?: Record<string, any>) => {
const path = (baseURL && !isAbsoluteURL(requestedURL)) ? combineURLs(baseURL, requestedURL) : requestedURL;
if (params) {
return `${path}?${queryString.stringify(params, { arrayFormat: 'bracket' })}`;
}
return path;
};
export {
isAbsoluteURL,
combineURLs,
buildFullPath,
};