2022-03-06 21:02:06 +00: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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-03-06 21:02:06 +00:00
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
import { IconButton, Menu, MenuItem, FormControlLabel, Radio } from '@mui/material';
|
2022-03-06 21:02:06 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import ViewModuleIcon from '@mui/icons-material/ViewModule';
|
2022-12-20 07:05:31 +02:00
|
|
|
import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-03-06 21:02:06 +00:00
|
|
|
|
2022-12-20 07:05:31 +02:00
|
|
|
// TODO: clean up this to use a FormControl, and remove dependency on name o radio button
|
2022-03-06 21:02:06 +00:00
|
|
|
export default function SourceGridLayout() {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
const {
|
|
|
|
|
options: { SourcegridLayout },
|
|
|
|
|
setOptions,
|
|
|
|
|
} = useLibraryOptionsContext();
|
2022-03-06 21:02:06 +00:00
|
|
|
|
|
|
|
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
|
const handleClick = (event: any) => {
|
|
|
|
|
setAnchorEl(event.currentTarget);
|
|
|
|
|
};
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
setAnchorEl(null);
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
function setGridContextOptions(e: React.ChangeEvent<HTMLInputElement>, checked: boolean) {
|
2022-03-06 21:02:06 +00:00
|
|
|
if (checked) {
|
|
|
|
|
setOptions((prev: any) => ({ ...prev, SourcegridLayout: parseInt(e.target.name, 10) }));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={handleClick}
|
|
|
|
|
size="small"
|
|
|
|
|
sx={{ ml: 2 }}
|
|
|
|
|
aria-controls={open ? 'account-menu' : undefined}
|
|
|
|
|
aria-haspopup="true"
|
|
|
|
|
aria-expanded={open ? 'true' : undefined}
|
|
|
|
|
>
|
|
|
|
|
<ViewModuleIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Menu
|
|
|
|
|
id="basic-menu"
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
MenuListProps={{ 'aria-labelledby': 'basic-button' }}
|
|
|
|
|
>
|
|
|
|
|
<MenuItem onClick={handleClose}>
|
|
|
|
|
<FormControlLabel
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.compact_grid')}
|
2022-12-20 07:05:31 +02:00
|
|
|
value={GridLayout.Compact}
|
2023-02-06 10:06:33 +01:00
|
|
|
control={
|
2022-03-06 21:02:06 +00:00
|
|
|
<Radio
|
2022-12-20 07:05:31 +02:00
|
|
|
name={GridLayout.Compact.toString()}
|
2023-02-08 18:19:26 +01:00
|
|
|
checked={SourcegridLayout === GridLayout.Compact || SourcegridLayout === undefined}
|
2022-03-06 21:02:06 +00:00
|
|
|
onChange={setGridContextOptions}
|
|
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2022-03-06 21:02:06 +00:00
|
|
|
/>
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem onClick={handleClose}>
|
|
|
|
|
<FormControlLabel
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.comfortable_grid')}
|
2023-02-06 10:06:33 +01:00
|
|
|
control={
|
2022-03-06 21:02:06 +00:00
|
|
|
<Radio
|
2022-12-20 07:05:31 +02:00
|
|
|
name={GridLayout.Comfortable.toString()}
|
|
|
|
|
checked={SourcegridLayout === GridLayout.Comfortable}
|
2022-03-06 21:02:06 +00:00
|
|
|
onChange={setGridContextOptions}
|
|
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2022-03-06 21:02:06 +00:00
|
|
|
/>
|
2022-03-06 21:03:15 +00:00
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem onClick={handleClose}>
|
|
|
|
|
<FormControlLabel
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.list')}
|
2023-02-06 10:06:33 +01:00
|
|
|
control={
|
2022-03-06 21:03:15 +00:00
|
|
|
<Radio
|
2022-12-20 07:05:31 +02:00
|
|
|
name={GridLayout.List.toString()}
|
|
|
|
|
checked={SourcegridLayout === GridLayout.List}
|
2022-03-06 21:03:15 +00:00
|
|
|
onChange={setGridContextOptions}
|
|
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2022-03-06 21:03:15 +00:00
|
|
|
/>
|
2022-03-06 21:02:06 +00:00
|
|
|
</MenuItem>
|
|
|
|
|
</Menu>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|