Files
suwayomi-material-you-webui/src/components/manga/useRefreshManga.ts
schroda 6b690cfd8d Handle error during manga refresh
The error of the refresh mutation was never catched and shown
2024-05-11 01:12:10 +02:00

29 lines
1.1 KiB
TypeScript

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { useCallback, useState } from 'react';
import { requestManager } from '@/lib/requests/RequestManager.ts';
export const useRefreshManga = (mangaId: string) => {
const [fetchingOnline, setFetchingOnline] = useState(false);
const [error, setError] = useState(null);
const handleRefresh = useCallback(async () => {
setFetchingOnline(true);
setError(null);
await Promise.all([
requestManager.getMangaFetch(mangaId, { awaitRefetchQueries: true }).response,
requestManager.getMangaChaptersFetch(mangaId, { awaitRefetchQueries: true }).response,
])
.catch((e) => setError(e))
.finally(() => setFetchingOnline(false));
}, [mangaId]);
return [handleRefresh, { loading: fetchingOnline, error }] as const;
};