From 419181efa90c4e55c7198c71650357167cd3de17 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 17 Feb 2025 03:26:44 +0100 Subject: [PATCH] Add add/remove to/from library button to reader desktop quick actions --- .../desktop/ReaderNavBarDesktopActions.tsx | 107 +++++++++++------- 1 file changed, 68 insertions(+), 39 deletions(-) diff --git a/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx b/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx index f46bb4fd..59e15237 100644 --- a/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx +++ b/src/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx @@ -16,14 +16,19 @@ 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 } from '@/modules/reader/types/Reader.types.ts'; +import { ReaderStateChapters, TReaderStateMangaContext } 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'; const DownloadButton = ({ currentChapter }: Required>) => { const { t } = useTranslation(); @@ -57,17 +62,29 @@ 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); @@ -81,49 +98,61 @@ 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], - ['currentChapter', 'pageLoadStates', 'setPageLoadStates', 'setRetryFailedPagesKeyPrefix'], + [useReaderStateChaptersContext, userReaderStatePagesContext, useReaderStateMangaContext], + ['currentChapter', 'pageLoadStates', 'setPageLoadStates', 'setRetryFailedPagesKeyPrefix', 'manga'], );