diff --git a/src/components/manga/ChapterCard.tsx b/src/components/manga/ChapterCard.tsx index 47385244..dac6c9b1 100644 --- a/src/components/manga/ChapterCard.tsx +++ b/src/components/manga/ChapterCard.tsx @@ -71,7 +71,7 @@ const ChapterCard: React.FC = (props: IProps) => { [key]: value, lastPageRead: key === 'read' ? 0 : undefined, }) - .then(() => triggerChaptersUpdate()); + .response.then(() => triggerChaptersUpdate()); }; const downloadChapter = () => { @@ -82,7 +82,7 @@ const ChapterCard: React.FC = (props: IProps) => { const deleteChapter = () => { requestManager .removeChapterFromDownloadQueue(chapter.mangaId, chapter.index) - .then(() => triggerChaptersUpdate()); + .response.then(() => triggerChaptersUpdate()); handleClose(); }; diff --git a/src/components/manga/ChapterList.tsx b/src/components/manga/ChapterList.tsx index 1a453911..426f8f70 100644 --- a/src/components/manga/ChapterList.tsx +++ b/src/components/manga/ChapterList.tsx @@ -153,7 +153,7 @@ const ChapterList: React.FC = ({ mangaId }) => { let actionPromise: Promise; if (action === 'download') { - actionPromise = requestManager.addChaptersToDownloadQueue(chapterIds); + actionPromise = requestManager.addChaptersToDownloadQueue(chapterIds).response; } else { const change: BatchChaptersChange = {}; @@ -165,7 +165,7 @@ const ChapterList: React.FC = ({ mangaId }) => { change.lastPageRead = 0; } - actionPromise = requestManager.updateChapters(chapterIds, change); + actionPromise = requestManager.updateChapters(chapterIds, change).response; } actionPromise diff --git a/src/components/manga/MangaDetails.tsx b/src/components/manga/MangaDetails.tsx index 3edbb310..736c224a 100644 --- a/src/components/manga/MangaDetails.tsx +++ b/src/components/manga/MangaDetails.tsx @@ -145,12 +145,12 @@ const MangaDetails: React.FC = ({ manga }) => { const addToLibrary = () => { mutate(`/api/v1/manga/${manga.id}`, { ...manga, inLibrary: true }, { revalidate: false }); - requestManager.addMangaToLibrary(manga.id).then(() => mutate(`/api/v1/manga/${manga.id}`)); + requestManager.addMangaToLibrary(manga.id).response.then(() => mutate(`/api/v1/manga/${manga.id}`)); }; const removeFromLibrary = () => { mutate(`/api/v1/manga/${manga.id}`, { ...manga, inLibrary: false }, { revalidate: false }); - requestManager.removeMangaFromLibrary(manga.id).then(() => mutate(`/api/v1/manga/${manga.id}`)); + requestManager.removeMangaFromLibrary(manga.id).response.then(() => mutate(`/api/v1/manga/${manga.id}`)); }; return ( diff --git a/src/components/navbar/action/CategorySelect.tsx b/src/components/navbar/action/CategorySelect.tsx index a723cbe0..1e4eb983 100644 --- a/src/components/navbar/action/CategorySelect.tsx +++ b/src/components/navbar/action/CategorySelect.tsx @@ -56,7 +56,7 @@ export default function CategorySelect(props: IProps) { (checked ? requestManager.addMangaToCategory(mangaId, categoryId) : requestManager.removeMangaFromCategory(mangaId, categoryId) - ).then(() => mutate()); + ).response.then(() => mutate()); }; return ( diff --git a/src/lib/RequestManager.ts b/src/lib/RequestManager.ts index 9f2f9e08..d04f8eef 100644 --- a/src/lib/RequestManager.ts +++ b/src/lib/RequestManager.ts @@ -52,6 +52,11 @@ type CustomSWROptions = { type SWROptions = SWRConfiguration & CustomSWROptions; type SWRInfiniteOptions = SWRInfiniteConfiguration & CustomSWROptions; +type AbortableRequest = { abortRequest: AbortController['abort'] }; +type AbortableAxiosResponse = { response: Promise> } & AbortableRequest; +type AbortableSWRResponse = SWRResponse & AbortableRequest; +type AbortableSWRInfiniteResponse = SWRInfiniteResponse & AbortableRequest; + // the following endpoints have not been implemented: // - PUT /api/v1/manga/{mangaId}/chapter/{chapterIndex} - modify chapter # PATCH endpoint used instead // - POST /api/v1/backup/import - import backup # "import backup file" endpoint used instead @@ -175,7 +180,7 @@ export class RequestManager { * In case "formData" is passed, "data" gets ignored. */ private doRequest< - Result extends Promise | SWRResponse | SWRInfiniteResponse, + Result extends AbortableAxiosResponse | AbortableSWRResponse | AbortableSWRInfiniteResponse, OptionsSWR extends SWROptions | SWRInfiniteOptions, >( httpMethod: HttpMethodType, @@ -205,54 +210,80 @@ export class RequestManager { }); } + const abortController = new AbortController(); + const abortRequest = (reason?: any): void => { + if (!abortController.signal.aborted) { + abortController.abort(reason); + } + }; + const axiosOptionsWithAbortController = { ...axiosOptions, signal: abortController.signal }; switch (httpMethod) { case HttpMethod.SWR_GET: - return this.useSwr(url, HttpMethod.GET, { axiosOptions, swrOptions }) as Result; + return { + ...(this.useSwr(url, HttpMethod.GET, { axiosOptions, swrOptions }) as Result), + abortRequest, + }; case HttpMethod.SWR_GET_INFINITE: // throw TypeError in case options aren't correctly passed - return this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.GET, { - axiosOptions, - swrOptions, - }) as Result; + return { + ...(this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.GET, { + axiosOptions: axiosOptionsWithAbortController, + swrOptions, + }) as Result), + abortRequest, + }; case SWRHttpMethod.SWR_POST_INFINITE: - return this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.POST, { - data, - axiosOptions, - swrOptions, - }) as Result; + return { + ...(this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.POST, { + data, + axiosOptions: axiosOptionsWithAbortController, + swrOptions, + }) as Result), + abortRequest, + }; case HttpMethod.SWR_POST: - return this.useSwr(url, HttpMethod.POST, { data, axiosOptions, swrOptions }) as Result; + return { + ...(this.useSwr(url, HttpMethod.POST, { + data, + axiosOptions: axiosOptionsWithAbortController, + swrOptions, + }) as Result), + controller: abortController, + }; default: - return this.restClient.fetcher(url, { - data, - httpMethod, - config: axiosOptions, - checkResponseIsJson: false, - }) as Result; + return { + response: this.restClient.fetcher(url, { + data, + httpMethod, + config: axiosOptionsWithAbortController, + checkResponseIsJson: false, + }), + abortRequest, + } as Result; } } - public useGetGlobalMeta(swrOptions?: SWROptions): SWRResponse { + public useGetGlobalMeta(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'meta', { swrOptions }); } - public setGlobalMetadata(key: string, value: any): Promise { + public setGlobalMetadata(key: string, value: any): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, 'meta', { formData: { key, value } }); } - public useGetAbout(swrOptions?: SWROptions): SWRResponse { + public useGetAbout(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'settings/about', { swrOptions }); } - public useCheckForUpdate(swrOptions?: SWROptions): SWRResponse { + public useCheckForUpdate(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'settings/check-update', { swrOptions }); } - public useGetExtensionList(swrOptions?: SWROptions): SWRResponse { + public useGetExtensionList(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'extension/list', { swrOptions }); } - public installExtension(extension: string | File): Promise { + public installExtension(extension: string | File): AbortableAxiosResponse { if (typeof extension === 'string') { return this.doRequest(HttpMethod.GET, `extension/install/${extension}`); } @@ -260,11 +291,11 @@ export class RequestManager { return this.doRequest(HttpMethod.POST, `extension/install`, { formData: { file: extension } }); } - public updateExtension(extension: string): Promise { + public updateExtension(extension: string): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `extension/update/${extension}`); } - public uninstallExtension(extension: string): Promise { + public uninstallExtension(extension: string): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `extension/uninstall/${extension}`); } @@ -272,11 +303,11 @@ export class RequestManager { return this.getValidImgUrlFor(`extension/icon/${extension}`); } - public useGetSourceList(swrOptions?: SWROptions): SWRResponse { + public useGetSourceList(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'source/list', { swrOptions }); } - public useGetSource(sourceId: string, swrOptions?: SWROptions): SWRResponse { + public useGetSource(sourceId: string, swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}`, { swrOptions }); } @@ -284,7 +315,7 @@ export class RequestManager { sourceId: string, initialPages?: number, swrOptions?: SWRInfiniteOptions, - ): SWRInfiniteResponse { + ): AbortableSWRInfiniteResponse { return this.doRequest(SWRHttpMethod.SWR_GET_INFINITE, '', { swrOptions: { getEndpoint: (page, previousData) => @@ -299,7 +330,7 @@ export class RequestManager { sourceId: string, initialPages?: number, swrOptions?: SWRInfiniteOptions, - ): SWRInfiniteResponse { + ): AbortableSWRInfiniteResponse { return this.doRequest(SWRHttpMethod.SWR_GET_INFINITE, '', { swrOptions: { getEndpoint: (page, previousData) => @@ -313,11 +344,11 @@ export class RequestManager { public useGetSourcePreferences( sourceId: string, swrOptions?: SWROptions, - ): SWRResponse { + ): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}/preferences`, { swrOptions }); } - public setSourcePreferences(sourceId: string, position: number, value: string): Promise { + public setSourcePreferences(sourceId: string, position: number, value: string): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `source/${sourceId}/preferences`, { data: { position, value } }); } @@ -325,15 +356,15 @@ export class RequestManager { sourceId: string, reset?: boolean, swrOptions?: SWROptions, - ): SWRResponse { + ): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}/filters`, { swrOptions }); } - public setSourceFilters(sourceId: string, filters: { position: number; state: string }[]): Promise { + public setSourceFilters(sourceId: string, filters: { position: number; state: string }[]): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `source/${sourceId}/filters`, { data: filters }); } - public resetSourceFilters(sourceId: string): Promise { + public resetSourceFilters(sourceId: string): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `source/${sourceId}/filters?reset=true`); } @@ -342,7 +373,7 @@ export class RequestManager { searchTerm: string, initialPages?: number, swrOptions?: SWRInfiniteOptions, - ): SWRInfiniteResponse { + ): AbortableSWRInfiniteResponse { return this.doRequest(HttpMethod.SWR_GET_INFINITE, '', { swrOptions: { getEndpoint: (page, previousData) => @@ -361,7 +392,7 @@ export class RequestManager { filters: { position: number; state: string }[], initialPages?: number, swrOptions?: SWRInfiniteOptions, - ): SWRInfiniteResponse { + ): AbortableSWRInfiniteResponse { return this.doRequest(HttpMethod.SWR_POST_INFINITE, '', { data: { searchTerm, filter: filters }, swrOptions: { @@ -378,7 +409,7 @@ export class RequestManager { public useGetManga( mangaId: number | string, { doOnlineFetch, ...swrOptions }: SWROptions & RequestOption = {}, - ): SWRResponse { + ): AbortableSWRResponse { const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : ''; return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}${onlineFetch}`, { swrOptions, @@ -388,7 +419,7 @@ export class RequestManager { public useGetFullManga( mangaId: number | string, { doOnlineFetch, ...swrOptions }: SWROptions & RequestOption = {}, - ): SWRResponse { + ): AbortableSWRResponse { const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : ''; return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/full${onlineFetch}`, { swrOptions, @@ -399,34 +430,37 @@ export class RequestManager { return this.getValidImgUrlFor(`manga/${mangaId}/thumbnail`); } - public useGetMangaCategories(mangaId: number, swrOptions?: SWROptions): SWRResponse { + public useGetMangaCategories( + mangaId: number, + swrOptions?: SWROptions, + ): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/category`, { swrOptions }); } - public addMangaToCategory(mangaId: number, categoryId: number): Promise { + public addMangaToCategory(mangaId: number, categoryId: number): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `manga/${mangaId}/category/${categoryId}`); } - public removeMangaFromCategory(mangaId: number, categoryId: number): Promise { + public removeMangaFromCategory(mangaId: number, categoryId: number): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/category/${categoryId}`); } - public addMangaToLibrary(mangaId: number | string): Promise { + public addMangaToLibrary(mangaId: number | string): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `manga/${mangaId}/library`); } - public removeMangaFromLibrary(mangaId: number | string): Promise { + public removeMangaFromLibrary(mangaId: number | string): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/library`); } - public setMangaMeta(mangaId: number, key: string, value: any): Promise { + public setMangaMeta(mangaId: number, key: string, value: any): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `manga/${mangaId}/meta`, { formData: { key, value } }); } public useGetMangaChapters( mangaId: number | string, { doOnlineFetch, ...swrOptions }: SWROptions & RequestOption = {}, - ): SWRResponse { + ): AbortableSWRResponse { const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : ''; return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/chapters${onlineFetch}`, { swrOptions, @@ -443,7 +477,7 @@ export class RequestManager { | { chapterIds?: number[]; chapterIndexes: number[] } | { chapterIds: number[]; chapterIndexes?: number[] } ) & { change: BatchChaptersChange }, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `manga/${mangaId}/chapter/batch`, { data: { chapterIds, @@ -457,13 +491,13 @@ export class RequestManager { mangaId: number | string, chapterIndex: number | string, swrOptions?: SWROptions, - ): SWRResponse { + ): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/chapter/${chapterIndex}`, { swrOptions, }); } - public deleteDownloadedChapter(mangaId: number | string, chapterIndex: number | string): Promise { + public deleteDownloadedChapter(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/chapter/${chapterIndex}`); } @@ -471,7 +505,7 @@ export class RequestManager { mangaId: number | string, chapterIndex: number | string, change: { read?: boolean; bookmarked?: boolean; markPrevRead?: boolean; lastPageRead?: number } = {}, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/chapter/${chapterIndex}`, { formData: change }); } @@ -480,7 +514,7 @@ export class RequestManager { chapterIndex: number | string, key: string, value: any, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/chapter/${chapterIndex}/meta`, { formData: { key, value }, }); @@ -493,51 +527,51 @@ export class RequestManager { ); } - public updateChapters(chapterIds: number[], change: BatchChaptersChange): Promise { + public updateChapters(chapterIds: number[], change: BatchChaptersChange): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `chapter/batch`, { data: { chapterIds, change } }); } - public useGetCategories(swrOptions?: SWROptions): SWRResponse { + public useGetCategories(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `category`, { swrOptions }); } - public createCategory(name: string): Promise { + public createCategory(name: string): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, `category`, { formData: { name } }); } - public reorderCategory(currentPosition: number, newPosition: number): Promise { + public reorderCategory(currentPosition: number, newPosition: number): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `category/reorder`, { formData: { from: currentPosition, to: newPosition }, }); } - public useGetCategoryMangas(categoryId: number, swrOptions?: SWROptions): SWRResponse { + public useGetCategoryMangas(categoryId: number, swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, `category/${categoryId}`, { swrOptions }); } - public deleteCategory(categoryId: number): Promise { + public deleteCategory(categoryId: number): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, `category/${categoryId}`); } public updateCategory( categoryId: number, change: { name?: string; default?: boolean; includeInUpdate?: IncludeInGlobalUpdate } = {}, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `category/${categoryId}`, { formData: change }); } - public setCategoryMeta(categoryId: number, key: string, value: any): Promise { + public setCategoryMeta(categoryId: number, key: string, value: any): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `category/${categoryId}`, { formData: { key, value } }); } - public restoreBackupFile(file: File): Promise { + public restoreBackupFile(file: File): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, 'backup/import/file', { formData: { 'backup.proto.gz': file } }); } public useValidateBackupFile( file: File, swrOptions?: SWROptions, - ): SWRResponse { + ): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_POST, 'backup/validate/file', { formData: { 'backup.proto.gz': file }, swrOptions, @@ -548,26 +582,26 @@ export class RequestManager { return this.getValidUrlFor('backup/export/file'); } - public startDownloads(): Promise { + public startDownloads(): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, 'downloads/start'); } - public stopDownloads(): Promise { + public stopDownloads(): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, 'downloads/stop'); } - public clearDownloads(): Promise { + public clearDownloads(): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, 'downloads/clear'); } - public addChapterToDownloadQueue(mangaId: number | string, chapterIndex: number | string): Promise { + public addChapterToDownloadQueue(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse { return this.doRequest(HttpMethod.GET, `download/${mangaId}/chapter/${chapterIndex}`); } public removeChapterFromDownloadQueue( mangaId: number | string, chapterIndex: number | string, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, `download/${mangaId}/chapter/${chapterIndex}`); } @@ -575,22 +609,22 @@ export class RequestManager { mangaId: number | string, chapterIndex: number | string, position: number, - ): Promise { + ): AbortableAxiosResponse { return this.doRequest(HttpMethod.PATCH, `download/${mangaId}/chapter/${chapterIndex}/reorder/${position}`); } - public addChaptersToDownloadQueue(chapterIds: number[]): Promise { + public addChaptersToDownloadQueue(chapterIds: number[]): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, 'download/batch', { data: { chapterIds } }); } - public removeChaptersFromDownloadQueue(chapterIds: number[]): Promise { + public removeChaptersFromDownloadQueue(chapterIds: number[]): AbortableAxiosResponse { return this.doRequest(HttpMethod.DELETE, 'download/batch', { data: { chapterIds } }); } public useGetRecentlyUpdatedChapters( initialPages?: number, swrOptions?: SWRInfiniteOptions>, - ): SWRInfiniteResponse> { + ): AbortableSWRInfiniteResponse> { return this.doRequest(HttpMethod.SWR_GET_INFINITE, '', { swrOptions: { getEndpoint: (page, previousData) => @@ -601,15 +635,15 @@ export class RequestManager { }); } - public startGlobalUpdate(categoryId?: number): Promise { + public startGlobalUpdate(categoryId?: number): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, 'update/fetch', { formData: { categoryId } }); } - public resetGlobalUpdate(): Promise { + public resetGlobalUpdate(): AbortableAxiosResponse { return this.doRequest(HttpMethod.POST, 'update/reset'); } - public useGetGlobalUpdateSummary(swrOptions?: SWROptions): SWRResponse { + public useGetGlobalUpdateSummary(swrOptions?: SWROptions): AbortableSWRResponse { return this.doRequest(HttpMethod.SWR_GET, 'update/summary', { swrOptions }); } } diff --git a/src/screens/DownloadQueue.tsx b/src/screens/DownloadQueue.tsx index 0f7fe414..211f41b9 100644 --- a/src/screens/DownloadQueue.tsx +++ b/src/screens/DownloadQueue.tsx @@ -85,7 +85,7 @@ const DownloadQueue: React.FC = () => { return; } - requestManager.startDownloads().catch(() => {}); + requestManager.startDownloads().response.catch(() => {}); }; return ( diff --git a/src/screens/Extensions.tsx b/src/screens/Extensions.tsx index 692f13ca..4917b932 100644 --- a/src/screens/Extensions.tsx +++ b/src/screens/Extensions.tsx @@ -135,7 +135,7 @@ export default function MangaExtensions() { makeToast(t('extension.label.installing_file'), 'info'); requestManager .installExtension(file) - .then(() => { + .response.then(() => { makeToast(t('extension.label.installed_successfully'), 'success'); mutate(); }) diff --git a/src/screens/SourceConfigure.tsx b/src/screens/SourceConfigure.tsx index be9af866..e5a41610 100644 --- a/src/screens/SourceConfigure.tsx +++ b/src/screens/SourceConfigure.tsx @@ -57,7 +57,9 @@ export default function SourceConfigure() { }; const updateValue = (position: number) => (value: any) => { - requestManager.setSourcePreferences(sourceId, position, convertToString(position, value)).then(() => mutate()); + requestManager + .setSourcePreferences(sourceId, position, convertToString(position, value)) + .response.then(() => mutate()); }; return ( diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index 09991e5c..02ebe2ce 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -108,7 +108,7 @@ export default function SourceMangas({ popular }: { popular: boolean }) { }; }), ) - .then(() => { + .response.then(() => { setTriggerUpdate(0); makeFilters(); }); @@ -128,7 +128,7 @@ export default function SourceMangas({ popular }: { popular: boolean }) { setNoreset(undefined); setReset(1); } else if (Noreset === undefined) { - requestManager.resetSourceFilters(sourceId).then(() => { + requestManager.resetSourceFilters(sourceId).response.then(() => { makeFilters(); setSearch(false); if (reset === 1) { diff --git a/src/screens/settings/Backup.tsx b/src/screens/settings/Backup.tsx index b0fb7ba5..3582f8eb 100644 --- a/src/screens/settings/Backup.tsx +++ b/src/screens/settings/Backup.tsx @@ -30,7 +30,7 @@ export default function Backup() { makeToast(t('settings.backup.label.restoring_backup'), 'info'); requestManager .restoreBackupFile(file) - .then(() => makeToast(t('settings.backup.label.restored_backup'), 'success')) + .response.then(() => makeToast(t('settings.backup.label.restored_backup'), 'success')) .catch(() => makeToast(t('settings.backup.label.backup_restore_failed'), 'error')); } else if (file.name.toLowerCase().endsWith('json')) { makeToast(t('settings.backup.label.legacy_backup_unsupported'), 'error'); diff --git a/src/screens/settings/Categories.tsx b/src/screens/settings/Categories.tsx index 98264523..16712f69 100644 --- a/src/screens/settings/Categories.tsx +++ b/src/screens/settings/Categories.tsx @@ -79,7 +79,7 @@ export default function Categories() { newData.splice(to, 0, removed); mutate(newData, { revalidate: false }); - requestManager.reorderCategory(from + 1, to + 1).finally(() => mutate()); + requestManager.reorderCategory(from + 1, to + 1).response.finally(() => mutate()); }; const onDragEnd = (result: DropResult) => { @@ -117,18 +117,18 @@ export default function Categories() { setDialogOpen(false); if (categoryToEdit === -1) { - requestManager.createCategory(dialogName).finally(() => mutate()); + requestManager.createCategory(dialogName).response.finally(() => mutate()); } else { const category = categories[categoryToEdit]; requestManager .updateCategory(category.id, { name: dialogName, default: dialogDefault }) - .finally(() => mutate()); + .response.finally(() => mutate()); } }; const deleteCategory = (index: number) => { const category = categories[index]; - requestManager.deleteCategory(category.id).finally(() => mutate()); + requestManager.deleteCategory(category.id).response.finally(() => mutate()); }; return (