Feature/automatic chapter deletion more options (#484)

* Add missing translations keys

* [Codegen] Update to latest server schema changes

* [VersionMapping] Require server version "r1431" for preview

* Rename "deleteChaptersAutoMarkedRead" metadata setting

* Add more options to auto delete chapters while reading

Makes it possible to delete the last to fifth to last read chapter instead of only being able to delete the last read chapter
This commit is contained in:
schroda
2023-12-05 22:20:13 +01:00
committed by GitHub
parent ee03c56684
commit ad0f072651
15 changed files with 230 additions and 42 deletions

View File

@@ -0,0 +1,78 @@
/*
* 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';
import {
SelectSetting,
SelectSettingValue,
SelectSettingValueDisplayInfo,
} from '@/components/settings/SelectSetting.tsx';
const CHAPTERS_TO_DELETE = [0, 1, 2, 3, 4, 5] as const;
const CHAPTERS_TO_DELETE_TO_TRANSLATION_KEY: {
[flavor in (typeof CHAPTERS_TO_DELETE)[number]]: SelectSettingValueDisplayInfo;
} = {
0: {
text: 'global.label.disabled',
},
1: {
text: 'download.settings.delete_chapters.while_reading.option.label.first',
},
2: {
text: 'download.settings.delete_chapters.while_reading.option.label.second',
},
3: {
text: 'download.settings.delete_chapters.while_reading.option.label.third',
},
4: {
text: 'download.settings.delete_chapters.while_reading.option.label.fourth',
},
5: {
text: 'download.settings.delete_chapters.while_reading.option.label.fifth',
},
};
const CHAPTERS_TO_DELETE_SELECT_VALUES: SelectSettingValue<(typeof CHAPTERS_TO_DELETE)[number]>[] =
CHAPTERS_TO_DELETE.map((chapterToDelete) => [
chapterToDelete,
CHAPTERS_TO_DELETE_TO_TRANSLATION_KEY[chapterToDelete],
]);
const getNormalizedChapterToDelete = (chapterToDelete?: number | boolean) => {
if (!chapterToDelete) {
return undefined;
}
const isMigrationVersion0 = typeof chapterToDelete === 'boolean';
if (isMigrationVersion0) {
return Number(chapterToDelete);
}
return chapterToDelete;
};
export const DeleteChaptersWhileReadingSetting = ({
chapterToDelete,
handleChange,
}: {
chapterToDelete?: number;
handleChange: (chapterToDelete: number) => void;
}) => {
const { t } = useTranslation();
const normalizedChapterToDelete = getNormalizedChapterToDelete(chapterToDelete);
return (
<SelectSetting
settingName={t('download.settings.delete_chapters.while_reading.label.title')}
value={normalizedChapterToDelete}
defaultValue={0}
values={CHAPTERS_TO_DELETE_SELECT_VALUES}
handleChange={handleChange}
/>
);
};