/* * 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 Stack from '@mui/material/Stack'; import { useTranslation } from 'react-i18next'; import IconButton from '@mui/material/IconButton'; 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 { CustomTooltip } from '@/base/components/CustomTooltip.tsx'; import { Chapters } from '@/features/chapter/services/Chapters.ts'; import { ReaderStateChapters } from '@/features/reader/Reader.types.ts'; import { DownloadStateIndicator } from '@/base/components/downloads/DownloadStateIndicator.tsx'; import { withPropsFrom } from '@/base/hoc/withPropsFrom.tsx'; import { useReaderStateChaptersContext } from '@/features/reader/contexts/state/ReaderStateChaptersContext.tsx'; import { ReaderLibraryButton } from '@/features/reader/overlay/navigation/components/ReaderLibraryButton.tsx'; import { ReaderBookmarkButton } from '@/features/reader/overlay/navigation/components/ReaderBookmarkButton.tsx'; import { CHAPTER_ACTION_TO_TRANSLATION, FALLBACK_CHAPTER } from '@/features/chapter/Chapter.constants.ts'; import { IconBrowser } from '@/assets/icons/IconBrowser.tsx'; import { IconWebView } from '@/assets/icons/IconWebView.tsx'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { useReaderStoreShallow } from '@/features/reader/ReaderStore.ts'; const DownloadButton = ({ currentChapter }: Required>) => { const { t } = useTranslation(); const downloadStatus = Chapters.useDownloadStatusFromCache(currentChapter?.id ?? -1); if (currentChapter && Chapters.isDownloaded(currentChapter)) { return ( Chapters.performAction('delete', [currentChapter.id], {})} color="inherit"> ); } if (downloadStatus) { return ; } return ( Chapters.performAction('download', [currentChapter?.id ?? -1], {})} color="inherit" > ); }; const BaseReaderNavBarDesktopActions = memo( ({ currentChapter }: Required>) => { const { id, isBookmarked, realUrl } = currentChapter ?? FALLBACK_CHAPTER; const { t } = useTranslation(); const { pageLoadStates, setPageLoadStates, setRetryFailedPagesKeyPrefix } = useReaderStoreShallow((state) => ({ pageLoadStates: state.pages.pageLoadStates, setPageLoadStates: state.pages.setPageLoadStates, setRetryFailedPagesKeyPrefix: state.pages.setRetryFailedPagesKeyPrefix, })); const pageRetryKeyPrefix = useRef(0); const haveSomePagesFailedToLoad = useMemo( () => pageLoadStates.some((pageLoadState) => pageLoadState.error), [pageLoadStates], ); return ( { setPageLoadStates((statePageLoadStates) => statePageLoadStates.map((pageLoadState) => ({ url: pageLoadState.url, loaded: pageLoadState.loaded, })), ); setRetryFailedPagesKeyPrefix(`${pageRetryKeyPrefix.current}`); pageRetryKeyPrefix.current = (pageRetryKeyPrefix.current + 1) % 1000; }} disabled={!haveSomePagesFailedToLoad} color="inherit" > ); }, ); export const ReaderNavBarDesktopActions = withPropsFrom( BaseReaderNavBarDesktopActions, [useReaderStateChaptersContext], ['currentChapter'], );