Feature/download ahead trigger chapter downloads client side (#597)

* Trigger download ahead while reading client side

* Trigger download ahead while reading earlier

Download ahead was only triggered once the chapter got marked as read

* Optionally ignore dupe chapters for download ahead

* Consider current chapters scanlator for dupe check

* Update download ahead related settings

- add new metadata setting for download ahead limit
- previous setting
  - rename
  - update usage (auto download new chapters limit)

* Select chapter to auto delete while reading depending on ignore dupe setting

Currently, the n-th to last chapter always got deleted ignoring if "ignore dupes" setting was enabled or not.

* Only auto delete chapter while reading if it is read

In case not the last read but the n-th to last read chapter should get auto deleted while reading, it currently just got deleted ignoring if it has been read or not.
This commit is contained in:
schroda
2024-02-16 19:16:18 +01:00
committed by GitHub
parent 0edec685f9
commit 2acf2b6d33
10 changed files with 232 additions and 116 deletions

View File

@@ -8,10 +8,12 @@
import { useTranslation } from 'react-i18next';
import { List, ListItem, ListItemText, Switch } from '@mui/material';
import { useCallback } from 'react';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { getPersistedServerSetting, usePersistedValue } from '@/util/usePersistedValue.tsx';
import { useMetadataServerSettings } from '@/util/metadataServerSettings.ts';
import { MetadataServerSettings } from '@/typings.ts';
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/util/metadata.ts';
import { makeToast } from '@/components/util/Toast.tsx';
const MIN_LIMIT = 2;
const MAX_LIMIT = 10;
@@ -20,10 +22,12 @@ const DEFAULT_LIMIT = MIN_LIMIT;
export const DownloadAheadSetting = () => {
const { t } = useTranslation();
const { data } = requestManager.useGetServerSettings();
const downloadAheadLimit = data?.settings.autoDownloadAheadLimit;
const {
metadata,
settings: { downloadAheadLimit },
} = useMetadataServerSettings();
const shouldDownloadAhead = !!downloadAheadLimit;
const [mutateSettings] = requestManager.useUpdateServerSettings();
const [currentDownloadAheadLimit, persistDownloadAheadLimit] = usePersistedValue(
'lastDownloadAheadLimit',
DEFAULT_LIMIT,
@@ -31,15 +35,12 @@ export const DownloadAheadSetting = () => {
getPersistedServerSetting,
);
const updateSetting = useCallback(
(autoDownloadAheadLimit: number) => {
persistDownloadAheadLimit(
autoDownloadAheadLimit === 0 ? currentDownloadAheadLimit : autoDownloadAheadLimit,
);
mutateSettings({ variables: { input: { settings: { autoDownloadAheadLimit } } } });
},
[currentDownloadAheadLimit],
);
const updateSetting = (value: MetadataServerSettings['downloadAheadLimit']) => {
persistDownloadAheadLimit(value === 0 ? currentDownloadAheadLimit : value);
requestUpdateServerMetadata(convertToGqlMeta(metadata)! ?? {}, [['downloadAheadLimit', value]]).catch(() =>
makeToast(t('search.error.label.failed_to_save_settings'), 'warning'),
);
};
const setDoAutoUpdates = (enable: boolean) => {
const globalUpdateInterval = enable ? currentDownloadAheadLimit : 0;
@@ -68,7 +69,6 @@ export const DownloadAheadSetting = () => {
defaultValue={DEFAULT_LIMIT}
showSlider
dialogDescription={t('download.settings.download_ahead.label.description')}
dialogDisclaimer={t('download.settings.download_ahead.label.disclaimer')}
valueUnit={t('chapter.title')}
handleUpdate={updateSetting}
disabled={!shouldDownloadAhead}