Remember last used migration flags (#656)
This commit is contained in:
@@ -19,6 +19,12 @@ import FormGroup from '@mui/material/FormGroup';
|
|||||||
import { CheckboxInput } from '@/components/atoms/CheckboxInput.tsx';
|
import { CheckboxInput } from '@/components/atoms/CheckboxInput.tsx';
|
||||||
import { Mangas, MigrateMode } from '@/lib/data/Mangas.ts';
|
import { Mangas, MigrateMode } from '@/lib/data/Mangas.ts';
|
||||||
import { makeToast } from '@/components/util/Toast.tsx';
|
import { makeToast } from '@/components/util/Toast.tsx';
|
||||||
|
import { convertSettingsToMetadata, useMetadataServerSettings } from '@/util/metadataServerSettings.ts';
|
||||||
|
import { MetadataServerSettings } from '@/typings.ts';
|
||||||
|
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/util/metadata.ts';
|
||||||
|
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
||||||
|
|
||||||
|
type MigrationSettingsType = Pick<MetadataServerSettings, 'includeChapters' | 'includeCategories' | 'deleteChapters'>;
|
||||||
|
|
||||||
export const MigrateDialog = ({ mangaIdToMigrateTo, onClose }: { mangaIdToMigrateTo: number; onClose: () => void }) => {
|
export const MigrateDialog = ({ mangaIdToMigrateTo, onClose }: { mangaIdToMigrateTo: number; onClose: () => void }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -28,12 +34,22 @@ export const MigrateDialog = ({ mangaIdToMigrateTo, onClose }: { mangaIdToMigrat
|
|||||||
const { mangaId: mangaIdAsString } = useParams<{ mangaId: string }>();
|
const { mangaId: mangaIdAsString } = useParams<{ mangaId: string }>();
|
||||||
const mangaId = Number(mangaIdAsString);
|
const mangaId = Number(mangaIdAsString);
|
||||||
|
|
||||||
const [includeChapters, setIncludeChapters] = useState(true);
|
const {
|
||||||
const [includeCategories, setIncludeCategories] = useState(true);
|
metadata,
|
||||||
const [deleteChapters, setDeleteChapters] = useState(true);
|
settings: { includeChapters, includeCategories, deleteChapters },
|
||||||
|
} = useMetadataServerSettings();
|
||||||
|
|
||||||
const [isMigrationInProcess, setIsMigrationInProcess] = useState(false);
|
const [isMigrationInProcess, setIsMigrationInProcess] = useState(false);
|
||||||
|
|
||||||
|
const setMigrationFlag = <Setting extends keyof MigrationSettingsType>(
|
||||||
|
setting: Setting,
|
||||||
|
value: MigrationSettingsType[Setting],
|
||||||
|
) => {
|
||||||
|
requestUpdateServerMetadata(convertToGqlMeta(metadata) ?? [], [
|
||||||
|
[setting, convertSettingsToMetadata({ [setting]: value })[setting]],
|
||||||
|
]).catch(defaultPromiseErrorHandler('MigrateDialog::updateSetting'));
|
||||||
|
};
|
||||||
|
|
||||||
const migrate = async (mode: MigrateMode) => {
|
const migrate = async (mode: MigrateMode) => {
|
||||||
if (mangaId == null) {
|
if (mangaId == null) {
|
||||||
throw new Error(`MigrateDialog::migrate: unexpected mangaId "${mangaId}"`);
|
throw new Error(`MigrateDialog::migrate: unexpected mangaId "${mangaId}"`);
|
||||||
@@ -66,19 +82,19 @@ export const MigrateDialog = ({ mangaIdToMigrateTo, onClose }: { mangaIdToMigrat
|
|||||||
disabled={isMigrationInProcess}
|
disabled={isMigrationInProcess}
|
||||||
label={t('chapter.title')}
|
label={t('chapter.title')}
|
||||||
checked={includeChapters}
|
checked={includeChapters}
|
||||||
onChange={(_, checked) => setIncludeChapters(checked)}
|
onChange={(_, checked) => setMigrationFlag('includeChapters', checked)}
|
||||||
/>
|
/>
|
||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
disabled={isMigrationInProcess}
|
disabled={isMigrationInProcess}
|
||||||
label={t('category.title.category_one')}
|
label={t('category.title.category_one')}
|
||||||
checked={includeCategories}
|
checked={includeCategories}
|
||||||
onChange={(_, checked) => setIncludeCategories(checked)}
|
onChange={(_, checked) => setMigrationFlag('includeCategories', checked)}
|
||||||
/>
|
/>
|
||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
disabled={isMigrationInProcess}
|
disabled={isMigrationInProcess}
|
||||||
label={t('migrate.dialog.label.delete_downloaded')}
|
label={t('migrate.dialog.label.delete_downloaded')}
|
||||||
checked={deleteChapters}
|
checked={deleteChapters}
|
||||||
onChange={(_, checked) => setDeleteChapters(checked)}
|
onChange={(_, checked) => setMigrationFlag('deleteChapters', checked)}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -232,6 +232,11 @@ export type MetadataServerSettings = {
|
|||||||
|
|
||||||
// client
|
// client
|
||||||
devices: string[];
|
devices: string[];
|
||||||
|
|
||||||
|
// migration
|
||||||
|
includeChapters: boolean;
|
||||||
|
includeCategories: boolean;
|
||||||
|
deleteChapters: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ISearchSettings {
|
export interface ISearchSettings {
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ export const getDefaultSettings = (): MetadataServerSettings => ({
|
|||||||
|
|
||||||
// client
|
// client
|
||||||
devices: [DEFAULT_DEVICE],
|
devices: [DEFAULT_DEVICE],
|
||||||
|
|
||||||
|
// migration
|
||||||
|
includeChapters: true,
|
||||||
|
includeCategories: true,
|
||||||
|
deleteChapters: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const convertSettingsToMetadata = (
|
export const convertSettingsToMetadata = (
|
||||||
|
|||||||
Reference in New Issue
Block a user