Files
suwayomi-material-you-webui/src/modules/reader/components/viewer/pager/ReaderHorizontalPager.tsx

82 lines
3.0 KiB
TypeScript
Raw Normal View History

2024-11-06 13:00:36 +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 { useTheme } from '@mui/material/styles';
2024-12-22 00:41:56 +01:00
import { memo } from 'react';
2024-11-06 13:00:36 +01:00
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
import { BasePager } from '@/modules/reader/components/viewer/pager/BasePager.tsx';
import { applyStyles } from '@/modules/core/utils/ApplyStyles.ts';
2024-12-21 03:46:55 +01:00
import { IReaderSettings, ReaderPagerProps, ReadingDirection } from '@/modules/reader/types/Reader.types.ts';
2024-11-06 13:00:36 +01:00
import { createReaderPage } from '@/modules/reader/utils/ReaderPager.utils.tsx';
2024-12-21 03:46:55 +01:00
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
2024-11-06 13:00:36 +01:00
2024-12-21 03:46:55 +01:00
const BaseReaderHorizontalPager = ({
2024-12-07 04:47:28 +01:00
onLoad,
onError,
pageLoadStates,
retryFailedPagesKeyPrefix,
2024-12-21 03:46:55 +01:00
pageGap,
readingDirection,
2024-12-07 04:47:28 +01:00
...props
2024-12-21 03:46:55 +01:00
}: ReaderPagerProps & Pick<IReaderSettings, 'pageGap' | 'readingDirection'>) => {
2024-11-06 13:00:36 +01:00
const { currentPageIndex, totalPages } = props;
const { direction: themeDirection } = useTheme();
2024-12-21 03:46:55 +01:00
const isLtrReadingDirection = readingDirection === ReadingDirection.LTR;
2024-11-06 13:00:36 +01:00
return (
<BasePager
{...props}
2024-12-03 18:00:46 +01:00
createPage={(page, pagesIndex, shouldLoad, _, setRef) =>
2024-11-06 13:00:36 +01:00
createReaderPage(
page,
2024-12-22 00:42:33 +01:00
pagesIndex,
true,
onLoad,
onError,
2024-11-06 13:00:36 +01:00
shouldLoad,
true,
currentPageIndex,
totalPages,
2024-12-07 04:47:28 +01:00
pageLoadStates[page.primary.index].error ? retryFailedPagesKeyPrefix : undefined,
2024-11-06 13:00:36 +01:00
undefined,
undefined,
undefined,
2024-11-06 13:00:36 +01:00
setRef,
)
}
slots={{
boxProps: {
2024-11-06 13:00:36 +01:00
sx: {
my: 'auto',
display: 'flex',
flexWrap: 'nowrap',
alignItems: 'center',
2024-12-21 03:46:55 +01:00
gap: `${pageGap}px`,
2024-11-06 13:00:36 +01:00
...applyStyles(themeDirection === 'ltr', {
flexDirection: isLtrReadingDirection ? 'row' : 'row-reverse',
justifyContent: isLtrReadingDirection ? 'flex-start' : 'flex-end',
}),
...applyStyles(themeDirection === 'rtl', {
flexDirection: isLtrReadingDirection ? 'row-reverse' : 'row',
justifyContent: isLtrReadingDirection ? 'flex-end' : 'flex-start',
}),
},
},
}}
/>
);
};
2024-12-21 03:46:55 +01:00
export const ReaderHorizontalPager = withPropsFrom(
2024-12-22 00:41:56 +01:00
memo(BaseReaderHorizontalPager),
2024-12-21 03:46:55 +01:00
[ReaderService.useSettingsWithoutDefaultFlag],
['pageGap', 'readingDirection'],
);