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 IconButton from '@mui/material/IconButton';
|
|
|
|
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
2025-01-17 01:38:19 +01:00
|
|
|
import PushPinOutlinedIcon from '@mui/icons-material/PushPinOutlined';
|
2024-10-03 04:02:59 +02:00
|
|
|
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';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { useLingui } from '@lingui/react/macro';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { ReaderNavBarDesktopProps } from '@/features/reader/overlay/ReaderOverlay.types.ts';
|
|
|
|
|
import { ReaderNavContainer } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavContainer.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopMetadata } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavBarDesktopMetadata.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopPageNavigation } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavBarDesktopPageNavigation.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopChapterNavigation } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavBarDesktopChapterNavigation.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopQuickSettings } from '@/features/reader/overlay/navigation/desktop/quick-settings/ReaderNavBarDesktopQuickSettings.tsx';
|
|
|
|
|
import { ReaderNavBarDesktopActions } from '@/features/reader/overlay/navigation/desktop/components/ReaderNavBarDesktopActions.tsx';
|
2025-08-16 02:14:49 +02:00
|
|
|
import { useNavBarContext } from '@/features/navigation-bar/NavbarContext.tsx';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { useResizeObserver } from '@/base/hooks/useResizeObserver.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { ReaderService } from '@/features/reader/services/ReaderService.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { LoadingPlaceholder } from '@/base/components/feedback/LoadingPlaceholder.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { NavbarContextType } from '@/features/navigation-bar/NavigationBar.types.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { withPropsFrom } from '@/base/hoc/withPropsFrom.tsx';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { ReaderExitButton } from '@/features/reader/overlay/navigation/components/ReaderExitButton.tsx';
|
2025-09-21 00:50:19 +02:00
|
|
|
import {
|
|
|
|
|
useReaderChaptersStore,
|
|
|
|
|
useReaderSettingsStore,
|
|
|
|
|
useReaderStore,
|
|
|
|
|
} from '@/features/reader/stores/ReaderStore.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,
|
2025-09-20 14:15:40 +02:00
|
|
|
}: ReaderNavBarDesktopProps & Pick<NavbarContextType, 'setReaderNavBarWidth'>) => {
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
2025-09-21 00:28:38 +02:00
|
|
|
const manga = useReaderStore((state) => state.manga);
|
2025-11-29 15:26:57 +01:00
|
|
|
const {
|
|
|
|
|
chapters,
|
|
|
|
|
currentChapterId,
|
|
|
|
|
currentChapterName,
|
|
|
|
|
currentChapterNumber,
|
|
|
|
|
currentChapterScanlator,
|
|
|
|
|
previousChapter,
|
|
|
|
|
nextChapter,
|
|
|
|
|
} = useReaderChaptersStore((state) => ({
|
2025-09-20 01:33:27 +02:00
|
|
|
chapters: state.chapters.chapters,
|
2025-11-29 15:26:57 +01:00
|
|
|
currentChapterId: state.chapters.currentChapter?.id,
|
|
|
|
|
currentChapterName: state.chapters.currentChapter?.name,
|
|
|
|
|
currentChapterNumber: state.chapters.currentChapter?.chapterNumber,
|
|
|
|
|
currentChapterScanlator: state.chapters.currentChapter?.scanlator,
|
2025-09-20 01:33:27 +02:00
|
|
|
previousChapter: state.chapters.previousChapter,
|
|
|
|
|
nextChapter: state.chapters.nextChapter,
|
|
|
|
|
}));
|
2025-09-21 00:50:19 +02:00
|
|
|
const isStaticNav = useReaderSettingsStore((state) => state.settings.isStaticNav);
|
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' }}>
|
2025-02-17 03:56:40 +01:00
|
|
|
<ReaderExitButton />
|
2026-01-10 19:45:02 +01:00
|
|
|
<CustomTooltip title={t`Static navigation`}>
|
2024-12-22 21:53:03 +01:00
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setReaderNavBarWidth(0);
|
2025-08-31 12:57:28 +02:00
|
|
|
ReaderService.updateSetting('isStaticNav', !isStaticNav);
|
2024-12-22 21:53:03 +01:00
|
|
|
}}
|
|
|
|
|
color={isStaticNav ? 'primary' : 'inherit'}
|
|
|
|
|
>
|
2025-01-17 01:38:19 +01:00
|
|
|
{isStaticNav ? <PushPinIcon /> : <PushPinOutlinedIcon />}
|
2024-12-22 21:53:03 +01:00
|
|
|
</IconButton>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
2024-12-22 21:53:03 +01:00
|
|
|
</Stack>
|
2025-11-29 15:26:57 +01:00
|
|
|
{manga && currentChapterId !== undefined ? (
|
2024-12-22 21:53:03 +01:00
|
|
|
<>
|
|
|
|
|
<ReaderNavBarDesktopMetadata
|
|
|
|
|
mangaId={manga.id}
|
|
|
|
|
mangaTitle={manga.title}
|
2025-11-29 15:26:57 +01:00
|
|
|
chapterTitle={currentChapterName ?? ''}
|
|
|
|
|
scanlator={currentChapterScanlator}
|
2024-12-22 21:53:03 +01:00
|
|
|
/>
|
|
|
|
|
<ReaderNavBarDesktopActions />
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<LoadingPlaceholder />
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
<Stack sx={{ p: 2, gap: 2 }}>
|
|
|
|
|
<Stack sx={{ gap: 1 }}>
|
|
|
|
|
<ReaderNavBarDesktopPageNavigation />
|
|
|
|
|
<ReaderNavBarDesktopChapterNavigation
|
|
|
|
|
chapters={chapters}
|
2025-11-29 15:26:57 +01:00
|
|
|
currentChapterId={currentChapterId}
|
|
|
|
|
currentChapterName={currentChapterName}
|
|
|
|
|
currentChapterNumber={currentChapterNumber}
|
2024-12-22 21:53:03 +01:00
|
|
|
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),
|
2025-09-20 14:15:40 +02:00
|
|
|
[useNavBarContext],
|
|
|
|
|
['setReaderNavBarWidth'],
|
2024-12-21 03:46:55 +01:00
|
|
|
);
|