2024-09-28 03:24: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 IconButton from '@mui/material/IconButton';
|
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
|
|
|
import { bindMenu, bindTrigger, usePopupState } from 'material-ui-popup-state/hooks';
|
|
|
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
|
|
|
import Menu from '@mui/material/Menu';
|
|
|
|
|
import Link from '@mui/material/Link';
|
|
|
|
|
import { Link as RouterLink } from 'react-router-dom';
|
|
|
|
|
import Slide from '@mui/material/Slide';
|
2026-03-11 00:11:29 +01:00
|
|
|
import type { Ref } from 'react';
|
|
|
|
|
import { memo } from 'react';
|
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';
|
|
|
|
|
import { TypographyMaxLines } from '@/base/components/texts/TypographyMaxLines.tsx';
|
|
|
|
|
import { makeToast } from '@/base/utils/Toast.ts';
|
2026-03-11 00:11:29 +01:00
|
|
|
import type { MobileHeaderProps } from '@/features/reader/overlay/ReaderOverlay.types.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { LoadingPlaceholder } from '@/base/components/feedback/LoadingPlaceholder.tsx';
|
|
|
|
|
import { AppRoutes } from '@/base/AppRoute.constants.ts';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { ReaderLibraryButton } from '@/features/reader/overlay/navigation/components/ReaderLibraryButton.tsx';
|
|
|
|
|
import { ReaderBookmarkButton } from '@/features/reader/overlay/navigation/components/ReaderBookmarkButton.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { FALLBACK_CHAPTER } from '@/features/chapter/Chapter.constants.ts';
|
|
|
|
|
import { FALLBACK_MANGA } from '@/features/manga/Manga.constants.ts';
|
2025-08-16 02:02:13 +02:00
|
|
|
import { ReaderExitButton } from '@/features/reader/overlay/navigation/components/ReaderExitButton.tsx';
|
2025-07-19 19:09:22 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
2025-09-21 00:50:19 +02:00
|
|
|
import {
|
|
|
|
|
useReaderChaptersStore,
|
|
|
|
|
useReaderScrollbarStore,
|
|
|
|
|
useReaderStore,
|
|
|
|
|
} from '@/features/reader/stores/ReaderStore.ts';
|
2024-09-28 03:24:59 +02:00
|
|
|
|
2025-02-17 03:51:07 +01:00
|
|
|
const DEFAULT_MANGA = { ...FALLBACK_MANGA, title: '' };
|
2024-09-28 03:24:59 +02:00
|
|
|
|
2025-09-24 00:51:13 +02:00
|
|
|
const BaseReaderOverlayHeaderMobile = ({ isVisible, ref }: MobileHeaderProps & { ref?: Ref<HTMLDivElement> }) => {
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
2024-09-28 03:24:59 +02:00
|
|
|
const popupState = usePopupState({ popupId: 'reader-overlay-more-menu', variant: 'popover' });
|
2026-03-11 22:10:34 +01:00
|
|
|
const currentChapter = useReaderChaptersStore('currentChapter');
|
2024-09-28 03:24:59 +02:00
|
|
|
|
2026-03-11 22:10:34 +01:00
|
|
|
const manga = useReaderStore('manga');
|
2026-02-21 17:33:13 +01:00
|
|
|
const scrollbar = useReaderScrollbarStore((state) => state);
|
2025-08-31 12:57:28 +02:00
|
|
|
|
2024-09-28 03:24:59 +02:00
|
|
|
const { id: mangaId, title } = manga ?? DEFAULT_MANGA;
|
2025-02-17 03:51:07 +01:00
|
|
|
const { id: chapterId, name, realUrl, isBookmarked } = currentChapter ?? FALLBACK_CHAPTER;
|
2024-09-28 03:24:59 +02:00
|
|
|
|
|
|
|
|
return (
|
2025-01-02 21:25:35 +01:00
|
|
|
<Slide direction="down" in={isVisible} ref={ref}>
|
2024-09-28 03:24:59 +02:00
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
2025-08-31 16:38:26 +02:00
|
|
|
right: `${scrollbar.ySize}px`,
|
2024-09-28 03:24:59 +02:00
|
|
|
p: 2,
|
2024-12-22 21:59:28 +01:00
|
|
|
pt: (theme) => `max(env(safe-area-inset-top), ${theme.spacing(2)})`,
|
2026-04-25 17:14:08 +02:00
|
|
|
backgroundColor: (theme) => theme.alpha(theme.palette.background.paper, 0.95),
|
2024-09-28 03:24:59 +02:00
|
|
|
pointerEvents: 'all',
|
2024-12-23 02:54:12 +01:00
|
|
|
boxShadow: 2,
|
2024-09-28 03:24:59 +02:00
|
|
|
}}
|
|
|
|
|
>
|
2025-02-17 03:56:40 +01:00
|
|
|
<ReaderExitButton />
|
2024-09-28 03:24:59 +02:00
|
|
|
<Stack sx={{ flexGrow: 1 }}>
|
|
|
|
|
{manga && currentChapter ? (
|
|
|
|
|
<>
|
2025-02-01 14:24:38 +01:00
|
|
|
<CustomTooltip title={title}>
|
2024-09-28 03:24:59 +02:00
|
|
|
<TypographyMaxLines lines={1} component="h1" variant="h5">
|
|
|
|
|
<Link
|
|
|
|
|
component={RouterLink}
|
2024-12-11 20:10:59 +01:00
|
|
|
to={AppRoutes.manga.path(mangaId)}
|
2024-09-28 03:24:59 +02:00
|
|
|
sx={{ textDecoration: 'none', color: 'inherit' }}
|
|
|
|
|
>
|
|
|
|
|
{title}
|
|
|
|
|
</Link>
|
|
|
|
|
</TypographyMaxLines>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
|
|
|
|
<CustomTooltip title={name}>
|
2024-09-28 03:24:59 +02:00
|
|
|
<TypographyMaxLines lines={1}>{name}</TypographyMaxLines>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
2024-09-28 03:24:59 +02:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<LoadingPlaceholder />
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
2025-02-17 03:45:18 +01:00
|
|
|
<ReaderLibraryButton />
|
2025-02-17 03:51:07 +01:00
|
|
|
<ReaderBookmarkButton id={chapterId} isBookmarked={isBookmarked} />
|
2024-09-28 03:24:59 +02:00
|
|
|
<IconButton {...bindTrigger(popupState)} color="inherit">
|
|
|
|
|
<MoreVertIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Menu {...bindMenu(popupState)}>
|
|
|
|
|
<MenuItem
|
|
|
|
|
component={Link}
|
|
|
|
|
disabled={!realUrl}
|
|
|
|
|
href={realUrl ?? ''}
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
2026-01-10 19:45:02 +01:00
|
|
|
{t`Open in browser`}
|
2025-07-19 19:09:22 +02:00
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem
|
|
|
|
|
component={Link}
|
|
|
|
|
disabled={!realUrl}
|
|
|
|
|
href={realUrl ? requestManager.getWebviewUrl(realUrl) : ''}
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
target="_blank"
|
|
|
|
|
>
|
2026-01-10 19:45:02 +01:00
|
|
|
{t`Open in WebView`}
|
2024-09-28 03:24:59 +02:00
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem
|
|
|
|
|
disabled={!realUrl}
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
await navigator.clipboard.writeText(title);
|
2026-01-10 19:45:02 +01:00
|
|
|
makeToast(t`Copied to clipboard`, 'info');
|
2024-09-28 03:24:59 +02:00
|
|
|
}}
|
|
|
|
|
>
|
2026-01-10 19:45:02 +01:00
|
|
|
{t`Share`}
|
2024-09-28 03:24:59 +02:00
|
|
|
</MenuItem>
|
|
|
|
|
</Menu>
|
|
|
|
|
</Stack>
|
|
|
|
|
</Slide>
|
|
|
|
|
);
|
2025-09-24 00:51:13 +02:00
|
|
|
};
|
2024-12-21 03:46:55 +01:00
|
|
|
|
2025-09-20 01:33:27 +02:00
|
|
|
export const ReaderOverlayHeaderMobile = memo(BaseReaderOverlayHeaderMobile);
|