2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-26 23:32:12 +03:30
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-01-26 23:32:12 +03:30
|
|
|
|
2021-09-09 17:51:22 +04:30
|
|
|
import FavoriteIcon from '@mui/icons-material/Favorite';
|
|
|
|
|
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
|
2023-06-04 20:58:44 +02:00
|
|
|
import { styled } from '@mui/material/styles';
|
2024-08-30 04:34:28 +02:00
|
|
|
import { ComponentProps, useEffect } from 'react';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-05-01 23:31:14 +02:00
|
|
|
import { t as translate } from 'i18next';
|
2024-04-14 15:50:12 +02:00
|
|
|
import Link from '@mui/material/Link';
|
2024-05-23 00:40:20 +02:00
|
|
|
import Typography from '@mui/material/Typography';
|
2024-05-23 02:28:37 +02:00
|
|
|
import { useLongPress } from 'use-long-press';
|
2024-08-30 04:34:28 +02:00
|
|
|
import Chip from '@mui/material/Chip';
|
|
|
|
|
import Tooltip from '@mui/material/Tooltip';
|
|
|
|
|
import LaunchIcon from '@mui/icons-material/Launch';
|
2024-08-30 04:36:07 +02:00
|
|
|
import Collapse from '@mui/material/Collapse';
|
2024-08-30 04:34:28 +02:00
|
|
|
import Stack from '@mui/material/Stack';
|
2024-08-30 04:36:07 +02:00
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
|
|
|
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { makeToast } from '@/components/util/Toast';
|
2024-07-08 18:02:50 +02:00
|
|
|
import { Mangas, MangaThumbnailInfo, MangaTrackRecordInfo } from '@/lib/data/Mangas.ts';
|
2024-02-16 21:21:47 +01:00
|
|
|
import { SpinnerImage } from '@/components/util/SpinnerImage.tsx';
|
2024-03-29 00:15:03 +01:00
|
|
|
import { CustomIconButton } from '@/components/atoms/CustomIconButton';
|
2024-03-10 17:36:22 +01:00
|
|
|
import { TrackMangaButton } from '@/components/manga/TrackMangaButton.tsx';
|
2024-04-07 15:33:08 +02:00
|
|
|
import { useManageMangaLibraryState } from '@/components/manga/useManageMangaLibraryState.tsx';
|
2024-05-23 00:40:20 +02:00
|
|
|
import { Metadata as BaseMetadata } from '@/components/atoms/Metadata.tsx';
|
2024-05-23 02:28:37 +02:00
|
|
|
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
2024-07-08 18:02:50 +02:00
|
|
|
import { MangaType, SourceType } from '@/lib/graphql/generated/graphql.ts';
|
2024-08-30 04:36:07 +02:00
|
|
|
import { useLocalStorage } from '@/util/useStorage.tsx';
|
2021-02-21 04:27:41 +03:30
|
|
|
|
2023-06-04 20:58:44 +02:00
|
|
|
const DetailsWrapper = styled('div')(({ theme }) => ({
|
2024-08-30 04:34:28 +02:00
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
gap: theme.spacing(2),
|
|
|
|
|
padding: theme.spacing(1),
|
2023-06-04 20:58:44 +02:00
|
|
|
[theme.breakpoints.up('md')]: {
|
2024-08-30 04:34:28 +02:00
|
|
|
flexBasis: '40%',
|
2023-06-04 20:58:44 +02:00
|
|
|
height: 'calc(100vh - 64px)',
|
|
|
|
|
overflowY: 'auto',
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2024-08-30 04:34:28 +02:00
|
|
|
const TopContentWrapper = styled('div')(() => ({}));
|
2023-06-04 20:58:44 +02:00
|
|
|
|
|
|
|
|
const ThumbnailMetadataWrapper = styled('div')(() => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
}));
|
|
|
|
|
|
2024-08-30 04:34:28 +02:00
|
|
|
const Thumbnail = styled('div')(({ theme }) => ({
|
2023-06-04 20:58:44 +02:00
|
|
|
'& img': {
|
|
|
|
|
borderRadius: 4,
|
2024-08-30 04:34:28 +02:00
|
|
|
width: '150px',
|
2023-06-04 20:58:44 +02:00
|
|
|
height: 'auto',
|
2024-08-30 04:34:28 +02:00
|
|
|
[theme.breakpoints.up('lg')]: {
|
|
|
|
|
width: '200px',
|
|
|
|
|
},
|
|
|
|
|
[theme.breakpoints.up('xl')]: {
|
|
|
|
|
width: '300px',
|
|
|
|
|
},
|
2023-06-04 20:58:44 +02:00
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2024-05-23 00:40:20 +02:00
|
|
|
const MetadataContainer = styled('div')(({ theme }) => ({
|
2024-08-30 04:34:28 +02:00
|
|
|
marginLeft: theme.spacing(1),
|
2023-06-04 20:58:44 +02:00
|
|
|
}));
|
2024-05-23 00:40:20 +02:00
|
|
|
|
2024-08-30 04:34:28 +02:00
|
|
|
const Metadata = (props: ComponentProps<typeof BaseMetadata>) => <BaseMetadata {...props} />;
|
2024-05-23 00:40:20 +02:00
|
|
|
|
2024-03-29 00:15:03 +01:00
|
|
|
const MangaButtonsContainer = styled('div')(({ theme }) => ({
|
2023-06-04 20:58:44 +02:00
|
|
|
display: 'flex',
|
2024-08-30 04:34:28 +02:00
|
|
|
gap: theme.spacing(1),
|
2023-06-04 20:58:44 +02:00
|
|
|
}));
|
2021-01-19 20:20:28 +03:30
|
|
|
|
2023-09-08 00:44:01 +02:00
|
|
|
const OpenSourceButton = ({ url }: { url?: string | null }) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2024-08-30 04:34:28 +02:00
|
|
|
return (
|
|
|
|
|
<Tooltip title={t('global.button.open_site')}>
|
2024-03-29 00:15:03 +01:00
|
|
|
<CustomIconButton
|
2024-08-30 04:34:28 +02:00
|
|
|
size="medium"
|
2024-03-29 00:15:03 +01:00
|
|
|
disabled={!url}
|
|
|
|
|
component={Link}
|
|
|
|
|
href={url ?? undefined}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
2024-08-30 04:34:28 +02:00
|
|
|
variant="outlined"
|
2024-03-29 00:15:03 +01:00
|
|
|
>
|
2024-08-30 04:34:28 +02:00
|
|
|
<LaunchIcon />
|
2024-03-29 00:15:03 +01:00
|
|
|
</CustomIconButton>
|
2024-08-30 04:34:28 +02:00
|
|
|
</Tooltip>
|
2024-03-29 00:15:03 +01:00
|
|
|
);
|
2023-09-08 00:44:01 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-03 23:15:50 +02:00
|
|
|
function getSourceName(source?: Pick<SourceType, 'id' | 'displayName'> | null): string {
|
2023-05-01 23:31:14 +02:00
|
|
|
if (!source) {
|
|
|
|
|
return translate('global.label.unknown');
|
2021-03-17 19:17:03 +03:30
|
|
|
}
|
2023-05-01 23:31:14 +02:00
|
|
|
|
|
|
|
|
return source.displayName ?? source.id;
|
2021-01-19 20:20:28 +03:30
|
|
|
}
|
|
|
|
|
|
2023-09-08 00:44:01 +02:00
|
|
|
function getValueOrUnknown(val?: string | null) {
|
2024-05-23 01:21:20 +02:00
|
|
|
return val ?? translate('global.label.unknown');
|
2021-03-17 19:17:03 +03:30
|
|
|
}
|
|
|
|
|
|
2024-08-30 04:36:07 +02:00
|
|
|
const DESCRIPTION_COLLAPSED_SIZE = 75;
|
2024-08-30 04:34:28 +02:00
|
|
|
const DescriptionGenre = ({
|
|
|
|
|
manga: { description, genre: genres },
|
|
|
|
|
}: {
|
|
|
|
|
manga: Pick<MangaType, 'description' | 'genre'>;
|
2024-08-30 04:36:07 +02:00
|
|
|
}) => {
|
|
|
|
|
const [isCollapsed, setIsCollapsed] = useLocalStorage('isDescriptionGenreCollapsed', true);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Stack sx={{ position: 'relative' }}>
|
|
|
|
|
<Collapse collapsedSize={DESCRIPTION_COLLAPSED_SIZE} in={!isCollapsed}>
|
|
|
|
|
<Typography style={{ whiteSpace: 'pre-line', textAlign: 'justify', textJustify: 'inter-word' }}>
|
|
|
|
|
{description}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Collapse>
|
|
|
|
|
<Stack
|
|
|
|
|
onClick={() => setIsCollapsed(!isCollapsed)}
|
|
|
|
|
sx={{
|
|
|
|
|
pt: 1,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
position: isCollapsed ? 'absolute' : null,
|
|
|
|
|
width: '100%',
|
|
|
|
|
bottom: 0,
|
|
|
|
|
background: (theme) => `linear-gradient(transparent 1px, ${theme.palette.background.paper})`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton sx={{ color: (theme) => (theme.palette.mode === 'light' ? 'black' : 'text') }}>
|
|
|
|
|
{isCollapsed ? <ExpandMoreIcon /> : <ExpandLessIcon />}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Stack>
|
|
|
|
|
</Stack>
|
|
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
flexWrap: isCollapsed ? 'no-wrap' : 'wrap',
|
|
|
|
|
gap: 1,
|
|
|
|
|
overflowX: isCollapsed ? 'auto' : null,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{genres.map((genre) => (
|
|
|
|
|
<Chip label={genre} variant="outlined" />
|
|
|
|
|
))}
|
|
|
|
|
</Stack>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-08-30 04:34:28 +02:00
|
|
|
|
2024-07-08 18:02:50 +02:00
|
|
|
export const MangaDetails = ({
|
|
|
|
|
manga,
|
|
|
|
|
}: {
|
|
|
|
|
manga: Pick<
|
|
|
|
|
MangaType,
|
|
|
|
|
'id' | 'title' | 'author' | 'artist' | 'status' | 'inLibrary' | 'realUrl' | 'description' | 'genre'
|
|
|
|
|
> &
|
|
|
|
|
MangaThumbnailInfo &
|
|
|
|
|
MangaTrackRecordInfo & {
|
|
|
|
|
source?: Pick<SourceType, 'id' | 'displayName'> | null;
|
|
|
|
|
};
|
|
|
|
|
}) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2023-12-27 18:08:16 +01:00
|
|
|
|
2023-05-02 00:35:56 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!manga.source) {
|
|
|
|
|
makeToast(translate('source.error.label.source_not_found'), 'error');
|
|
|
|
|
}
|
|
|
|
|
}, [manga.source]);
|
2023-05-01 23:31:14 +02:00
|
|
|
|
2024-04-07 15:33:08 +02:00
|
|
|
const { CategorySelectComponent, updateLibraryState } = useManageMangaLibraryState(manga);
|
2021-01-19 20:20:28 +03:30
|
|
|
|
2024-05-23 02:28:37 +02:00
|
|
|
const copyTitleLongPressBind = useLongPress(async () => {
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(manga.title);
|
|
|
|
|
makeToast(t('global.label.copied'), 'info');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
defaultPromiseErrorHandler('MangaDetails::copyTitleLongPress')(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-01-19 20:20:28 +03:30
|
|
|
return (
|
2023-12-27 18:08:16 +01:00
|
|
|
<>
|
|
|
|
|
<DetailsWrapper>
|
|
|
|
|
<TopContentWrapper>
|
|
|
|
|
<ThumbnailMetadataWrapper>
|
|
|
|
|
<Thumbnail>
|
2024-02-16 21:21:47 +01:00
|
|
|
<SpinnerImage src={Mangas.getThumbnailUrl(manga)} alt="Manga Thumbnail" />
|
2023-12-27 18:08:16 +01:00
|
|
|
</Thumbnail>
|
2024-05-23 00:40:20 +02:00
|
|
|
<MetadataContainer>
|
2024-05-23 02:28:37 +02:00
|
|
|
<Typography
|
2024-08-30 04:34:28 +02:00
|
|
|
variant="h5"
|
|
|
|
|
component="h2"
|
2024-05-23 02:28:37 +02:00
|
|
|
sx={{ mb: 1, '@media not (pointer: fine)': { userSelect: 'none' } }}
|
|
|
|
|
{...copyTitleLongPressBind()}
|
|
|
|
|
>
|
2024-05-23 00:40:20 +02:00
|
|
|
{manga.title}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Metadata title={t('manga.label.author')} value={getValueOrUnknown(manga.author)} />
|
|
|
|
|
<Metadata title={t('manga.label.artist')} value={getValueOrUnknown(manga.artist)} />
|
|
|
|
|
<Metadata title={t('manga.label.status')} value={getValueOrUnknown(manga.status)} />
|
2024-07-01 19:51:27 +02:00
|
|
|
<Metadata title={t('source.title_one')} value={getSourceName(manga.source)} />
|
2024-05-23 00:40:20 +02:00
|
|
|
</MetadataContainer>
|
2023-12-27 18:08:16 +01:00
|
|
|
</ThumbnailMetadataWrapper>
|
2024-03-29 00:15:03 +01:00
|
|
|
<MangaButtonsContainer>
|
|
|
|
|
<CustomIconButton
|
2024-08-30 04:34:28 +02:00
|
|
|
size="medium"
|
2024-04-07 15:33:08 +02:00
|
|
|
onClick={updateLibraryState}
|
2024-08-30 04:34:28 +02:00
|
|
|
variant={manga.inLibrary ? 'contained' : 'outlined'}
|
2024-03-29 00:15:03 +01:00
|
|
|
>
|
|
|
|
|
{manga.inLibrary ? <FavoriteIcon /> : <FavoriteBorderIcon />}
|
|
|
|
|
{manga.inLibrary ? t('manga.button.in_library') : t('manga.button.add_to_library')}
|
|
|
|
|
</CustomIconButton>
|
2024-03-10 17:36:22 +01:00
|
|
|
<TrackMangaButton manga={manga} />
|
2023-12-27 18:08:16 +01:00
|
|
|
<OpenSourceButton url={manga.realUrl} />
|
|
|
|
|
</MangaButtonsContainer>
|
|
|
|
|
</TopContentWrapper>
|
2024-08-30 04:34:28 +02:00
|
|
|
<DescriptionGenre manga={manga} />
|
2023-12-27 18:08:16 +01:00
|
|
|
</DetailsWrapper>
|
2024-04-07 15:33:08 +02:00
|
|
|
{CategorySelectComponent}
|
2023-12-27 18:08:16 +01:00
|
|
|
</>
|
2021-01-19 20:20:28 +03:30
|
|
|
);
|
2022-11-09 18:09:15 +01:00
|
|
|
};
|