2023-10-27 23:39:05 +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 List from '@mui/material/List';
|
|
|
|
|
import ListSubheader from '@mui/material/ListSubheader';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-04-14 15:50:12 +02:00
|
|
|
import ListItem from '@mui/material/ListItem';
|
|
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
|
|
|
|
import Switch from '@mui/material/Switch';
|
2024-04-28 01:00:43 +02:00
|
|
|
import {
|
|
|
|
|
CategoriesInclusionSetting,
|
|
|
|
|
CategoriesInclusionSettingProps,
|
|
|
|
|
} from '@/components/settings/CategoriesInclusionSetting.tsx';
|
2023-10-29 02:01:59 +02:00
|
|
|
import { GlobalUpdateSettingsEntries } from '@/components/settings/globalUpdate/GlobalUpdateSettingsEntries.tsx';
|
|
|
|
|
import { GlobalUpdateSettingsInterval } from '@/components/settings/globalUpdate/GlobalUpdateSettingsInterval.tsx';
|
2024-10-05 16:09:34 +02:00
|
|
|
import { requestManager } from '@/lib/requests/requests/RequestManager.ts';
|
|
|
|
|
import { makeToast } from '@/lib/ui/Toast.ts';
|
2023-11-04 14:55:25 +01:00
|
|
|
import { ServerSettings } from '@/typings.ts';
|
|
|
|
|
|
|
|
|
|
type LibrarySettingsType = Pick<ServerSettings, 'updateMangas'>;
|
2023-10-27 23:39:05 +02:00
|
|
|
|
2024-04-28 01:00:43 +02:00
|
|
|
export const GlobalUpdateSettings = ({
|
|
|
|
|
serverSettings,
|
|
|
|
|
categories,
|
|
|
|
|
}: {
|
|
|
|
|
serverSettings: ServerSettings;
|
|
|
|
|
categories: CategoriesInclusionSettingProps['categories'];
|
|
|
|
|
}) => {
|
2023-10-27 23:39:05 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2024-04-28 01:00:43 +02:00
|
|
|
const { updateMangas } = serverSettings;
|
2023-11-04 14:55:25 +01:00
|
|
|
const [mutateSettings] = requestManager.useUpdateServerSettings();
|
|
|
|
|
|
|
|
|
|
const updateSetting = async <Setting extends keyof LibrarySettingsType>(
|
|
|
|
|
setting: Setting,
|
|
|
|
|
value: LibrarySettingsType[Setting],
|
|
|
|
|
) => {
|
|
|
|
|
try {
|
|
|
|
|
await mutateSettings({ variables: { input: { settings: { [setting]: value } } } });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
makeToast(t('global.error.label.failed_to_save_changes'), 'error');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-27 23:39:05 +02:00
|
|
|
return (
|
|
|
|
|
<List
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="global-update-settings">
|
|
|
|
|
{t('library.settings.global_update.title')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-04-28 01:00:43 +02:00
|
|
|
<GlobalUpdateSettingsInterval globalUpdateInterval={serverSettings.globalUpdateInterval} />
|
|
|
|
|
<GlobalUpdateSettingsEntries serverSettings={serverSettings} />
|
2024-01-21 13:31:04 -08:00
|
|
|
<CategoriesInclusionSetting
|
2024-04-28 01:00:43 +02:00
|
|
|
categories={categories}
|
2024-01-21 13:31:04 -08:00
|
|
|
includeField="includeInUpdate"
|
|
|
|
|
dialogText={t('library.settings.global_update.categories.label.info')}
|
|
|
|
|
/>
|
2023-11-04 14:55:25 +01:00
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('library.settings.global_update.metadata.label.title')}
|
|
|
|
|
secondary={t('library.settings.global_update.metadata.label.description')}
|
|
|
|
|
/>
|
2023-12-09 14:16:59 +01:00
|
|
|
<Switch
|
|
|
|
|
edge="end"
|
|
|
|
|
checked={updateMangas}
|
|
|
|
|
onChange={(e) => updateSetting('updateMangas', e.target.checked)}
|
|
|
|
|
/>
|
2023-11-04 14:55:25 +01:00
|
|
|
</ListItem>
|
2023-10-27 23:39:05 +02:00
|
|
|
</List>
|
|
|
|
|
);
|
|
|
|
|
};
|