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 Tooltip from '@mui/material/Tooltip';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
|
import ArrowBack from '@mui/icons-material/ArrowBack';
|
|
|
|
|
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
|
|
|
|
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
|
|
|
|
import Divider from '@mui/material/Divider';
|
2024-12-22 00:41:56 +01:00
|
|
|
import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
2024-10-03 04:02:59 +02:00
|
|
|
import Drawer from '@mui/material/Drawer';
|
2024-12-11 13:59:50 +01:00
|
|
|
import { useGetOptionForDirection } from '@/modules/theme/services/ThemeCreator.ts';
|
2024-10-03 04:02:59 +02:00
|
|
|
import { ReaderNavBarDesktopProps } from '@/modules/reader/types/ReaderOverlay.types.ts';
|
|
|
|
|
import { ReaderNavContainer } from '@/modules/reader/components/overlay/navigation/desktop/ReaderNavContainer.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopMetadata } from '@/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopMetadata.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopPageNavigation } from '@/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopPageNavigation.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopChapterNavigation } from '@/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopChapterNavigation.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopQuickSettings } from '@/modules/reader/components/overlay/navigation/desktop/quick-settings/ReaderNavBarDesktopQuickSettings.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopActions } from '@/modules/reader/components/overlay/navigation/desktop/ReaderNavBarDesktopActions.tsx';
|
|
|
|
|
import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
|
|
|
|
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
|
|
|
|
|
import { useReaderStateMangaContext } from '@/modules/reader/contexts/state/ReaderStateMangaContext.tsx';
|
|
|
|
|
import { userReaderStatePagesContext } from '@/modules/reader/contexts/state/ReaderStatePagesContext.tsx';
|
|
|
|
|
import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx';
|
|
|
|
|
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
|
|
|
|
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
2024-12-21 03:46:55 +01:00
|
|
|
import { NavbarContextType } from '@/modules/navigation-bar/NavigationBar.types.ts';
|
2024-12-21 15:36:23 +01:00
|
|
|
import { IReaderSettings, ReaderStateChapters, TReaderStateMangaContext } from '@/modules/reader/types/Reader.types.ts';
|
2024-12-21 03:46:55 +01:00
|
|
|
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
2024-12-26 02:47:37 +01:00
|
|
|
import { FALLBACK_MANGA } from '@/modules/manga/Manga.constants.ts';
|
2024-10-03 04:02:59 +02:00
|
|
|
|
2024-11-04 18:00:35 +01:00
|
|
|
const useGetPreviousNavBarStaticValue = (isVisible: boolean, isStaticNav: boolean) => {
|
|
|
|
|
const wasNavBarStaticRef = useRef(isStaticNav);
|
|
|
|
|
const wasNavBarStaticPreviousRef = useRef(isStaticNav);
|
2024-10-03 04:02:59 +02:00
|
|
|
|
|
|
|
|
const resetWasNavBarStaticValue = wasNavBarStaticPreviousRef.current !== wasNavBarStaticRef.current && !isVisible;
|
|
|
|
|
if (resetWasNavBarStaticValue) {
|
|
|
|
|
wasNavBarStaticRef.current = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 18:00:35 +01:00
|
|
|
const didNavBarStaticValueChange = wasNavBarStaticPreviousRef.current !== isStaticNav;
|
2024-10-03 04:02:59 +02:00
|
|
|
if (didNavBarStaticValueChange) {
|
|
|
|
|
wasNavBarStaticRef.current = wasNavBarStaticPreviousRef.current;
|
2024-11-04 18:00:35 +01:00
|
|
|
wasNavBarStaticPreviousRef.current = isStaticNav;
|
2024-10-03 04:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wasNavBarStaticRef.current;
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-21 03:46:55 +01:00
|
|
|
const BaseReaderNavBarDesktop = ({
|
|
|
|
|
isVisible,
|
|
|
|
|
openSettings,
|
|
|
|
|
setReaderNavBarWidth,
|
|
|
|
|
manga,
|
|
|
|
|
chapters,
|
|
|
|
|
currentChapter,
|
|
|
|
|
previousChapter,
|
|
|
|
|
nextChapter,
|
2024-12-21 15:36:23 +01:00
|
|
|
isStaticNav,
|
2024-12-21 03:46:55 +01:00
|
|
|
exit,
|
|
|
|
|
}: ReaderNavBarDesktopProps &
|
|
|
|
|
Pick<NavbarContextType, 'setReaderNavBarWidth'> &
|
|
|
|
|
Pick<TReaderStateMangaContext, 'manga'> &
|
|
|
|
|
Pick<ReaderStateChapters, 'currentChapter' | 'previousChapter' | 'nextChapter' | 'chapters'> &
|
2024-12-21 15:36:23 +01:00
|
|
|
Pick<IReaderSettings, 'isStaticNav'> & {
|
2024-12-21 03:46:55 +01:00
|
|
|
exit: ReturnType<typeof ReaderService.useExit>;
|
|
|
|
|
}) => {
|
2024-10-03 04:02:59 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
const getOptionForDirection = useGetOptionForDirection();
|
|
|
|
|
|
2024-12-26 02:47:37 +01:00
|
|
|
const updateReaderSettings = ReaderService.useCreateUpdateSetting(manga ?? FALLBACK_MANGA);
|
2024-10-03 04:02:59 +02:00
|
|
|
|
|
|
|
|
const [navBarElement, setNavBarElement] = useState<HTMLDivElement | null>();
|
|
|
|
|
useResizeObserver(
|
|
|
|
|
navBarElement,
|
|
|
|
|
useCallback(() => {
|
2024-12-21 15:36:23 +01:00
|
|
|
if (!isStaticNav) {
|
2024-10-03 04:02:59 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setReaderNavBarWidth(navBarElement!.offsetWidth);
|
2024-12-21 15:36:23 +01:00
|
|
|
}, [navBarElement, isStaticNav]),
|
2024-10-03 04:02:59 +02:00
|
|
|
);
|
|
|
|
|
useLayoutEffect(() => () => setReaderNavBarWidth(0), []);
|
|
|
|
|
|
2024-12-21 15:36:23 +01:00
|
|
|
const wasNavBarStatic = useGetPreviousNavBarStaticValue(isVisible, isStaticNav);
|
2024-10-03 04:02:59 +02:00
|
|
|
const changedNavBarStaticValue = wasNavBarStatic && isVisible;
|
|
|
|
|
const drawerTransitionDuration = changedNavBarStaticValue ? 0 : undefined;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Drawer
|
2024-12-21 15:36:23 +01:00
|
|
|
variant={isStaticNav ? 'permanent' : 'persistent'}
|
|
|
|
|
open={isVisible || isStaticNav}
|
2024-10-03 04:02:59 +02:00
|
|
|
transitionDuration={drawerTransitionDuration}
|
2024-12-29 17:12:24 +01:00
|
|
|
SlideProps={{
|
|
|
|
|
unmountOnExit: true,
|
|
|
|
|
}}
|
2024-10-03 04:02:59 +02:00
|
|
|
PaperProps={{
|
|
|
|
|
ref: (ref: HTMLDivElement | null) => setNavBarElement(ref),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<ReaderNavContainer sx={{ backgroundColor: 'background.paper', pointerEvents: 'all' }}>
|
2024-12-22 21:53:03 +01:00
|
|
|
<Stack sx={{ p: 2, gap: 2, backgroundColor: 'action.hover' }}>
|
|
|
|
|
<Stack sx={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
|
|
|
<Tooltip title={t('reader.button.exit')}>
|
|
|
|
|
<IconButton onClick={exit} color="inherit">
|
|
|
|
|
{getOptionForDirection(<ArrowBack />, <ArrowForwardIcon />)}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title={t('reader.settings.label.static_navigation')}>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setReaderNavBarWidth(0);
|
|
|
|
|
updateReaderSettings('isStaticNav', !isStaticNav);
|
|
|
|
|
}}
|
|
|
|
|
color={isStaticNav ? 'primary' : 'inherit'}
|
|
|
|
|
>
|
|
|
|
|
<PushPinIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Stack>
|
|
|
|
|
{manga && currentChapter ? (
|
|
|
|
|
<>
|
|
|
|
|
<ReaderNavBarDesktopMetadata
|
|
|
|
|
mangaId={manga.id}
|
|
|
|
|
mangaTitle={manga.title}
|
|
|
|
|
chapterTitle={currentChapter.name}
|
|
|
|
|
scanlator={currentChapter.scanlator}
|
|
|
|
|
/>
|
|
|
|
|
<ReaderNavBarDesktopActions />
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<LoadingPlaceholder />
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
<Stack sx={{ p: 2, gap: 2 }}>
|
|
|
|
|
<Stack sx={{ gap: 1 }}>
|
|
|
|
|
<ReaderNavBarDesktopPageNavigation />
|
|
|
|
|
<ReaderNavBarDesktopChapterNavigation
|
|
|
|
|
chapters={chapters}
|
|
|
|
|
currentChapter={currentChapter}
|
|
|
|
|
nextChapter={nextChapter}
|
|
|
|
|
previousChapter={previousChapter}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
<Divider />
|
|
|
|
|
<ReaderNavBarDesktopQuickSettings openSettings={openSettings} />
|
|
|
|
|
</Stack>
|
2024-10-03 04:02:59 +02:00
|
|
|
</ReaderNavContainer>
|
|
|
|
|
</Drawer>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-12-21 03:46:55 +01:00
|
|
|
|
|
|
|
|
export const ReaderNavBarDesktop = withPropsFrom(
|
2024-12-22 00:41:56 +01:00
|
|
|
memo(BaseReaderNavBarDesktop),
|
2024-12-21 03:46:55 +01:00
|
|
|
[
|
|
|
|
|
useNavBarContext,
|
|
|
|
|
useReaderStateMangaContext,
|
|
|
|
|
useReaderStateChaptersContext,
|
|
|
|
|
userReaderStatePagesContext,
|
2024-12-21 15:36:23 +01:00
|
|
|
ReaderService.useSettingsWithoutDefaultFlag,
|
2024-12-21 03:46:55 +01:00
|
|
|
() => ({ exit: ReaderService.useExit() }),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'setReaderNavBarWidth',
|
|
|
|
|
'manga',
|
|
|
|
|
'chapters',
|
|
|
|
|
'currentChapter',
|
|
|
|
|
'previousChapter',
|
|
|
|
|
'nextChapter',
|
2024-12-21 15:36:23 +01:00
|
|
|
'isStaticNav',
|
2024-12-21 03:46:55 +01:00
|
|
|
'exit',
|
|
|
|
|
],
|
|
|
|
|
);
|