2023-04-22 13:03:51 +02: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
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-10-27 23:39:05 +02:00
|
|
|
import { useContext, useEffect } from 'react';
|
2023-12-27 18:17:41 +01:00
|
|
|
import { List, ListItem, ListItemButton, ListItemText, Switch } from '@mui/material';
|
2023-12-27 18:08:16 +01:00
|
|
|
import ListSubheader from '@mui/material/ListSubheader';
|
2023-12-27 18:17:41 +01:00
|
|
|
import { t as translate } from 'i18next';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx';
|
2023-10-29 02:01:59 +02:00
|
|
|
import { GlobalUpdateSettings } from '@/components/settings/globalUpdate/GlobalUpdateSettings.tsx';
|
2023-12-27 18:08:16 +01:00
|
|
|
import { MetadataServerSettingKeys, MetadataServerSettings } from '@/typings.ts';
|
|
|
|
|
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/util/metadata.ts';
|
|
|
|
|
import { makeToast } from '@/components/util/Toast.tsx';
|
2024-03-06 23:07:48 +01:00
|
|
|
import { convertSettingsToMetadata, useMetadataServerSettings } from '@/util/metadataServerSettings.ts';
|
2023-12-27 18:17:41 +01:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
|
|
|
|
import { Mangas } from '@/lib/data/Mangas.ts';
|
|
|
|
|
|
|
|
|
|
const removeNonLibraryMangasFromCategories = async (): Promise<void> => {
|
|
|
|
|
try {
|
|
|
|
|
const nonLibraryMangas = await requestManager.getMangas({
|
|
|
|
|
filter: { inLibrary: { equalTo: false }, categoryId: { isNull: false } },
|
|
|
|
|
}).response;
|
|
|
|
|
|
|
|
|
|
const mangaIdsToRemove = Mangas.getIds(nonLibraryMangas.data.mangas.nodes);
|
|
|
|
|
|
2024-01-26 21:36:07 +01:00
|
|
|
if (mangaIdsToRemove.length) {
|
2023-12-27 18:17:41 +01:00
|
|
|
await requestManager.updateMangasCategories(mangaIdsToRemove, {
|
|
|
|
|
clearCategories: true,
|
|
|
|
|
}).response;
|
|
|
|
|
}
|
|
|
|
|
makeToast(translate('library.settings.advanced.database.cleanup.label.success'), 'success');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
makeToast(translate('library.settings.advanced.database.cleanup.label.error'), 'error');
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-04-22 13:03:51 +02:00
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function LibrarySettings() {
|
2023-04-22 13:03:51 +02:00
|
|
|
const { t } = useTranslation();
|
2023-10-28 00:32:02 +02:00
|
|
|
const { setTitle, setAction } = useContext(NavBarContext);
|
2023-04-22 13:03:51 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setTitle(t('library.settings.title'));
|
|
|
|
|
setAction(null);
|
2024-01-26 20:50:51 +01:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setTitle('');
|
|
|
|
|
setAction(null);
|
|
|
|
|
};
|
2023-05-01 23:32:38 +02:00
|
|
|
}, [t]);
|
2023-04-22 13:03:51 +02:00
|
|
|
|
2023-06-26 20:40:35 +02:00
|
|
|
useSetDefaultBackTo('settings');
|
|
|
|
|
|
2023-12-27 18:08:16 +01:00
|
|
|
const { metadata, settings } = useMetadataServerSettings();
|
|
|
|
|
|
|
|
|
|
const setSettingValue = <Setting extends MetadataServerSettingKeys>(
|
|
|
|
|
setting: Setting,
|
|
|
|
|
value: MetadataServerSettings[Setting],
|
|
|
|
|
) => {
|
2024-03-06 23:07:48 +01:00
|
|
|
requestUpdateServerMetadata(convertToGqlMeta(metadata)! ?? {}, [
|
|
|
|
|
[setting, convertSettingsToMetadata({ [setting]: value })[setting]],
|
|
|
|
|
]).catch(() => makeToast(t('search.error.label.failed_to_save_settings'), 'warning'));
|
2023-12-27 18:08:16 +01:00
|
|
|
};
|
|
|
|
|
|
2023-04-22 13:03:51 +02:00
|
|
|
return (
|
2023-12-27 18:08:16 +01:00
|
|
|
<List>
|
|
|
|
|
<List
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="library-general-settings">
|
|
|
|
|
{t('global.label.general')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('library.settings.general.search.ignore_filters.label.title')}
|
|
|
|
|
secondary={t('library.settings.general.search.ignore_filters.label.description')}
|
|
|
|
|
/>
|
|
|
|
|
<Switch
|
|
|
|
|
edge="end"
|
|
|
|
|
checked={settings.ignoreFilters}
|
|
|
|
|
onChange={(e) => setSettingValue('ignoreFilters', e.target.checked)}
|
|
|
|
|
/>
|
|
|
|
|
</ListItem>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('library.settings.general.add_to_library.category_selection.label.title')}
|
|
|
|
|
secondary={t('library.settings.general.add_to_library.category_selection.label.description')}
|
|
|
|
|
/>
|
|
|
|
|
<Switch
|
|
|
|
|
edge="end"
|
|
|
|
|
checked={settings.showAddToLibraryCategorySelectDialog}
|
|
|
|
|
onChange={(e) => setSettingValue('showAddToLibraryCategorySelectDialog', e.target.checked)}
|
|
|
|
|
/>
|
|
|
|
|
</ListItem>
|
2024-03-02 15:28:58 +01:00
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('library.settings.general.remove_from_library.remove_from_categories.label.title')}
|
|
|
|
|
secondary={t(
|
|
|
|
|
'library.settings.general.remove_from_library.remove_from_categories.label.description',
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Switch
|
|
|
|
|
edge="end"
|
|
|
|
|
checked={settings.removeMangaFromCategories}
|
|
|
|
|
onChange={(e) => setSettingValue('removeMangaFromCategories', e.target.checked)}
|
|
|
|
|
/>
|
|
|
|
|
</ListItem>
|
2023-12-27 18:08:16 +01:00
|
|
|
</List>
|
2023-10-27 23:39:05 +02:00
|
|
|
<GlobalUpdateSettings />
|
2023-12-27 18:17:41 +01:00
|
|
|
<List
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="library-advanced">
|
|
|
|
|
{t('global.label.advanced')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<ListItemButton onClick={() => removeNonLibraryMangasFromCategories()}>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('library.settings.advanced.database.cleanup.label.title')}
|
|
|
|
|
secondary={t('library.settings.advanced.database.cleanup.label.description')}
|
|
|
|
|
/>
|
|
|
|
|
</ListItemButton>
|
|
|
|
|
</List>
|
2023-12-27 18:08:16 +01:00
|
|
|
</List>
|
2023-04-22 13:03:51 +02:00
|
|
|
);
|
|
|
|
|
}
|