2024-12-03 18:00:46 +01:00
|
|
|
/*
|
|
|
|
|
* 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';
|
2024-12-22 00:41:56 +01:00
|
|
|
import { memo } from 'react';
|
2024-12-25 02:36:53 +01:00
|
|
|
import { alpha, useTheme } from '@mui/material/styles';
|
2024-12-03 18:00:46 +01:00
|
|
|
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,
|
2024-12-21 03:46:55 +01:00
|
|
|
ReaderStateChapters,
|
2024-12-03 18:00:46 +01:00
|
|
|
ReaderTransitionPageMode,
|
|
|
|
|
ReadingMode,
|
2024-12-21 03:46:55 +01:00
|
|
|
TReaderScrollbarContext,
|
|
|
|
|
TReaderStateMangaContext,
|
2024-12-03 18:00:46 +01:00
|
|
|
} 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';
|
2024-12-16 16:26:32 +01:00
|
|
|
import {
|
|
|
|
|
isContinuousReadingMode,
|
|
|
|
|
isContinuousVerticalReadingMode,
|
|
|
|
|
} from '@/modules/reader/utils/ReaderSettings.utils.tsx';
|
2024-12-03 18:00:46 +01:00
|
|
|
import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
2024-12-11 20:10:59 +01:00
|
|
|
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
|
2024-12-21 03:46:55 +01:00
|
|
|
import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts';
|
|
|
|
|
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
2024-12-23 01:58:59 +01:00
|
|
|
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
2024-12-25 02:36:53 +01:00
|
|
|
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';
|
2024-12-25 17:12:07 +01:00
|
|
|
import { userReaderStatePagesContext } from '@/modules/reader/contexts/state/ReaderStatePagesContext.tsx';
|
|
|
|
|
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
|
2024-12-03 18:00:46 +01:00
|
|
|
|
|
|
|
|
const ChapterInfo = ({
|
|
|
|
|
title,
|
|
|
|
|
chapter,
|
2024-12-25 02:36:53 +01:00
|
|
|
backgroundColor,
|
2024-12-03 18:00:46 +01:00
|
|
|
}: {
|
|
|
|
|
title: string;
|
|
|
|
|
chapter?: Pick<TChapterReader, 'name'> & ChapterScanlatorInfo;
|
2024-12-25 02:36:53 +01:00
|
|
|
backgroundColor: IReaderSettings['backgroundColor'];
|
2024-12-03 18:00:46 +01:00
|
|
|
}) => {
|
2024-12-25 02:36:53 +01:00
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
|
|
const contrastText = theme.palette.getContrastText(
|
|
|
|
|
getValueFromObject(theme.palette, READER_BACKGROUND_TO_COLOR[backgroundColor]),
|
|
|
|
|
);
|
|
|
|
|
const disabledText = alpha(contrastText, 0.5);
|
|
|
|
|
|
2024-12-03 18:00:46 +01:00
|
|
|
if (!chapter) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack>
|
2024-12-25 02:36:53 +01:00
|
|
|
<Typography color={contrastText}>{title}</Typography>
|
|
|
|
|
<Typography color={contrastText} variant="h6" component="h1">
|
2024-12-03 18:00:46 +01:00
|
|
|
{chapter.name}
|
|
|
|
|
</Typography>
|
|
|
|
|
{chapter.scanlator && (
|
2024-12-25 02:36:53 +01:00
|
|
|
<Typography variant="body2" color={disabledText}>
|
2024-12-03 18:00:46 +01:00
|
|
|
{chapter.scanlator}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-21 03:46:55 +01:00
|
|
|
const BaseReaderTransitionPage = ({
|
2024-12-03 18:00:46 +01:00
|
|
|
type,
|
2024-12-25 17:12:07 +01:00
|
|
|
transitionPageMode,
|
2024-12-03 18:00:46 +01:00
|
|
|
readingMode,
|
|
|
|
|
pageScaleMode,
|
2024-12-25 02:36:53 +01:00
|
|
|
backgroundColor,
|
2024-12-21 03:46:55 +01:00
|
|
|
manga,
|
|
|
|
|
currentChapter,
|
|
|
|
|
previousChapter,
|
|
|
|
|
nextChapter,
|
|
|
|
|
scrollbarXSize,
|
|
|
|
|
scrollbarYSize,
|
|
|
|
|
readerNavBarWidth,
|
2024-12-25 02:36:53 +01:00
|
|
|
}: Pick<IReaderSettings, 'readingMode' | 'pageScaleMode' | 'backgroundColor'> &
|
2024-12-21 03:46:55 +01:00
|
|
|
Pick<TReaderStateMangaContext, 'manga'> &
|
|
|
|
|
Pick<ReaderStateChapters, 'currentChapter' | 'previousChapter' | 'nextChapter'> &
|
|
|
|
|
Pick<TReaderScrollbarContext, 'scrollbarXSize' | 'scrollbarYSize'> &
|
2024-12-25 17:12:07 +01:00
|
|
|
Pick<ReaderStatePages, 'transitionPageMode'> &
|
2024-12-21 03:46:55 +01:00
|
|
|
Pick<NavbarContextType, 'readerNavBarWidth'> & {
|
|
|
|
|
type: Exclude<ReaderTransitionPageMode, ReaderTransitionPageMode.NONE | ReaderTransitionPageMode.BOTH>;
|
|
|
|
|
}) => {
|
2024-12-03 18:00:46 +01:00
|
|
|
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);
|
|
|
|
|
|
2024-12-30 14:11:28 +01:00
|
|
|
if (!isTransitionPageVisible(transitionPageMode, readingMode, type)) {
|
2024-12-03 18:00:46 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2024-12-18 00:33:03 +01:00
|
|
|
...applyStyles(!isContinuousReadingMode(readingMode), {
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
}),
|
2024-12-03 18:00:46 +01:00
|
|
|
...applyStyles(isContinuousReadingMode(readingMode), {
|
|
|
|
|
position: 'relative',
|
|
|
|
|
transform: 'scale(1)',
|
2024-12-16 16:26:32 +01:00
|
|
|
...applyStyles(isContinuousVerticalReadingMode(readingMode), {
|
2024-12-16 21:14:18 +01:00
|
|
|
minHeight: `calc(100vh - ${scrollbarXSize}px)`,
|
2024-12-03 18:00:46 +01:00
|
|
|
maxWidth: '100%',
|
|
|
|
|
width: '100%',
|
|
|
|
|
...applyStyles(!isFitWidthPageScaleMode, { alignItems: 'baseline' }),
|
|
|
|
|
}),
|
|
|
|
|
...applyStyles(readingMode === ReadingMode.CONTINUOUS_HORIZONTAL, {
|
2024-12-16 21:14:18 +01:00
|
|
|
minWidth: `calc(100vw - ${scrollbarYSize}px - ${readerNavBarWidth}px)`,
|
2024-12-03 18:00:46 +01:00
|
|
|
maxHeight: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
justifyContent: 'unset',
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
gap: 2,
|
|
|
|
|
maxWidth: `calc(100vw - ${scrollbarYSize}px)`,
|
|
|
|
|
maxHeight: `calc(100vh - ${scrollbarXSize}px)`,
|
|
|
|
|
width: 'max-content',
|
|
|
|
|
p: 1,
|
|
|
|
|
...applyStyles(isContinuousReadingMode(readingMode), {
|
|
|
|
|
position: 'sticky',
|
|
|
|
|
...applyStyles(
|
|
|
|
|
// on small screens with "fit to with" enabled, "left 50%" does not center the element in the
|
|
|
|
|
// viewport which then causes "translate" to move the element mostly outside the viewport with
|
|
|
|
|
// only a small part of it being visible
|
2024-12-16 16:26:32 +01:00
|
|
|
!isFitWidthPageScaleMode && isContinuousVerticalReadingMode(readingMode),
|
2024-12-03 18:00:46 +01:00
|
|
|
{
|
|
|
|
|
left: '50%',
|
|
|
|
|
transform: 'translateX(-50%)',
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
...applyStyles(readingMode === ReadingMode.CONTINUOUS_HORIZONTAL, {
|
|
|
|
|
top: '50%',
|
|
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{isPreviousType && isFirstChapter && (
|
|
|
|
|
<Typography variant="h6">{t('reader.transition_page.first_chapter')}</Typography>
|
|
|
|
|
)}
|
|
|
|
|
<Stack sx={{ gap: 5 }}>
|
|
|
|
|
{isPreviousType && !isFirstChapter && (
|
2024-12-25 02:36:53 +01:00
|
|
|
<ChapterInfo
|
|
|
|
|
title={t('reader.transition_page.previous')}
|
|
|
|
|
chapter={previousChapter}
|
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
/>
|
2024-12-03 18:00:46 +01:00
|
|
|
)}
|
|
|
|
|
{!!currentChapter && (
|
|
|
|
|
<ChapterInfo
|
|
|
|
|
title={t(
|
|
|
|
|
isPreviousType ? 'reader.transition_page.current' : 'reader.transition_page.finished',
|
|
|
|
|
)}
|
|
|
|
|
chapter={currentChapter}
|
2024-12-25 02:36:53 +01:00
|
|
|
backgroundColor={backgroundColor}
|
2024-12-03 18:00:46 +01:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{isNextType && !isLastChapter && (
|
2024-12-25 02:36:53 +01:00
|
|
|
<ChapterInfo
|
|
|
|
|
title={t('reader.transition_page.next')}
|
|
|
|
|
chapter={nextChapter}
|
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
|
/>
|
2024-12-03 18:00:46 +01:00
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
{isNextType && isLastChapter && (
|
|
|
|
|
<Typography variant="h6">{t('reader.transition_page.last_chapter')}</Typography>
|
|
|
|
|
)}
|
|
|
|
|
{((isPreviousType && isFirstChapter) || (isNextType && isLastChapter)) && (
|
|
|
|
|
<Stack sx={{ flexDirection: 'row', flexWrap: 'wrap', gap: 1 }}>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{ flexGrow: 1 }}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
handleBack();
|
|
|
|
|
}}
|
|
|
|
|
variant="contained"
|
|
|
|
|
>
|
|
|
|
|
{t('reader.transition_page.exit.previous_page')}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{ flexGrow: 1 }}
|
|
|
|
|
component={Link}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}}
|
|
|
|
|
variant="contained"
|
2024-12-11 20:10:59 +01:00
|
|
|
to={AppRoutes.manga.path(manga?.id ?? -1)}
|
2024-12-03 18:00:46 +01:00
|
|
|
>
|
|
|
|
|
{t('reader.transition_page.exit.manga_page')}
|
|
|
|
|
</Button>
|
|
|
|
|
</Stack>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-12-21 03:46:55 +01:00
|
|
|
|
|
|
|
|
export const ReaderTransitionPage = withPropsFrom(
|
2024-12-22 00:41:56 +01:00
|
|
|
memo(BaseReaderTransitionPage),
|
2024-12-25 02:36:53 +01:00
|
|
|
[
|
|
|
|
|
useReaderStateMangaContext,
|
|
|
|
|
useReaderStateChaptersContext,
|
|
|
|
|
useReaderScrollbarContext,
|
|
|
|
|
useNavBarContext,
|
2024-12-25 17:12:07 +01:00
|
|
|
userReaderStatePagesContext,
|
2024-12-25 02:36:53 +01:00
|
|
|
ReaderService.useSettingsWithoutDefaultFlag,
|
|
|
|
|
],
|
2024-12-21 03:46:55 +01:00
|
|
|
[
|
|
|
|
|
'manga',
|
|
|
|
|
'currentChapter',
|
|
|
|
|
'previousChapter',
|
|
|
|
|
'nextChapter',
|
|
|
|
|
'scrollbarXSize',
|
|
|
|
|
'scrollbarYSize',
|
|
|
|
|
'readerNavBarWidth',
|
2024-12-25 02:36:53 +01:00
|
|
|
'backgroundColor',
|
2024-12-25 17:12:07 +01:00
|
|
|
'transitionPageMode',
|
2024-12-25 02:38:36 +01:00
|
|
|
'readingMode',
|
|
|
|
|
'pageScaleMode',
|
2024-12-21 03:46:55 +01:00
|
|
|
],
|
|
|
|
|
);
|