mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
chore(deps): bump all (#294)
This commit is contained in:
parent
1979d924c9
commit
38cf2ff549
69 changed files with 4681 additions and 3804 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import axios, {
|
||||
AxiosInstance,
|
||||
InternalAxiosRequestConfig,
|
||||
AxiosResponse,
|
||||
} from "axios";
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
|
|
@ -13,7 +17,7 @@ interface ApiClientContext {
|
|||
}
|
||||
|
||||
const apiClientContext = createContext<ApiClientContext>(
|
||||
undefined as any as ApiClientContext
|
||||
undefined as any as ApiClientContext,
|
||||
);
|
||||
|
||||
export const ProvideApiClient: React.FC<{ children: React.ReactNode }> = ({
|
||||
|
|
@ -35,13 +39,13 @@ export function useApiClient() {
|
|||
function useProvideApiClient(): ApiClientContext {
|
||||
const { accessToken, refreshAccessToken } = useAuth();
|
||||
|
||||
// Wrap value to immediatly update when refreshing access token
|
||||
// Wrap value to immediately update when refreshing access token
|
||||
// and always having access to newest access token in interceptor
|
||||
const localAccessToken = useRef(accessToken);
|
||||
|
||||
// initialState must be passed as function as return value of axios.create()
|
||||
// is also callable and react will call it and then use that result (promise)
|
||||
// as the initial state instead of the axios instace.
|
||||
// as the initial state instead of the axios instance.
|
||||
const [client] = useState<AxiosInstance>(() => axios.create());
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -54,15 +58,11 @@ function useProvideApiClient(): ApiClientContext {
|
|||
// Setup Axios Interceptors
|
||||
const requestInterceptor = client.interceptors.request.use(
|
||||
(config) => {
|
||||
if (!config.headers) {
|
||||
config.headers = {};
|
||||
}
|
||||
|
||||
config.headers.Authorization = `Bearer ${localAccessToken.current}`;
|
||||
|
||||
return config;
|
||||
},
|
||||
(err) => Promise.reject(err)
|
||||
(err) => Promise.reject(err),
|
||||
);
|
||||
const responseInterceptor = client.interceptors.response.use(
|
||||
(data) => data,
|
||||
|
|
@ -73,7 +73,7 @@ function useProvideApiClient(): ApiClientContext {
|
|||
|
||||
const { response, config } = err as {
|
||||
response: AxiosResponse;
|
||||
config: AxiosRequestConfig;
|
||||
config: InternalAxiosRequestConfig;
|
||||
};
|
||||
|
||||
if (response && response.status !== 401) {
|
||||
|
|
@ -84,7 +84,7 @@ function useProvideApiClient(): ApiClientContext {
|
|||
localAccessToken.current = await refreshAccessToken();
|
||||
|
||||
return client.request(config);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export const useRecentListens = (options: PaginationOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getRecentListens(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -48,7 +48,7 @@ export const useListensReport = (options: ListenReportOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getListensReport(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -65,7 +65,7 @@ export const useTopArtists = (options: TopArtistsOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopArtists(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -82,7 +82,7 @@ export const useTopAlbums = (options: TopAlbumsOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopAlbums(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -99,7 +99,7 @@ export const useTopTracks = (options: TopTracksOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopTracks(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -116,7 +116,7 @@ export const useTopGenres = (options: TopGenresOptions) => {
|
|||
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopGenres(options, client),
|
||||
[options, client]
|
||||
[options, client],
|
||||
);
|
||||
|
||||
const {
|
||||
|
|
@ -149,7 +149,7 @@ export const useApiTokens = () => {
|
|||
|
||||
return apiToken;
|
||||
},
|
||||
[client, reload]
|
||||
[client, reload],
|
||||
);
|
||||
|
||||
const revokeToken = useCallback(
|
||||
|
|
@ -157,7 +157,7 @@ export const useApiTokens = () => {
|
|||
await revokeApiToken(id, client);
|
||||
await reload();
|
||||
},
|
||||
[client, reload]
|
||||
[client, reload],
|
||||
);
|
||||
|
||||
return { apiTokens, isLoading, error, createToken, revokeToken };
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useCallback, useEffect, useState, useTransition } from "react";
|
|||
|
||||
type UseAsync = <T>(
|
||||
asyncFunction: () => Promise<T>,
|
||||
initialValue: T
|
||||
initialValue: T,
|
||||
) => {
|
||||
pending: boolean;
|
||||
value: T;
|
||||
|
|
@ -12,7 +12,7 @@ type UseAsync = <T>(
|
|||
|
||||
export const useAsync: UseAsync = <T extends any>(
|
||||
asyncFunction: () => Promise<T>,
|
||||
initialValue: T
|
||||
initialValue: T,
|
||||
) => {
|
||||
const [pending, setPending] = useState(false);
|
||||
const [value, setValue] = useState<T>(initialValue);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import React, { useEffect } from "react";
|
|||
*/
|
||||
export const useOutsideClick = (
|
||||
ref: React.MutableRefObject<any>,
|
||||
callback: () => void
|
||||
callback: () => void,
|
||||
) => {
|
||||
useEffect(() => {
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue