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

54 lines
1.7 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/.
*/
2024-12-22 00:41:56 +01:00
import { memo } from 'react';
2024-11-06 13:00:36 +01:00
import { BasePager } from '@/modules/reader/components/viewer/pager/BasePager.tsx';
import { ReaderPagerProps } from '@/modules/reader/types/Reader.types.ts';
import { createReaderPage } from '@/modules/reader/utils/ReaderPager.utils.tsx';
2024-12-22 00:41:56 +01:00
const BaseReaderPagedPager = ({
2024-12-07 04:47:28 +01:00
onLoad,
onError,
pageLoadStates,
retryFailedPagesKeyPrefix,
...props
}: ReaderPagerProps) => {
2024-11-06 13:00:36 +01:00
const { currentPageIndex, totalPages } = props;
return (
<BasePager
{...props}
createPage={(page, pagesIndex, shouldLoad, shouldDisplay, _setRef, ...baseProps) =>
2024-11-06 13:00:36 +01:00
createReaderPage(
page,
2024-12-22 00:42:33 +01:00
pagesIndex,
true,
pageLoadStates[page.primary.index].loaded,
2024-12-22 00:42:33 +01:00
onLoad,
onError,
2024-11-06 13:00:36 +01:00
shouldLoad,
2025-01-28 02:16:00 +01:00
shouldDisplay && shouldLoad && currentPageIndex === page.primary.index,
2024-11-06 13:00:36 +01:00
currentPageIndex,
totalPages,
...baseProps,
2024-12-07 04:47:28 +01:00
pageLoadStates[page.primary.index].error ? retryFailedPagesKeyPrefix : undefined,
2024-11-06 13:00:36 +01:00
)
}
slots={{
boxProps: {
2024-11-06 13:00:36 +01:00
sx: {
margin: 'auto',
},
},
}}
/>
);
};
2024-12-22 00:41:56 +01:00
export const ReaderPagedPager = memo(BaseReaderPagedPager);