/* * 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 Typography from '@mui/material/Typography'; import Stack from '@mui/material/Stack'; import { useTranslation } from 'react-i18next'; import Button from '@mui/material/Button'; import { Link } from 'react-router-dom'; import { memo } from 'react'; import { alpha, useTheme } from '@mui/material/styles'; import { useReaderScrollbarContext } from '@/modules/reader/contexts/ReaderScrollbarContext.tsx'; import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx'; import { ChapterScanlatorInfo } from '@/modules/chapter/services/Chapters.ts'; import { TChapterReader } from '@/modules/chapter/Chapter.types.ts'; import { IReaderSettings, ReaderPageScaleMode, ReaderStateChapters, ReaderTransitionPageMode, ReadingMode, TReaderScrollbarContext, TReaderStateMangaContext, } from '@/modules/reader/types/Reader.types.ts'; import { isTransitionPageVisible } from '@/modules/reader/utils/ReaderPager.utils.tsx'; import { useBackButton } from '@/modules/core/hooks/useBackButton.ts'; import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts'; import { isContinuousReadingMode, isContinuousVerticalReadingMode, } from '@/modules/reader/utils/ReaderSettings.utils.tsx'; import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx'; import { AppRoutes } from '@/modules/core/AppRoute.constants.ts'; import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts'; import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx'; import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx'; import { getValueFromObject } from '@/lib/HelperFunctions.ts'; import { READER_BACKGROUND_TO_COLOR } from '@/modules/reader/constants/ReaderSettings.constants.tsx'; import { ReaderService } from '@/modules/reader/services/ReaderService.ts'; const ChapterInfo = ({ title, chapter, backgroundColor, }: { title: string; chapter?: Pick & ChapterScanlatorInfo; backgroundColor: IReaderSettings['backgroundColor']; }) => { const theme = useTheme(); const contrastText = theme.palette.getContrastText( getValueFromObject(theme.palette, READER_BACKGROUND_TO_COLOR[backgroundColor]), ); const disabledText = alpha(contrastText, 0.5); if (!chapter) { return null; } return ( {title} {chapter.name} {chapter.scanlator && ( {chapter.scanlator} )} ); }; const BaseReaderTransitionPage = ({ type, mode, readingMode, pageScaleMode, backgroundColor, manga, currentChapter, previousChapter, nextChapter, scrollbarXSize, scrollbarYSize, readerNavBarWidth, }: Pick & Pick & Pick & Pick & Pick & { type: Exclude; mode: ReaderTransitionPageMode; }) => { const { t } = useTranslation(); const handleBack = useBackButton(); const isPreviousType = type === ReaderTransitionPageMode.PREVIOUS; const isNextType = type === ReaderTransitionPageMode.NEXT; const isFirstChapter = !!currentChapter && !previousChapter; const isLastChapter = !!currentChapter && !nextChapter; const isFitWidthPageScaleMode = [ReaderPageScaleMode.SCREEN, ReaderPageScaleMode.WIDTH].includes(pageScaleMode); if (!isTransitionPageVisible(type, mode, readingMode)) { return null; } return ( {isPreviousType && isFirstChapter && ( {t('reader.transition_page.first_chapter')} )} {isPreviousType && !isFirstChapter && ( )} {!!currentChapter && ( )} {isNextType && !isLastChapter && ( )} {isNextType && isLastChapter && ( {t('reader.transition_page.last_chapter')} )} {((isPreviousType && isFirstChapter) || (isNextType && isLastChapter)) && ( )} ); }; export const ReaderTransitionPage = withPropsFrom( memo(BaseReaderTransitionPage), [ useReaderStateMangaContext, useReaderStateChaptersContext, useReaderScrollbarContext, useNavBarContext, ReaderService.useSettingsWithoutDefaultFlag, ], [ 'manga', 'currentChapter', 'previousChapter', 'nextChapter', 'scrollbarXSize', 'scrollbarYSize', 'readerNavBarWidth', 'backgroundColor', ], );