2024-10-03 04:02:59 +02: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 Stack from '@mui/material/Stack';
|
|
|
|
|
import MenuItem from '@mui/material/MenuItem';
|
2024-12-22 00:41:56 +01:00
|
|
|
import { memo, useMemo } from 'react';
|
2024-10-03 04:02:59 +02:00
|
|
|
import FormControl from '@mui/material/FormControl';
|
|
|
|
|
import InputLabel from '@mui/material/InputLabel';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { useLingui } from '@lingui/react/macro';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { Select } from '@/base/components/inputs/Select.tsx';
|
2026-02-21 15:06:09 +01:00
|
|
|
import { getIndexOfPage, getPage } from '@/features/reader/overlay/progress-bar/ReaderProgressBar.utils.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { useGetOptionForDirection } from '@/features/theme/services/ThemeCreator.ts';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { ReaderNavBarDesktopNextPreviousButton } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavBarDesktopNextPreviousButton.tsx';
|
|
|
|
|
import { READING_DIRECTION_TO_THEME_DIRECTION } from '@/features/reader/settings/ReaderSettings.constants.tsx';
|
2025-09-21 00:50:19 +02:00
|
|
|
import { useReaderPagesStore, useReaderSettingsStore } from '@/features/reader/stores/ReaderStore.ts';
|
2025-09-20 19:56:31 +02:00
|
|
|
import { ReaderControls } from '@/features/reader/services/ReaderControls.ts';
|
2024-10-03 04:02:59 +02:00
|
|
|
|
2025-09-20 19:56:31 +02:00
|
|
|
const BaseReaderNavBarDesktopPageNavigation = () => {
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
2024-10-03 04:02:59 +02:00
|
|
|
const getOptionForDirection = useGetOptionForDirection();
|
2025-09-21 00:50:19 +02:00
|
|
|
const { currentPageIndex, pages } = useReaderPagesStore((state) => ({
|
2025-09-19 17:01:20 +02:00
|
|
|
currentPageIndex: state.pages.currentPageIndex,
|
|
|
|
|
pages: state.pages.pages,
|
|
|
|
|
}));
|
2025-09-21 00:50:19 +02:00
|
|
|
const readingDirection = useReaderSettingsStore((state) => state.settings.readingDirection.value);
|
2024-10-03 04:02:59 +02:00
|
|
|
|
2025-09-19 17:01:20 +02:00
|
|
|
const currentPage = useMemo(() => getPage(currentPageIndex, pages), [currentPageIndex, pages]);
|
2024-12-21 03:46:55 +01:00
|
|
|
const direction = READING_DIRECTION_TO_THEME_DIRECTION[readingDirection];
|
2024-10-03 04:02:59 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack sx={{ flexDirection: 'row', gap: 1 }} dir="ltr">
|
|
|
|
|
<ReaderNavBarDesktopNextPreviousButton
|
|
|
|
|
type="previous"
|
2026-01-10 19:45:02 +01:00
|
|
|
title={getOptionForDirection(t`Previous page`, t`Next page`, direction)}
|
2024-10-03 04:02:59 +02:00
|
|
|
disabled={getOptionForDirection(
|
2024-12-13 02:29:27 +01:00
|
|
|
!currentPage.primary.index,
|
2026-02-21 15:06:09 +01:00
|
|
|
getIndexOfPage(currentPage) === getIndexOfPage(pages.slice(-1)[0]),
|
2024-10-03 04:02:59 +02:00
|
|
|
direction,
|
|
|
|
|
)}
|
2025-09-20 19:56:31 +02:00
|
|
|
onClick={() => ReaderControls.openPage('previous', undefined, false)}
|
2024-10-03 04:02:59 +02:00
|
|
|
/>
|
|
|
|
|
<FormControl sx={{ flexBasis: '70%', flexGrow: 0, flexShrink: 0 }}>
|
2026-01-10 19:45:02 +01:00
|
|
|
<InputLabel id="reader-nav-bar-desktop-page-select">{t`Page`}</InputLabel>
|
2024-10-03 04:02:59 +02:00
|
|
|
<Select
|
|
|
|
|
labelId="reader-nav-bar-desktop-page-select"
|
2026-01-10 19:45:02 +01:00
|
|
|
label={t`Page`}
|
2026-02-21 15:06:09 +01:00
|
|
|
value={getIndexOfPage(currentPage)}
|
2025-09-20 19:56:31 +02:00
|
|
|
onChange={(e) => ReaderControls.openPage(e.target.value as number, undefined, false)}
|
2024-10-03 04:02:59 +02:00
|
|
|
>
|
2024-12-13 02:07:02 +01:00
|
|
|
{pages.map((page) => (
|
2026-02-21 15:06:09 +01:00
|
|
|
<MenuItem key={getIndexOfPage(page)} value={getIndexOfPage(page)}>
|
2024-12-13 02:07:02 +01:00
|
|
|
{page.name}
|
2024-10-03 04:02:59 +02:00
|
|
|
</MenuItem>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<ReaderNavBarDesktopNextPreviousButton
|
|
|
|
|
type="next"
|
2026-01-10 19:45:02 +01:00
|
|
|
title={getOptionForDirection(t`Next page`, t`Previous page`, direction)}
|
2024-10-03 04:02:59 +02:00
|
|
|
disabled={getOptionForDirection(
|
2026-02-21 15:06:09 +01:00
|
|
|
getIndexOfPage(currentPage) === getIndexOfPage(pages.slice(-1)[0]),
|
2024-12-13 02:29:27 +01:00
|
|
|
!currentPage.primary.index,
|
2024-10-03 04:02:59 +02:00
|
|
|
direction,
|
|
|
|
|
)}
|
2025-09-20 19:56:31 +02:00
|
|
|
onClick={() => ReaderControls.openPage('next', undefined, false)}
|
2024-10-03 04:02:59 +02:00
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-12-21 03:46:55 +01:00
|
|
|
|
2025-09-20 19:56:31 +02:00
|
|
|
export const ReaderNavBarDesktopPageNavigation = memo(BaseReaderNavBarDesktopPageNavigation);
|