/* * 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 { RadioGroup } from '@mui/material'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { ChapterListOptions, ChapterOptionsReducerAction, TranslationKey } from '@/typings'; import { RadioInput } from '@/components/atoms/RadioInput'; import { SortRadioInput } from '@/components/atoms/SortRadioInput'; import { ThreeStateCheckboxInput } from '@/components/atoms/ThreeStateCheckboxInput'; import { OptionsTabs } from '@/components/molecules/OptionsTabs'; import { SORT_OPTIONS } from '@/components/manga/util'; interface IProps { open: boolean; onClose: () => void; options: ChapterListOptions; optionsDispatch: React.Dispatch; } const TITLES: { [key in 'filter' | 'sort' | 'display']: TranslationKey } = { filter: 'global.label.filter', sort: 'global.label.sort', display: 'global.label.display', }; export const ChapterOptions: React.FC = ({ open, onClose, options, optionsDispatch }) => { const { t } = useTranslation(); return ( open={open} onClose={onClose} minHeight={150} tabs={['filter', 'sort', 'display']} tabTitle={(key) => t(TITLES[key])} tabContent={(key) => { if (key === 'filter') { return ( <> optionsDispatch({ type: 'filter', filterType: 'unread', filterValue: c, }) } /> optionsDispatch({ type: 'filter', filterType: 'downloaded', filterValue: c, }) } /> optionsDispatch({ type: 'filter', filterType: 'bookmarked', filterValue: c, }) } /> ); } if (key === 'sort') { return SORT_OPTIONS.map(([mode, label]) => ( mode !== options.sortBy ? optionsDispatch({ type: 'sortBy', sortBy: mode }) : optionsDispatch({ type: 'sortReverse' }) } /> )); } if (key === 'display') { return ( optionsDispatch({ type: 'showChapterNumber' })} value={options.showChapterNumber} > ); } return null; }} /> ); };