From ca7fba0757cec800d9d2df9d7dbcf4b025ba27d2 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 17 Feb 2025 03:45:18 +0100 Subject: [PATCH] Add library button to "ReaderOverlayHeaderMobile" --- .../overlay/ReaderOverlayHeaderMobile.tsx | 2 + .../navigation/ReaderLibraryButton.tsx | 52 +++++++++ .../desktop/ReaderNavBarDesktopActions.tsx | 109 +++++++----------- 3 files changed, 95 insertions(+), 68 deletions(-) create mode 100644 src/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx diff --git a/src/modules/reader/components/overlay/ReaderOverlayHeaderMobile.tsx b/src/modules/reader/components/overlay/ReaderOverlayHeaderMobile.tsx index 0d92d8df..8554af4f 100644 --- a/src/modules/reader/components/overlay/ReaderOverlayHeaderMobile.tsx +++ b/src/modules/reader/components/overlay/ReaderOverlayHeaderMobile.tsx @@ -40,6 +40,7 @@ import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx'; import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx'; import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx'; import { useReaderScrollbarContext } from '@/modules/reader/contexts/ReaderScrollbarContext.tsx'; +import { ReaderLibraryButton } from '@/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx'; const DEFAULT_MANGA = { id: -1, title: '' }; const DEFAULT_CHAPTER = { id: -1, name: '', realUrl: '', isBookmarked: false }; @@ -107,6 +108,7 @@ const BaseReaderOverlayHeaderMobile = forwardRef< )} + Chapters.performAction(bookmarkAction, [chapterId], {})} color="inherit"> {isBookmarked ? : } diff --git a/src/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx b/src/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx new file mode 100644 index 00000000..bceed650 --- /dev/null +++ b/src/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx @@ -0,0 +1,52 @@ +/* + * 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 IconButton from '@mui/material/IconButton'; +import { useTranslation } from 'react-i18next'; +import FavoriteIcon from '@mui/icons-material/Favorite'; +import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder'; +import { memo } from 'react'; +import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; +import { useManageMangaLibraryState } from '@/modules/manga/hooks/useManageMangaLibraryState.tsx'; +import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts'; +import { TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts'; +import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx'; +import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx'; + +const ACTION_FALLBACK_MANGA = { + ...FALLBACK_MANGA, + title: 'Fallback', + inLibrary: false, +}; + +const BaseReaderLibraryButton = ({ manga }: Pick) => { + const { inLibrary } = manga ?? ACTION_FALLBACK_MANGA; + + const { t } = useTranslation(); + const { CategorySelectComponent, updateLibraryState } = useManageMangaLibraryState(manga ?? ACTION_FALLBACK_MANGA); + + return ( + <> + + + {inLibrary ? : } + + + + {CategorySelectComponent} + + ); +}; + +export const ReaderLibraryButton = withPropsFrom( + memo(BaseReaderLibraryButton), + [useReaderStateMangaContext], + ['manga'], +); diff --git a/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx b/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx index 59e15237..5f317d56 100644 --- a/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx +++ b/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx @@ -16,19 +16,15 @@ import DownloadIcon from '@mui/icons-material/Download'; import ReplayIcon from '@mui/icons-material/Replay'; import { memo, useMemo, useRef } from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; -import FavoriteIcon from '@mui/icons-material/Favorite'; -import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder'; import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx'; import { actionToTranslationKey, ChapterAction, Chapters } from '@/modules/chapter/services/Chapters.ts'; -import { ReaderStateChapters, TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts'; +import { ReaderStateChapters } from '@/modules/reader/types/Reader.types.ts'; import { DownloadStateIndicator } from '@/modules/core/components/DownloadStateIndicator.tsx'; import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts'; import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx'; import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx'; import { userReaderStatePagesContext } from '@/modules/reader/contexts/state/ReaderStatePagesContext.tsx'; -import { useManageMangaLibraryState } from '@/modules/manga/hooks/useManageMangaLibraryState.tsx'; -import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts'; -import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx'; +import { ReaderLibraryButton } from '@/modules/reader/components/overlay/navigation/ReaderLibraryButton.tsx'; const DownloadButton = ({ currentChapter }: Required>) => { const { t } = useTranslation(); @@ -62,29 +58,17 @@ const DownloadButton = ({ currentChapter }: Required> & - Pick & Pick) => { const { id, isBookmarked, realUrl } = currentChapter ?? { id: -1, isBookmarked: false, realUrl: '' }; - const { inLibrary } = manga ?? ACTION_FALLBACK_MANGA; const { t } = useTranslation(); - const { CategorySelectComponent, updateLibraryState } = useManageMangaLibraryState( - manga ?? ACTION_FALLBACK_MANGA, - ); const pageRetryKeyPrefix = useRef(0); @@ -98,61 +82,50 @@ const BaseReaderNavBarDesktopActions = memo( : 'bookmark'; return ( - <> - - + + + Chapters.performAction(bookmarkAction, [id], {})} color="inherit"> + {isBookmarked ? : } + + + + { + setPageLoadStates((statePageLoadStates) => + statePageLoadStates.map((pageLoadState) => ({ + url: pageLoadState.url, + loaded: pageLoadState.loaded, + })), + ); + setRetryFailedPagesKeyPrefix(`${pageRetryKeyPrefix.current}`); + pageRetryKeyPrefix.current = (pageRetryKeyPrefix.current + 1) % 1000; + }} + disabled={!haveSomePagesFailedToLoad} + color="inherit" > - - {inLibrary ? : } - - - - Chapters.performAction(bookmarkAction, [id], {})} color="inherit"> - {isBookmarked ? : } - - - - { - setPageLoadStates((statePageLoadStates) => - statePageLoadStates.map((pageLoadState) => ({ - url: pageLoadState.url, - loaded: pageLoadState.loaded, - })), - ); - setRetryFailedPagesKeyPrefix(`${pageRetryKeyPrefix.current}`); - pageRetryKeyPrefix.current = (pageRetryKeyPrefix.current + 1) % 1000; - }} - disabled={!haveSomePagesFailedToLoad} - color="inherit" - > - - - - - - - - - - - {CategorySelectComponent} - + + + + + + + + + + ); }, ); export const ReaderNavBarDesktopActions = withPropsFrom( BaseReaderNavBarDesktopActions, - [useReaderStateChaptersContext, userReaderStatePagesContext, useReaderStateMangaContext], - ['currentChapter', 'pageLoadStates', 'setPageLoadStates', 'setRetryFailedPagesKeyPrefix', 'manga'], + [useReaderStateChaptersContext, userReaderStatePagesContext], + ['currentChapter', 'pageLoadStates', 'setPageLoadStates', 'setRetryFailedPagesKeyPrefix'], );