/* * 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'; import { GridLayout, useLibraryOptionsContext } from 'components/context/LibraryOptionsContext'; 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 { open: boolean, onClose: () => void, } const LibraryOptionsPanel: React.FC = ({ open, onClose }) => { const { options, setOptions } = useLibraryOptionsContext(); const handleFilterChange = ( key: T, value: LibraryOptions[T], ) => { setOptions((v) => ({ ...v, [key]: value })); }; return ( open={open} onClose={onClose} tabs={['filter', 'sort', 'display']} tabTitle={(key) => TITLES[key]} tabContent={(key) => { if (key === 'filter') { return ( <> handleFilterChange('unread', c)} /> handleFilterChange('downloaded', c)} /> ); } if (key === 'sort') { return SORT_OPTIONS.map(([mode, label]) => ( (mode !== options.sorts ? handleFilterChange('sorts', mode) : handleFilterChange('sortDesc', !options.sortDesc))} /> )); } if (key === 'display') { const { gridLayout, showDownloadBadge, showUnreadBadge } = options; return ( <> Display mode handleFilterChange('gridLayout', Number(e.target.value))} value={gridLayout} > Badges handleFilterChange('showUnreadBadge', !showUnreadBadge)} /> handleFilterChange('showDownloadBadge', !showDownloadBadge)} /> ); } return null; }} /> ); }; export default LibraryOptionsPanel;