2021-10-29 20:11:23 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-05 05:44:59 +00:00
|
|
|
import React, { useState } from 'react';
|
2021-10-29 20:11:23 +02:00
|
|
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
2022-03-03 18:19:01 +05:30
|
|
|
import {
|
2022-03-05 05:44:59 +00:00
|
|
|
Drawer,
|
|
|
|
|
FormControlLabel,
|
|
|
|
|
IconButton,
|
|
|
|
|
Tabs,
|
|
|
|
|
Tab,
|
|
|
|
|
Box,
|
|
|
|
|
Stack,
|
|
|
|
|
Checkbox,
|
|
|
|
|
ListItem,
|
|
|
|
|
ListItemButton,
|
|
|
|
|
ListItemIcon,
|
|
|
|
|
ListItemText,
|
2022-03-03 18:19:01 +05:30
|
|
|
} from '@mui/material';
|
2021-10-30 16:10:34 +03:30
|
|
|
import useLibraryOptions from 'util/useLibraryOptions';
|
|
|
|
|
import ThreeStateCheckbox from 'components/util/ThreeStateCheckbox';
|
2022-03-04 11:11:46 +00:00
|
|
|
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
|
|
|
|
|
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
|
2022-03-05 05:44:59 +00:00
|
|
|
import TabPanel from 'components/util/TabPanel';
|
|
|
|
|
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
2021-10-29 20:11:23 +02:00
|
|
|
|
2022-03-05 23:08:32 +00:00
|
|
|
function filtersTab(currentTab: number) {
|
2021-11-07 15:59:48 +05:30
|
|
|
const {
|
|
|
|
|
downloaded, setDownloaded, unread, setUnread,
|
|
|
|
|
} = useLibraryOptions();
|
2022-03-05 23:08:32 +00:00
|
|
|
return (
|
|
|
|
|
<TabPanel index={0} currentIndex={currentTab}>
|
|
|
|
|
<Stack direction="column">
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<ThreeStateCheckbox
|
|
|
|
|
name="Unread"
|
|
|
|
|
checked={unread}
|
|
|
|
|
onChange={setUnread}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Unread"
|
|
|
|
|
/>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<ThreeStateCheckbox
|
|
|
|
|
name="Downloaded"
|
|
|
|
|
checked={downloaded}
|
|
|
|
|
onChange={setDownloaded}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Downloaded"
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sortsTab(currentTab: number) {
|
|
|
|
|
const {
|
|
|
|
|
sorts, setSorts, sortDesc, setSortDesc,
|
|
|
|
|
} = useLibraryOptions();
|
|
|
|
|
|
|
|
|
|
const handleChange = (event:
|
|
|
|
|
React.MouseEvent<HTMLDivElement, MouseEvent>, index: string) => {
|
|
|
|
|
if (sorts === index) {
|
|
|
|
|
setSortDesc(!sortDesc);
|
|
|
|
|
} else { setSortDesc(false); }
|
|
|
|
|
setSorts(index);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<TabPanel index={1} currentIndex={currentTab}>
|
|
|
|
|
<Stack direction="column">
|
|
|
|
|
{
|
|
|
|
|
['sortToRead', 'sortAlph', 'sortID'].map((e) => {
|
|
|
|
|
let icon;
|
|
|
|
|
if (sorts === e) {
|
|
|
|
|
icon = !sortDesc ? (<ArrowUpwardIcon color="primary" />)
|
|
|
|
|
: (<ArrowDownwardIcon color="primary" />);
|
|
|
|
|
}
|
|
|
|
|
icon = icon === undefined && sortDesc === undefined && e === 'sortID' ? (<ArrowDownwardIcon color="primary" />) : icon;
|
|
|
|
|
return (
|
|
|
|
|
<ListItem disablePadding>
|
|
|
|
|
<ListItemButton onClick={(event) => handleChange(event, e)}>
|
|
|
|
|
<ListItemIcon>{icon}</ListItemIcon>
|
|
|
|
|
<ListItemText primary={e} />
|
|
|
|
|
</ListItemButton>
|
|
|
|
|
</ListItem>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</Stack>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dispalyTab(currentTab: number) {
|
2022-03-05 05:44:59 +00:00
|
|
|
const { options, setOptions } = useLibraryOptionsContext();
|
|
|
|
|
|
|
|
|
|
function setContextOptions(
|
|
|
|
|
e: React.ChangeEvent<HTMLInputElement>,
|
|
|
|
|
checked: boolean,
|
|
|
|
|
) {
|
|
|
|
|
setOptions((prev) => ({ ...prev, [e.target.name]: checked }));
|
|
|
|
|
}
|
2022-03-05 23:08:32 +00:00
|
|
|
return (
|
|
|
|
|
<TabPanel index={2} currentIndex={currentTab}>
|
|
|
|
|
<Stack direction="column">
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
label="Unread Badges"
|
|
|
|
|
control={(
|
|
|
|
|
<Checkbox
|
|
|
|
|
name="showUnreadBadge"
|
|
|
|
|
checked={options.showUnreadBadge}
|
|
|
|
|
onChange={setContextOptions}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
label="Download Badges"
|
|
|
|
|
control={(
|
|
|
|
|
<Checkbox
|
|
|
|
|
name="showDownloadBadge"
|
|
|
|
|
checked={options.showDownloadBadge}
|
|
|
|
|
onChange={setContextOptions}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Options() {
|
|
|
|
|
const [currentTab, setCurrentTab] = useState<number>(0);
|
2022-03-05 05:44:59 +00:00
|
|
|
|
2021-10-29 20:11:23 +02:00
|
|
|
return (
|
2022-03-05 05:44:59 +00:00
|
|
|
<Box>
|
|
|
|
|
<Tabs
|
|
|
|
|
key={currentTab}
|
|
|
|
|
value={currentTab}
|
|
|
|
|
variant="fullWidth"
|
|
|
|
|
onChange={(e, newTab) => setCurrentTab(newTab)}
|
|
|
|
|
indicatorColor="primary"
|
|
|
|
|
textColor="primary"
|
|
|
|
|
>
|
|
|
|
|
<Tab label="Filter" value={0} />
|
2022-03-05 23:08:32 +00:00
|
|
|
<Tab label="Sort" value={1} />
|
|
|
|
|
<Tab label="Display" value={2} />
|
2022-03-05 05:44:59 +00:00
|
|
|
</Tabs>
|
2022-03-05 23:08:32 +00:00
|
|
|
{filtersTab(currentTab)}
|
|
|
|
|
{sortsTab(currentTab)}
|
|
|
|
|
{dispalyTab(currentTab)}
|
2021-11-15 19:33:04 +03:30
|
|
|
</Box>
|
2021-10-29 20:11:23 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function LibraryOptions() {
|
|
|
|
|
const [filtersOpen, setFiltersOpen] = React.useState(false);
|
|
|
|
|
const { active } = useLibraryOptions();
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => setFiltersOpen(!filtersOpen)}
|
|
|
|
|
color={active ? 'warning' : 'default'}
|
|
|
|
|
>
|
|
|
|
|
<FilterListIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
|
|
<Drawer
|
|
|
|
|
anchor="bottom"
|
|
|
|
|
open={filtersOpen}
|
|
|
|
|
onClose={() => setFiltersOpen(false)}
|
|
|
|
|
PaperProps={{
|
|
|
|
|
style: {
|
2022-03-04 11:11:46 +00:00
|
|
|
maxWidth: 600, padding: '1em', marginLeft: 'auto', marginRight: 'auto',
|
2021-10-29 20:11:23 +02:00
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Options />
|
|
|
|
|
</Drawer>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|