2022-11-24 09:41:03 +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 { FormLabel, RadioGroup } from '@mui/material';
|
|
|
|
|
import CheckboxInput from 'components/atoms/CheckboxInput';
|
|
|
|
|
import RadioInput from 'components/atoms/RadioInput';
|
|
|
|
|
import SortRadioInput from 'components/atoms/SortRadioInput';
|
|
|
|
|
import ThreeStateCheckboxInput from 'components/atoms/ThreeStateCheckboxInput';
|
2022-12-20 07:05:31 +02:00
|
|
|
import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext';
|
2022-11-24 09:41:03 +01:00
|
|
|
import OptionsTabs from 'components/molecules/OptionsTabs';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
const TITLES = {
|
|
|
|
|
filter: 'Filter',
|
|
|
|
|
sort: 'Sort',
|
|
|
|
|
display: 'Display',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const SORT_OPTIONS: [LibrarySortMode, string][] = [
|
|
|
|
|
['sortToRead', 'By Unread chapters'],
|
|
|
|
|
['sortAlph', 'Alphabetically'],
|
|
|
|
|
['sortID', 'By ID'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
2022-11-24 09:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LibraryOptionsPanel: React.FC<IProps> = ({ open, onClose }) => {
|
|
|
|
|
const { options, setOptions } = useLibraryOptionsContext();
|
|
|
|
|
|
|
|
|
|
const handleFilterChange = <T extends keyof LibraryOptions>(
|
|
|
|
|
key: T,
|
|
|
|
|
value: LibraryOptions[T],
|
|
|
|
|
) => {
|
|
|
|
|
setOptions((v) => ({ ...v, [key]: value }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<OptionsTabs<'filter' | 'sort' | 'display'>
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
tabs={['filter', 'sort', 'display']}
|
|
|
|
|
tabTitle={(key) => TITLES[key]}
|
|
|
|
|
tabContent={(key) => {
|
|
|
|
|
if (key === 'filter') {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label="Unread"
|
|
|
|
|
checked={options.unread}
|
|
|
|
|
onChange={(c) => handleFilterChange('unread', c)}
|
|
|
|
|
/>
|
|
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label="Downloaded"
|
|
|
|
|
checked={options.downloaded}
|
|
|
|
|
onChange={(c) => handleFilterChange('downloaded', c)}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (key === 'sort') {
|
|
|
|
|
return SORT_OPTIONS.map(([mode, label]) => (
|
|
|
|
|
<SortRadioInput
|
|
|
|
|
key={mode}
|
|
|
|
|
label={label}
|
|
|
|
|
checked={options.sorts === mode}
|
|
|
|
|
sortDescending={options.sortDesc}
|
2023-02-06 10:06:33 +01:00
|
|
|
onClick={() =>
|
|
|
|
|
mode !== options.sorts
|
|
|
|
|
? handleFilterChange('sorts', mode)
|
|
|
|
|
: handleFilterChange('sortDesc', !options.sortDesc)
|
|
|
|
|
}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
if (key === 'display') {
|
|
|
|
|
const { gridLayout, showDownloadBadge, showUnreadBadge } = options;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<FormLabel>Display mode</FormLabel>
|
|
|
|
|
<RadioGroup
|
2023-02-06 10:06:33 +01:00
|
|
|
onChange={(e) =>
|
|
|
|
|
handleFilterChange('gridLayout', Number(e.target.value))
|
|
|
|
|
}
|
2022-11-24 09:41:03 +01:00
|
|
|
value={gridLayout}
|
|
|
|
|
>
|
2023-02-06 10:06:33 +01:00
|
|
|
<RadioInput
|
|
|
|
|
label="Compact grid"
|
|
|
|
|
value={GridLayout.Compact}
|
|
|
|
|
checked={
|
|
|
|
|
gridLayout == null || gridLayout === GridLayout.Compact
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
<RadioInput
|
|
|
|
|
label="Comfortable grid"
|
|
|
|
|
value={GridLayout.Comfortable}
|
|
|
|
|
checked={gridLayout === GridLayout.Comfortable}
|
|
|
|
|
/>
|
|
|
|
|
<RadioInput
|
|
|
|
|
label="List"
|
|
|
|
|
value={GridLayout.List}
|
|
|
|
|
checked={gridLayout === GridLayout.List}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</RadioGroup>
|
|
|
|
|
|
|
|
|
|
<FormLabel sx={{ mt: 2 }}>Badges</FormLabel>
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
label="Unread Badges"
|
|
|
|
|
checked={showUnreadBadge === true}
|
2023-02-06 10:06:33 +01:00
|
|
|
onChange={() =>
|
|
|
|
|
handleFilterChange('showUnreadBadge', !showUnreadBadge)
|
|
|
|
|
}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
label="Download Badges"
|
|
|
|
|
checked={showDownloadBadge === true}
|
2023-02-06 10:06:33 +01:00
|
|
|
onChange={() =>
|
|
|
|
|
handleFilterChange('showDownloadBadge', !showDownloadBadge)
|
|
|
|
|
}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default LibraryOptionsPanel;
|