/* * 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 React from 'react'; import { useTranslation } from 'react-i18next'; import { LibraryOptions, LibrarySortMode, TranslationKey } from '@/typings'; 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'; const TITLES: { [key in 'filter' | 'sort' | 'display']: TranslationKey } = { filter: 'global.label.filter', sort: 'global.label.sort', display: 'global.label.display', }; const SORT_OPTIONS: [LibrarySortMode, TranslationKey][] = [ ['sortToRead', 'library.option.sort.label.by_unread_chapters'], ['sortAlph', 'library.option.sort.label.alphabetically'], ['sortDateAdded', 'library.option.sort.label.by_date_added'], ['sortLastRead', 'library.option.sort.label.by_last_read'], ]; interface IProps { open: boolean; onClose: () => void; } const LibraryOptionsPanel: React.FC = ({ open, onClose }) => { const { t } = useTranslation(); 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) => t(TITLES[key]) as string} 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, showTabSize } = options; return ( <> {t('global.grid_layout.title')} handleFilterChange('gridLayout', Number(e.target.value))} value={gridLayout} > {t('library.option.display.badge.title')} handleFilterChange('showUnreadBadge', !showUnreadBadge)} /> handleFilterChange('showDownloadBadge', !showDownloadBadge)} /> {t('library.option.display.tab.title')} handleFilterChange('showTabSize', !showTabSize)} /> ); } return null; }} /> ); }; export default LibraryOptionsPanel;