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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2024-04-14 15:50:12 +02:00
|
|
|
import FormLabel from '@mui/material/FormLabel';
|
|
|
|
|
import RadioGroup from '@mui/material/RadioGroup';
|
2022-11-24 09:41:03 +01:00
|
|
|
import React from 'react';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { LibraryOptions, LibrarySortMode, TranslationKey } from '@/typings';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { CheckboxInput } from '@/components/atoms/CheckboxInput';
|
|
|
|
|
import { RadioInput } from '@/components/atoms/RadioInput';
|
|
|
|
|
import { SortRadioInput } from '@/components/atoms/SortRadioInput';
|
|
|
|
|
import { ThreeStateCheckboxInput } from '@/components/atoms/ThreeStateCheckboxInput';
|
2023-06-05 01:42:39 +02:00
|
|
|
import { GridLayout, useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { OptionsTabs } from '@/components/molecules/OptionsTabs';
|
2024-03-28 20:00:46 +01:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
|
|
|
|
import { Trackers } from '@/lib/data/Trackers.ts';
|
2024-07-04 22:00:39 +02:00
|
|
|
import { GetTrackersSettingsQuery } from '@/lib/graphql/generated/graphql.ts';
|
|
|
|
|
import { GET_TRACKERS_SETTINGS } from '@/lib/graphql/queries/TrackerQuery.ts';
|
2022-11-24 09:41:03 +01:00
|
|
|
|
2023-03-23 13:59:32 +01:00
|
|
|
const TITLES: { [key in 'filter' | 'sort' | 'display']: TranslationKey } = {
|
|
|
|
|
filter: 'global.label.filter',
|
|
|
|
|
sort: 'global.label.sort',
|
|
|
|
|
display: 'global.label.display',
|
2022-11-24 09:41:03 +01:00
|
|
|
};
|
|
|
|
|
|
2023-03-23 13:59:32 +01:00
|
|
|
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'],
|
2024-01-11 03:56:04 +01:00
|
|
|
['sortLatestFetchedChapter', 'library.option.sort.label.by_latest_fetched_chapter'],
|
|
|
|
|
['sortLatestUploadedChapter', 'library.option.sort.label.by_latest_uploaded_chapter'],
|
2022-11-24 09:41:03 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
2022-11-24 09:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export const LibraryOptionsPanel: React.FC<IProps> = ({ open, onClose }) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2022-11-24 09:41:03 +01:00
|
|
|
const { options, setOptions } = useLibraryOptionsContext();
|
|
|
|
|
|
2024-07-04 22:00:39 +02:00
|
|
|
const trackerList = requestManager.useGetTrackerList<GetTrackersSettingsQuery>(GET_TRACKERS_SETTINGS);
|
2024-03-28 20:00:46 +01:00
|
|
|
const loggedInTrackers = Trackers.getLoggedIn(trackerList.data?.trackers.nodes ?? []);
|
|
|
|
|
|
2023-02-08 18:19:26 +01:00
|
|
|
const handleFilterChange = <T extends keyof LibraryOptions>(key: T, value: LibraryOptions[T]) => {
|
2022-11-24 09:41:03 +01:00
|
|
|
setOptions((v) => ({ ...v, [key]: value }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<OptionsTabs<'filter' | 'sort' | 'display'>
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
tabs={['filter', 'sort', 'display']}
|
2023-07-04 21:53:25 +02:00
|
|
|
tabTitle={(key) => t(TITLES[key])}
|
2022-11-24 09:41:03 +01:00
|
|
|
tabContent={(key) => {
|
|
|
|
|
if (key === 'filter') {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ThreeStateCheckboxInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.filter.label.unread')}
|
2023-02-06 10:06:33 +01:00
|
|
|
checked={options.unread}
|
|
|
|
|
onChange={(c) => handleFilterChange('unread', c)}
|
|
|
|
|
/>
|
|
|
|
|
<ThreeStateCheckboxInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.filter.label.downloaded')}
|
2023-02-06 10:06:33 +01:00
|
|
|
checked={options.downloaded}
|
|
|
|
|
onChange={(c) => handleFilterChange('downloaded', c)}
|
|
|
|
|
/>
|
2024-04-01 01:12:26 +02:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label={t('global.filter.label.bookmarked')}
|
|
|
|
|
checked={options.bookmarked}
|
|
|
|
|
onChange={(c) => handleFilterChange('bookmarked', c)}
|
|
|
|
|
/>
|
2024-03-29 00:51:14 +01:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t('global.filter.label.tracked')}</FormLabel>
|
2024-03-28 20:00:46 +01:00
|
|
|
{loggedInTrackers.map((tracker) => (
|
|
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
key={tracker.id}
|
|
|
|
|
label={tracker.name}
|
|
|
|
|
checked={options.tracker[tracker.id]}
|
|
|
|
|
onChange={(checked) =>
|
|
|
|
|
handleFilterChange('tracker', { ...options.tracker, [tracker.id]: checked })
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (key === 'sort') {
|
|
|
|
|
return SORT_OPTIONS.map(([mode, label]) => (
|
|
|
|
|
<SortRadioInput
|
|
|
|
|
key={mode}
|
2023-07-04 21:53:25 +02:00
|
|
|
label={t(label)}
|
2022-11-24 09:41:03 +01:00
|
|
|
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') {
|
2023-12-19 15:17:00 +01:00
|
|
|
const { gridLayout, showContinueReadingButton, showDownloadBadge, showUnreadBadge, showTabSize } =
|
|
|
|
|
options;
|
2022-11-24 09:41:03 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2023-03-23 13:59:32 +01:00
|
|
|
<FormLabel>{t('global.grid_layout.title')}</FormLabel>
|
2022-11-24 09:41:03 +01:00
|
|
|
<RadioGroup
|
2023-02-08 18:19:26 +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
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.compact_grid')}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.Compact}
|
2023-02-08 18:19:26 +01:00
|
|
|
checked={gridLayout == null || gridLayout === GridLayout.Compact}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
|
|
|
|
<RadioInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.comfortable_grid')}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.Comfortable}
|
|
|
|
|
checked={gridLayout === GridLayout.Comfortable}
|
|
|
|
|
/>
|
|
|
|
|
<RadioInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.grid_layout.label.list')}
|
2023-02-06 10:06:33 +01:00
|
|
|
value={GridLayout.List}
|
|
|
|
|
checked={gridLayout === GridLayout.List}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</RadioGroup>
|
|
|
|
|
|
2023-03-23 13:59:32 +01:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t('library.option.display.badge.title')}</FormLabel>
|
2022-11-24 09:41:03 +01:00
|
|
|
<CheckboxInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('library.option.display.badge.label.unread_badges')}
|
2023-12-19 15:17:00 +01:00
|
|
|
checked={showUnreadBadge}
|
2023-02-08 18:19:26 +01:00
|
|
|
onChange={() => handleFilterChange('showUnreadBadge', !showUnreadBadge)}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
<CheckboxInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('library.option.display.badge.label.download_badges')}
|
2023-12-19 15:17:00 +01:00
|
|
|
checked={showDownloadBadge}
|
2023-02-08 18:19:26 +01:00
|
|
|
onChange={() => handleFilterChange('showDownloadBadge', !showDownloadBadge)}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
2023-04-22 11:39:59 +02:00
|
|
|
|
|
|
|
|
<FormLabel sx={{ mt: 2 }}>{t('library.option.display.tab.title')}</FormLabel>
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
label={t('library.option.display.tab.label.show_number_of_items')}
|
|
|
|
|
checked={showTabSize}
|
|
|
|
|
onChange={() => handleFilterChange('showTabSize', !showTabSize)}
|
|
|
|
|
/>
|
2023-12-19 15:17:00 +01:00
|
|
|
|
|
|
|
|
<FormLabel sx={{ mt: 2 }}>{t('global.label.other')}</FormLabel>
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
label={t('library.option.display.other.label.show_continue_reading_button')}
|
|
|
|
|
checked={showContinueReadingButton}
|
|
|
|
|
onChange={() =>
|
|
|
|
|
handleFilterChange('showContinueReadingButton', !showContinueReadingButton)
|
|
|
|
|
}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|