* Add NavbarToolbar component for rendering items in toolbar through portal * Refactor Manga screen, move chapters filtering to toolbar menu, cleanup ChapterOptions * Fix warning * Update layout of ChapterList and add selection for chapters, add batch download, move stuff around * Add space to bookmark icon * Clear actions when leaving source mangas page * Move bookmark icon back inline and align it correctly with text * Fixup MangaDetails buttons to update cache properly so buttons in manga menu are updated * Move chapters filter to ChapterList * Fixup error display overlapping with loaded content when revalidation fails * Fixup spacing around ChapterList title * Only show small progress if manga is loaded so there is not to many spinners * Prevent title wrapping * Add icon buttons to desktop sizes of manga toolbar menu
28 lines
1.2 KiB
TypeScript
28 lines
1.2 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 { mutate } from 'swr';
|
|
import { fetcher } from 'util/client';
|
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
export const useRefreshManga = (mangaId: string) => {
|
|
const [fetchingOnline, setFetchingOnline] = useState(false);
|
|
|
|
const handleRefresh = useCallback(async () => {
|
|
setFetchingOnline(true);
|
|
await Promise.all([
|
|
fetcher(`/api/v1/manga/${mangaId}/?onlineFetch=true`)
|
|
.then((res) => mutate(`/api/v1/manga/${mangaId}/?onlineFetch=false`, res, { revalidate: false })),
|
|
fetcher(`/api/v1/manga/${mangaId}/chapters?onlineFetch=true`)
|
|
.then((res) => mutate(`/api/v1/manga/${mangaId}/chapters?onlineFetch=false`, res, { revalidate: false })),
|
|
]).finally(() => setFetchingOnline(false));
|
|
}, [mangaId]);
|
|
|
|
return [handleRefresh, { loading: fetchingOnline }] as const;
|
|
};
|