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-03 18:19:01 +05:30
|
|
|
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 {
|
|
|
|
|
Drawer,
|
|
|
|
|
FormControlLabel,
|
|
|
|
|
IconButton,
|
|
|
|
|
Tabs,
|
|
|
|
|
Tab,
|
|
|
|
|
Box,
|
|
|
|
|
Stack,
|
|
|
|
|
Checkbox,
|
|
|
|
|
Radio,
|
|
|
|
|
Switch,
|
|
|
|
|
} from '@mui/material';
|
2021-10-30 16:10:34 +03:30
|
|
|
import useLibraryOptions from 'util/useLibraryOptions';
|
|
|
|
|
import ThreeStateCheckbox from 'components/util/ThreeStateCheckbox';
|
2022-03-03 18:19:01 +05:30
|
|
|
import TabPanel from 'components/util/TabPanel';
|
|
|
|
|
import { useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
|
|
|
|
import SortIcon from '@mui/icons-material/Sort';
|
2021-10-29 20:11:23 +02:00
|
|
|
|
|
|
|
|
function Options() {
|
2021-11-07 15:59:48 +05:30
|
|
|
const {
|
|
|
|
|
downloaded, setDownloaded, unread, setUnread,
|
|
|
|
|
} = useLibraryOptions();
|
2022-03-03 18:19:01 +05:30
|
|
|
const [currentTab, setCurrentTab] = useState<number>(0);
|
|
|
|
|
const { options, setOptions } = useLibraryOptionsContext();
|
|
|
|
|
|
|
|
|
|
function setContextOptions(
|
|
|
|
|
e: React.ChangeEvent<HTMLInputElement>,
|
|
|
|
|
checked: boolean,
|
|
|
|
|
) {
|
|
|
|
|
setOptions((prev) => ({ ...prev, [e.target.name]: checked }));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 20:11:23 +02:00
|
|
|
return (
|
2022-03-03 18:19:01 +05:30
|
|
|
<Box>
|
|
|
|
|
<Tabs
|
|
|
|
|
key={currentTab}
|
|
|
|
|
value={currentTab}
|
|
|
|
|
variant="fullWidth"
|
|
|
|
|
onChange={(e, newTab) => setCurrentTab(newTab)}
|
|
|
|
|
indicatorColor="primary"
|
|
|
|
|
textColor="primary"
|
|
|
|
|
>
|
|
|
|
|
<Tab label="Filter" value={0} />
|
|
|
|
|
<Tab label="Display" value={1} />
|
|
|
|
|
</Tabs>
|
|
|
|
|
<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>
|
|
|
|
|
<TabPanel index={1} 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>
|
2021-11-15 19:33:04 +03:30
|
|
|
</Box>
|
2021-10-29 20:11:23 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 06:16:21 +00:00
|
|
|
function SortOptions() {
|
|
|
|
|
const {
|
|
|
|
|
sorts, setSorts, sortDesc, setSortDesc,
|
|
|
|
|
} = useLibraryOptions();
|
|
|
|
|
|
2022-03-03 18:19:01 +05:30
|
|
|
const handleSortChange = (name: string) => (event: { target: { checked: boolean } }) => {
|
2022-02-24 06:16:21 +00:00
|
|
|
setSorts(event.target.checked ? name : undefined);
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-03 18:19:01 +05:30
|
|
|
const handleOrderChange = () => (event: { target: { checked: boolean } }) => {
|
2022-02-24 06:16:21 +00:00
|
|
|
setSortDesc(event.target.checked);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
2022-03-03 18:19:01 +05:30
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<Switch
|
|
|
|
|
name="sortDesc"
|
|
|
|
|
checked={sortDesc === true}
|
|
|
|
|
onChange={handleOrderChange()}
|
|
|
|
|
color="default"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Asc/Desc"
|
|
|
|
|
/>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<Radio
|
|
|
|
|
name="sortToRead"
|
|
|
|
|
checked={sorts === 'sortToRead'}
|
|
|
|
|
onChange={handleSortChange('sortToRead')}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Sort by left to read"
|
|
|
|
|
/>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<Radio
|
|
|
|
|
name="sortAlph"
|
|
|
|
|
checked={sorts === 'sortAlph'}
|
|
|
|
|
onChange={handleSortChange('sortAlph')}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Sort alphbetical"
|
|
|
|
|
/>
|
|
|
|
|
<FormControlLabel
|
|
|
|
|
control={(
|
|
|
|
|
<Radio
|
|
|
|
|
name="sortID"
|
|
|
|
|
checked={sorts === 'sortID' || sorts === undefined}
|
|
|
|
|
onChange={handleSortChange('sortID')}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
label="Sort by ID"
|
|
|
|
|
/>
|
2022-02-24 06:16:21 +00:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 20:11:23 +02:00
|
|
|
export default function LibraryOptions() {
|
|
|
|
|
const [filtersOpen, setFiltersOpen] = React.useState(false);
|
2022-02-24 06:16:21 +00:00
|
|
|
const [sortsOpen, setSortsOpen] = React.useState(false);
|
2021-10-29 20:11:23 +02:00
|
|
|
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-03 18:19:01 +05:30
|
|
|
maxWidth: 600,
|
|
|
|
|
padding: '1em',
|
|
|
|
|
marginLeft: 'auto',
|
|
|
|
|
marginRight: 'auto',
|
2021-10-29 20:11:23 +02:00
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Options />
|
|
|
|
|
</Drawer>
|
|
|
|
|
|
2022-02-24 06:16:21 +00:00
|
|
|
<IconButton
|
|
|
|
|
onClick={() => setSortsOpen(!filtersOpen)}
|
|
|
|
|
color={active ? 'warning' : 'default'}
|
|
|
|
|
>
|
|
|
|
|
<SortIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
|
|
<Drawer
|
|
|
|
|
anchor="bottom"
|
|
|
|
|
open={sortsOpen}
|
|
|
|
|
onClose={() => setSortsOpen(false)}
|
|
|
|
|
PaperProps={{
|
|
|
|
|
style: {
|
2022-03-03 18:19:01 +05:30
|
|
|
maxWidth: 600,
|
|
|
|
|
padding: '1em',
|
|
|
|
|
marginLeft: 'auto',
|
|
|
|
|
marginRight: 'auto',
|
2022-02-24 06:16:21 +00:00
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SortOptions />
|
|
|
|
|
</Drawer>
|
2021-10-29 20:11:23 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|