Refac APIClient to return data, error and status as object

This commit is contained in:
MerlinScheurer
2025-03-20 20:30:08 +01:00
parent 52083e6fb7
commit edcede5de6
67 changed files with 660 additions and 544 deletions

View File

@@ -1,8 +1,8 @@
import APIClient from '../../functions/APIClient';
import { CookieStateType } from '../loader/loadCookie';
const deleteCookie = async (): Promise<CookieStateType> => {
return APIClient('/api/appsettings/cookie/', {
const deleteCookie = async () => {
return APIClient<CookieStateType>('/api/appsettings/cookie/', {
method: 'DELETE',
});
};

View File

@@ -1,8 +1,8 @@
import APIClient from '../../functions/APIClient';
import { CookieStateType } from '../loader/loadCookie';
const updateCookie = async (cookie: string): Promise<CookieStateType> => {
return APIClient('/api/appsettings/cookie/', {
const updateCookie = async (cookie: string) => {
return APIClient<CookieStateType>('/api/appsettings/cookie/', {
method: 'PUT',
body: { cookie },
});

View File

@@ -25,8 +25,8 @@ export type UserConfigType = {
show_help_text: boolean;
};
const updateUserConfig = async (config: Partial<UserConfigType>): Promise<UserConfigType> => {
return APIClient('/api/user/me/', {
const updateUserConfig = async (config: Partial<UserConfigType>) => {
return APIClient<UserConfigType>('/api/user/me/', {
method: 'POST',
body: config,
});

View File

@@ -14,11 +14,8 @@ type VideoProgressProp = {
currentProgress: number;
};
const updateVideoProgressById = async ({
youtubeId,
currentProgress,
}: VideoProgressProp): Promise<VideoProgressResponseType> => {
return APIClient(`/api/video/${youtubeId}/progress/`, {
const updateVideoProgressById = async ({ youtubeId, currentProgress }: VideoProgressProp) => {
return APIClient<VideoProgressResponseType>(`/api/video/${youtubeId}/progress/`, {
method: 'POST',
body: { position: currentProgress },
});

View File

@@ -1,8 +1,8 @@
import APIClient from '../../functions/APIClient';
import { CookieStateType } from '../loader/loadCookie';
const validateCookie = async (): Promise<CookieStateType> => {
return APIClient('/api/appsettings/cookie/', {
const validateCookie = async () => {
return APIClient<CookieStateType>('/api/appsettings/cookie/', {
method: 'POST',
});
};