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';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { CheckboxInput } from '@/modules/core/components/inputs/CheckboxInput.tsx';
|
|
|
|
|
import { RadioInput } from '@/modules/core/components/inputs/RadioInput.tsx';
|
|
|
|
|
import { SortRadioInput } from '@/modules/core/components/inputs/SortRadioInput.tsx';
|
|
|
|
|
import { ThreeStateCheckboxInput } from '@/modules/core/components/inputs/ThreeStateCheckboxInput.tsx';
|
|
|
|
|
import { OptionsTabs } from '@/modules/core/components/OptionsTabs.tsx';
|
2024-10-06 01:27:51 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
2024-10-05 21:32:31 +02:00
|
|
|
import { Trackers } from '@/modules/tracker/services/Trackers.ts';
|
2024-09-15 00:48:32 +02:00
|
|
|
import { GetTrackersSettingsQuery, MangaStatus } from '@/lib/graphql/generated/graphql.ts';
|
2024-07-04 22:00:39 +02:00
|
|
|
import { GET_TRACKERS_SETTINGS } from '@/lib/graphql/queries/TrackerQuery.ts';
|
2024-10-26 17:25:04 +02:00
|
|
|
import { createUpdateCategoryMetadata, useGetCategoryMetadata } from '@/modules/category/services/CategoryMetadata.ts';
|
2024-10-05 23:22:42 +02:00
|
|
|
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
2024-09-17 03:40:55 +02:00
|
|
|
import {
|
|
|
|
|
createUpdateMetadataServerSettings,
|
|
|
|
|
useMetadataServerSettings,
|
2024-10-05 22:53:22 +02:00
|
|
|
} from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { TranslationKey } from '@/Base.types.ts';
|
2024-10-05 19:33:09 +02:00
|
|
|
import { LibrarySortMode } from '@/modules/library/Library.types.ts';
|
2024-10-05 21:39:58 +02:00
|
|
|
import { CategoryMetadataInfo } from '@/modules/category/Category.types.ts';
|
2024-10-07 13:35:07 +02:00
|
|
|
import { statusToTranslationKey } from '@/modules/manga/Manga.constants.ts';
|
2024-10-26 17:25:04 +02:00
|
|
|
import { GridLayout } from '@/modules/core/Core.types.ts';
|
2024-12-20 17:24:40 +01:00
|
|
|
import { getErrorMessage } from '@/lib/HelperFunctions.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][] = [
|
2024-09-16 11:35:55 +02:00
|
|
|
['unreadChapters', 'library.option.sort.label.by_unread_chapters'],
|
|
|
|
|
['totalChapters', 'library.option.sort.label.by_total_chapters'],
|
|
|
|
|
['alphabetically', 'library.option.sort.label.alphabetically'],
|
|
|
|
|
['dateAdded', 'library.option.sort.label.by_date_added'],
|
|
|
|
|
['lastRead', 'library.option.sort.label.by_last_read'],
|
|
|
|
|
['latestFetchedChapter', 'library.option.sort.label.by_latest_fetched_chapter'],
|
|
|
|
|
['latestUploadedChapter', 'library.option.sort.label.by_latest_uploaded_chapter'],
|
2022-11-24 09:41:03 +01:00
|
|
|
];
|
|
|
|
|
|
2024-09-17 03:40:55 +02:00
|
|
|
export const LibraryOptionsPanel = ({
|
|
|
|
|
category,
|
|
|
|
|
open,
|
|
|
|
|
onClose,
|
|
|
|
|
}: {
|
|
|
|
|
category: CategoryMetadataInfo;
|
2023-02-06 10:06:33 +01:00
|
|
|
open: boolean;
|
|
|
|
|
onClose: () => void;
|
2024-09-17 03:40:55 +02:00
|
|
|
}) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2022-11-24 09:41:03 +01:00
|
|
|
|
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 ?? []);
|
|
|
|
|
|
2024-10-26 17:25:04 +02:00
|
|
|
const categoryLibraryOptions = useGetCategoryMetadata(category);
|
2024-12-20 17:24:40 +01:00
|
|
|
const updateCategoryLibraryOptions = createUpdateCategoryMetadata(category, (e) =>
|
|
|
|
|
makeToast(t('global.error.label.failed_to_save_changes'), 'error', getErrorMessage(e)),
|
2024-09-17 03:40:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
settings: { showTabSize },
|
|
|
|
|
} = useMetadataServerSettings();
|
2024-12-20 17:24:40 +01:00
|
|
|
const setSettingValue = createUpdateMetadataServerSettings<'showTabSize'>((e) =>
|
|
|
|
|
makeToast(t('search.error.label.failed_to_save_settings'), 'error', getErrorMessage(e)),
|
2024-09-17 03:40:55 +02:00
|
|
|
);
|
2022-11-24 09:41:03 +01:00
|
|
|
|
|
|
|
|
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')}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasUnreadChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasUnreadChapters', c)}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
2024-12-27 03:32:30 +01:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label={t('global.filter.label.started')}
|
|
|
|
|
checked={categoryLibraryOptions.hasReadChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasReadChapters', c)}
|
|
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
<ThreeStateCheckboxInput
|
2023-03-23 13:59:32 +01:00
|
|
|
label={t('global.filter.label.downloaded')}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasDownloadedChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasDownloadedChapters', c)}
|
2023-02-06 10:06:33 +01:00
|
|
|
/>
|
2024-04-01 01:12:26 +02:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label={t('global.filter.label.bookmarked')}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasBookmarkedChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasBookmarkedChapters', c)}
|
2024-04-01 01:12:26 +02:00
|
|
|
/>
|
2024-07-28 23:14:42 +02:00
|
|
|
<ThreeStateCheckboxInput
|
|
|
|
|
label={t('global.filter.label.duplicate_chapters')}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasDuplicateChapters}
|
|
|
|
|
onChange={(c) => updateCategoryLibraryOptions('hasDuplicateChapters', c)}
|
2024-07-28 23:14:42 +02:00
|
|
|
/>
|
2024-09-15 00:48:32 +02:00
|
|
|
<FormLabel sx={{ mt: 2 }}>{t('manga.label.status')}</FormLabel>
|
|
|
|
|
{Object.values(MangaStatus).map((status) => (
|
|
|
|
|
<ThreeStateCheckboxInput
|
2024-09-17 03:40:55 +02:00
|
|
|
key={status}
|
2024-09-15 00:48:32 +02:00
|
|
|
label={t(statusToTranslationKey[status])}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasStatus[status]}
|
2024-09-15 00:48:32 +02:00
|
|
|
onChange={(checked) =>
|
2024-09-17 03:40:55 +02:00
|
|
|
updateCategoryLibraryOptions('hasStatus', {
|
|
|
|
|
...categoryLibraryOptions.hasStatus,
|
2024-09-15 00:48:32 +02:00
|
|
|
[status]: checked,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
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}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.hasTrackerBinding[tracker.id]}
|
2024-03-28 20:00:46 +01:00
|
|
|
onChange={(checked) =>
|
2024-09-17 03:40:55 +02:00
|
|
|
updateCategoryLibraryOptions('hasTrackerBinding', {
|
|
|
|
|
...categoryLibraryOptions.hasTrackerBinding,
|
2024-09-16 11:35:55 +02:00
|
|
|
[tracker.id]: checked,
|
|
|
|
|
})
|
2024-03-28 20:00:46 +01:00
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
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)}
|
2024-09-17 03:40:55 +02:00
|
|
|
checked={categoryLibraryOptions.sortBy === mode}
|
|
|
|
|
sortDescending={categoryLibraryOptions.sortDesc}
|
2023-02-06 10:06:33 +01:00
|
|
|
onClick={() =>
|
2024-09-17 03:40:55 +02:00
|
|
|
mode !== categoryLibraryOptions.sortBy
|
|
|
|
|
? updateCategoryLibraryOptions('sortBy', mode)
|
|
|
|
|
: updateCategoryLibraryOptions('sortDesc', !categoryLibraryOptions.sortDesc)
|
2023-02-06 10:06:33 +01:00
|
|
|
}
|
2022-11-24 09:41:03 +01:00
|
|
|
/>
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
if (key === 'display') {
|
2024-09-17 03:40:55 +02:00
|
|
|
const { gridLayout, showContinueReadingButton, showDownloadBadge, showUnreadBadge } =
|
|
|
|
|
categoryLibraryOptions;
|
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
|
2024-09-17 03:40:55 +02:00
|
|
|
onChange={(e) => updateCategoryLibraryOptions('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}
|
2024-09-17 03:40:55 +02:00
|
|
|
onChange={() => updateCategoryLibraryOptions('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}
|
2024-09-17 03:40:55 +02:00
|
|
|
onChange={() => updateCategoryLibraryOptions('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}
|
2024-09-17 03:40:55 +02:00
|
|
|
onChange={() => setSettingValue('showTabSize', !showTabSize)}
|
2023-04-22 11:39:59 +02:00
|
|
|
/>
|
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={() =>
|
2024-09-17 03:40:55 +02:00
|
|
|
updateCategoryLibraryOptions(
|
|
|
|
|
'showContinueReadingButton',
|
|
|
|
|
!showContinueReadingButton,
|
|
|
|
|
)
|
2023-12-19 15:17:00 +01:00
|
|
|
}
|
|
|
|
|
/>
|
2022-11-24 09:41:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|