2022-11-09 18:09:15 +01: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 Label from '@mui/icons-material/Label';
|
|
|
|
|
import MoreHoriz from '@mui/icons-material/MoreHoriz';
|
|
|
|
|
import Refresh from '@mui/icons-material/Refresh';
|
|
|
|
|
import {
|
2023-02-06 10:06:33 +01:00
|
|
|
IconButton,
|
|
|
|
|
ListItemIcon,
|
|
|
|
|
ListItemText,
|
|
|
|
|
Menu,
|
|
|
|
|
MenuItem,
|
|
|
|
|
Tooltip,
|
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2022-11-09 18:09:15 +01:00
|
|
|
} from '@mui/material';
|
|
|
|
|
import CategorySelect from 'components/navbar/action/CategorySelect';
|
|
|
|
|
import React, { useState } from 'react';
|
2023-02-24 16:40:37 +01:00
|
|
|
import { IManga } from 'typings';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-11-09 18:09:15 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
manga: IManga;
|
|
|
|
|
onRefresh: () => any;
|
|
|
|
|
refreshing: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MangaToolbarMenu = ({ manga, onRefresh, refreshing }: IProps) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2022-11-09 18:09:15 +01:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const isLargeScreen = useMediaQuery(theme.breakpoints.up('sm'));
|
|
|
|
|
|
|
|
|
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
setAnchorEl(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [editCategories, setEditCategories] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{isLargeScreen && (
|
|
|
|
|
<>
|
2023-03-23 13:59:32 +01:00
|
|
|
<Tooltip title={t('manga.label.reload_from_source')}>
|
2023-02-06 10:06:33 +01:00
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
onRefresh();
|
|
|
|
|
}}
|
|
|
|
|
disabled={refreshing}
|
|
|
|
|
>
|
2022-11-09 18:09:15 +01:00
|
|
|
<Refresh />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
{manga.inLibrary && (
|
2023-03-23 13:59:32 +01:00
|
|
|
<Tooltip title={t('manga.label.edit_categories')}>
|
2023-02-06 10:06:33 +01:00
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setEditCategories(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-11-09 18:09:15 +01:00
|
|
|
<Label />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{!isLargeScreen && (
|
|
|
|
|
<>
|
|
|
|
|
<IconButton
|
|
|
|
|
id="chaptersMenuButton"
|
|
|
|
|
aria-controls={open ? 'chaptersMenu' : undefined}
|
|
|
|
|
aria-haspopup="true"
|
|
|
|
|
aria-expanded={open ? 'true' : undefined}
|
|
|
|
|
onClick={(e) => setAnchorEl(e.currentTarget)}
|
|
|
|
|
>
|
|
|
|
|
<MoreHoriz />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Menu
|
|
|
|
|
id="chaptersMenu"
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
MenuListProps={{
|
|
|
|
|
'aria-labelledby': 'chaptersMenuButton',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<MenuItem
|
2023-02-06 10:06:33 +01:00
|
|
|
onClick={() => {
|
|
|
|
|
onRefresh();
|
|
|
|
|
handleClose();
|
|
|
|
|
}}
|
2022-11-09 18:09:15 +01:00
|
|
|
disabled={refreshing}
|
|
|
|
|
>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<Refresh fontSize="small" />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText>{t('manga.label.reload_from_source')}</ListItemText>
|
2022-11-09 18:09:15 +01:00
|
|
|
</MenuItem>
|
|
|
|
|
{manga.inLibrary && (
|
|
|
|
|
<MenuItem
|
2023-02-06 10:06:33 +01:00
|
|
|
onClick={() => {
|
|
|
|
|
setEditCategories(true);
|
|
|
|
|
handleClose();
|
|
|
|
|
}}
|
2022-11-09 18:09:15 +01:00
|
|
|
>
|
|
|
|
|
<ListItemIcon>
|
|
|
|
|
<Label fontSize="small" />
|
|
|
|
|
</ListItemIcon>
|
2023-03-23 13:59:32 +01:00
|
|
|
<ListItemText>{t('manga.label.edit_categories')}</ListItemText>
|
2022-11-09 18:09:15 +01:00
|
|
|
</MenuItem>
|
|
|
|
|
)}
|
|
|
|
|
</Menu>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
<CategorySelect open={editCategories} setOpen={setEditCategories} mangaId={manga.id} />
|
2022-11-09 18:09:15 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MangaToolbarMenu;
|