2024-04-07 21:30:47 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-04-14 15:50:12 +02:00
|
|
|
import { styled } from '@mui/material/styles';
|
2024-04-07 21:30:47 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-04-14 15:50:12 +02:00
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
2024-10-07 13:31:23 +02:00
|
|
|
import { MangaCardMode } from '@/modules/manga/Manga.types.ts';
|
2024-10-05 23:22:42 +02:00
|
|
|
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
2024-12-30 03:49:39 +01:00
|
|
|
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
2025-03-29 03:12:36 +01:00
|
|
|
import { MUIUtil } from '@/lib/mui/MUI.util.ts';
|
2024-04-07 21:30:47 +02:00
|
|
|
|
2024-08-30 21:19:40 +02:00
|
|
|
const BadgeContainer = styled('div')(({ theme }) => ({
|
2024-04-07 21:30:47 +02:00
|
|
|
display: 'flex',
|
|
|
|
|
height: 'fit-content',
|
2024-08-30 21:19:40 +02:00
|
|
|
borderRadius: theme.shape.borderRadius,
|
2024-04-07 21:30:47 +02:00
|
|
|
overflow: 'hidden',
|
2024-08-30 21:19:40 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const Badge = styled(Typography)(({ theme }) => ({
|
|
|
|
|
color: theme.palette.primary.contrastText,
|
|
|
|
|
paddingInline: theme.spacing(0.3),
|
|
|
|
|
}));
|
2024-04-07 21:30:47 +02:00
|
|
|
|
|
|
|
|
export const MangaBadges = ({
|
|
|
|
|
inLibraryIndicator,
|
|
|
|
|
updateLibraryState,
|
|
|
|
|
isInLibrary,
|
|
|
|
|
unread,
|
|
|
|
|
downloadCount,
|
2024-04-11 02:02:31 +02:00
|
|
|
mode,
|
2024-04-07 21:30:47 +02:00
|
|
|
}: {
|
|
|
|
|
inLibraryIndicator?: boolean;
|
|
|
|
|
updateLibraryState: () => void;
|
|
|
|
|
isInLibrary: boolean;
|
|
|
|
|
unread?: number;
|
|
|
|
|
downloadCount?: number;
|
2024-04-11 02:02:31 +02:00
|
|
|
mode: MangaCardMode;
|
2024-04-07 21:30:47 +02:00
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2024-05-23 02:29:08 +02:00
|
|
|
const isTouchDevice = MediaQuery.useIsTouchDevice();
|
|
|
|
|
|
2024-04-07 21:30:47 +02:00
|
|
|
const {
|
2024-12-30 03:49:39 +01:00
|
|
|
settings: { showUnreadBadge, showDownloadBadge },
|
|
|
|
|
} = useMetadataServerSettings();
|
2024-04-07 21:30:47 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BadgeContainer>
|
2024-05-23 02:29:08 +02:00
|
|
|
{!isTouchDevice && inLibraryIndicator && mode === 'source' && (
|
2024-04-07 21:30:47 +02:00
|
|
|
<Button
|
|
|
|
|
className="source-manga-library-state-button"
|
|
|
|
|
component="div"
|
|
|
|
|
variant="contained"
|
|
|
|
|
size="small"
|
2025-03-29 03:12:36 +01:00
|
|
|
{...MUIUtil.preventRippleProp()}
|
2024-04-07 21:30:47 +02:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
updateLibraryState();
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'none',
|
|
|
|
|
}}
|
|
|
|
|
color={isInLibrary ? 'error' : 'primary'}
|
|
|
|
|
>
|
|
|
|
|
{t(isInLibrary ? 'manga.action.library.remove.label.action' : 'manga.button.add_to_library')}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{inLibraryIndicator && isInLibrary && (
|
2024-09-04 18:03:59 +02:00
|
|
|
<Typography
|
|
|
|
|
className="source-manga-library-state-indicator"
|
2024-09-05 02:35:08 +02:00
|
|
|
sx={{ backgroundColor: 'primary.dark', color: 'primary.contrastText', p: 0.3 }}
|
2024-09-04 18:03:59 +02:00
|
|
|
>
|
2024-04-07 21:30:47 +02:00
|
|
|
{t('manga.button.in_library')}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
2024-05-08 19:11:23 +02:00
|
|
|
{((showUnreadBadge && mode === 'default') || mode === 'duplicate') && (unread ?? 0) > 0 && (
|
2024-09-05 02:35:08 +02:00
|
|
|
<Badge sx={{ backgroundColor: 'primary.main', color: 'primary.contrastText' }}>{unread}</Badge>
|
2024-04-07 21:30:47 +02:00
|
|
|
)}
|
2024-05-08 19:11:23 +02:00
|
|
|
{((showDownloadBadge && mode === 'default') || mode === 'duplicate') && (downloadCount ?? 0) > 0 && (
|
2024-08-30 21:19:40 +02:00
|
|
|
<Badge
|
2024-04-07 21:30:47 +02:00
|
|
|
sx={{
|
2024-09-05 02:35:08 +02:00
|
|
|
backgroundColor: 'secondary.main',
|
|
|
|
|
color: 'secondary.contrastText',
|
2024-04-07 21:30:47 +02:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{downloadCount}
|
2024-08-30 21:19:40 +02:00
|
|
|
</Badge>
|
2024-04-07 21:30:47 +02:00
|
|
|
)}
|
|
|
|
|
</BadgeContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|