Move download files into new folder
This commit is contained in:
14
src/modules/downloads/Downloads.types.ts
Normal file
14
src/modules/downloads/Downloads.types.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
export type MetadataDownloadSettings = {
|
||||
deleteChaptersManuallyMarkedRead: boolean;
|
||||
deleteChaptersWhileReading: number;
|
||||
deleteChaptersWithBookmark: boolean;
|
||||
downloadAheadLimit: number;
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 '@/modules/core/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) => {
|
||||
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}
|
||||
values={CHAPTERS_TO_DELETE_SELECT_VALUES}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
77
src/modules/downloads/components/DownloadAheadSetting.tsx
Normal file
77
src/modules/downloads/components/DownloadAheadSetting.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import Switch from '@mui/material/Switch';
|
||||
import { NumberSetting } from '@/modules/core/components/settings/NumberSetting.tsx';
|
||||
import { getPersistedServerSetting, usePersistedValue } from '@/modules/core/hooks/usePersistedValue.tsx';
|
||||
import { updateMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
|
||||
import { MetadataServerSettings } from '@/typings.ts';
|
||||
import { makeToast } from '@/lib/ui/Toast.ts';
|
||||
import { MetadataDownloadSettings } from '@/modules/downloads/Downloads.types.ts';
|
||||
|
||||
const MIN_LIMIT = 2;
|
||||
const MAX_LIMIT = 10;
|
||||
const DEFAULT_LIMIT = MIN_LIMIT;
|
||||
|
||||
export const DownloadAheadSetting = ({
|
||||
downloadAheadLimit,
|
||||
}: {
|
||||
downloadAheadLimit: MetadataServerSettings['downloadAheadLimit'];
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const shouldDownloadAhead = !!downloadAheadLimit;
|
||||
const [currentDownloadAheadLimit, persistDownloadAheadLimit] = usePersistedValue(
|
||||
'lastDownloadAheadLimit',
|
||||
DEFAULT_LIMIT,
|
||||
downloadAheadLimit,
|
||||
getPersistedServerSetting,
|
||||
);
|
||||
|
||||
const updateSetting = (value: MetadataDownloadSettings['downloadAheadLimit']) => {
|
||||
persistDownloadAheadLimit(value === 0 ? currentDownloadAheadLimit : value);
|
||||
updateMetadataServerSettings('downloadAheadLimit', value).catch(() =>
|
||||
makeToast(t('global.error.label.failed_to_save_changes'), 'error'),
|
||||
);
|
||||
};
|
||||
|
||||
const setDoAutoUpdates = (enable: boolean) => {
|
||||
const globalUpdateInterval = enable ? currentDownloadAheadLimit : 0;
|
||||
updateSetting(globalUpdateInterval);
|
||||
};
|
||||
|
||||
return (
|
||||
<List>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.download_ahead.label.while_reading')} />
|
||||
<Switch edge="end" checked={shouldDownloadAhead} onChange={(e) => setDoAutoUpdates(e.target.checked)} />
|
||||
</ListItem>
|
||||
<NumberSetting
|
||||
settingTitle={t('download.settings.download_ahead.label.unread_chapters_to_download')}
|
||||
settingValue={t('download.settings.download_ahead.label.value', {
|
||||
chapters: currentDownloadAheadLimit,
|
||||
count: currentDownloadAheadLimit,
|
||||
})}
|
||||
value={currentDownloadAheadLimit}
|
||||
minValue={MIN_LIMIT}
|
||||
maxValue={MAX_LIMIT}
|
||||
defaultValue={DEFAULT_LIMIT}
|
||||
showSlider
|
||||
dialogDescription={t('download.settings.download_ahead.label.description')}
|
||||
dialogDisclaimer={t('download.settings.download_ahead.label.disclaimer')}
|
||||
valueUnit={t('chapter.title_one')}
|
||||
handleUpdate={updateSetting}
|
||||
disabled={!shouldDownloadAhead}
|
||||
/>
|
||||
</List>
|
||||
);
|
||||
};
|
||||
312
src/modules/downloads/screens/DownloadQueue.tsx
Normal file
312
src/modules/downloads/screens/DownloadQueue.tsx
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* 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 DeleteIcon from '@mui/icons-material/Delete';
|
||||
import DragHandle from '@mui/icons-material/DragHandle';
|
||||
import PauseIcon from '@mui/icons-material/Pause';
|
||||
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||
import Card from '@mui/material/Card';
|
||||
import CardActionArea from '@mui/material/CardActionArea';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Box, { BoxProps } from '@mui/material/Box';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import React, { useContext, useEffect, useLayoutEffect } from 'react';
|
||||
import { DragDropContext, Draggable, DraggableProvided, DropResult } from 'react-beautiful-dnd';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import DeleteSweepIcon from '@mui/icons-material/DeleteSweep';
|
||||
import { Virtuoso } from 'react-virtuoso';
|
||||
import CardContent from '@mui/material/CardContent';
|
||||
import Refresh from '@mui/icons-material/Refresh';
|
||||
import { requestManager } from '@/lib/requests/requests/RequestManager.ts';
|
||||
import { StrictModeDroppable } from '@/modules/core/components/StrictModeDroppable.tsx';
|
||||
import { makeToast } from '@/lib/ui/Toast.ts';
|
||||
import { DownloadStateIndicator } from '@/modules/core/components/DownloadStateIndicator.tsx';
|
||||
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx';
|
||||
import { NavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
||||
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
||||
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
||||
import { ChapterDownloadStatus, ChapterIdInfo } from '@/modules/chapter/services/Chapters.ts';
|
||||
import { DownloadState } from '@/lib/graphql/generated/graphql.ts';
|
||||
|
||||
const HeightPreservingItem = ({ children, ...props }: BoxProps) => (
|
||||
// the height is necessary to prevent the item container from collapsing, which confuses Virtuoso measurements
|
||||
<Box {...props} style={{ height: props['data-known-size' as keyof typeof props] || undefined }}>
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
|
||||
const DownloadChapterItem = ({
|
||||
provided,
|
||||
item,
|
||||
handleDelete,
|
||||
handleRetry,
|
||||
}: {
|
||||
provided: DraggableProvided;
|
||||
item: ChapterDownloadStatus;
|
||||
handleDelete: (chapter: ChapterIdInfo) => void;
|
||||
handleRetry: (chapter: ChapterIdInfo) => void;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Box {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef} sx={{ p: 1, pb: 0 }}>
|
||||
<Card>
|
||||
<CardActionArea component={Link} to={`/manga/${item.manga.id}`}>
|
||||
<CardContent
|
||||
sx={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
p: 1.5,
|
||||
}}
|
||||
>
|
||||
<IconButton sx={{ pointerEvents: 'none' }}>
|
||||
<DragHandle />
|
||||
</IconButton>
|
||||
<Stack sx={{ flex: 1, ml: 1 }} direction="column">
|
||||
<Typography variant="h6" component="h3">
|
||||
{item.manga.title}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
display: 'block',
|
||||
}}
|
||||
>
|
||||
{item.chapter.name}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<DownloadStateIndicator download={item} />
|
||||
{item.state === DownloadState.Error && (
|
||||
<Tooltip title={t('global.button.retry')}>
|
||||
<IconButton
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
handleRetry(item.chapter);
|
||||
}}
|
||||
size="large"
|
||||
>
|
||||
<Refresh />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip title={t('chapter.action.download.delete.label.action')}>
|
||||
<IconButton
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
handleDelete(item.chapter);
|
||||
}}
|
||||
size="large"
|
||||
>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</CardContent>
|
||||
</CardActionArea>
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export const DownloadQueue: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [reorderDownload, { reset: revertReorder }] = requestManager.useReorderChapterInDownloadQueue();
|
||||
|
||||
const {
|
||||
data: downloadStatusData,
|
||||
loading: isLoading,
|
||||
error,
|
||||
refetch,
|
||||
} = requestManager.useGetDownloadStatus({ notifyOnNetworkStatusChange: true });
|
||||
const downloaderData = downloadStatusData?.downloadStatus;
|
||||
|
||||
const queue = downloaderData?.queue ?? [];
|
||||
const status = downloaderData?.state ?? 'STARTED';
|
||||
const isQueueEmpty = !queue.length;
|
||||
|
||||
const { setTitle, setAction } = useContext(NavBarContext);
|
||||
|
||||
const clearQueue = async () => {
|
||||
try {
|
||||
await requestManager.clearDownloads().response;
|
||||
} catch (e) {
|
||||
makeToast(t('download.queue.error.label.failed_delete_all'), 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const toggleQueueStatus = () => {
|
||||
if (status === 'STOPPED') {
|
||||
requestManager.startDownloads();
|
||||
} else {
|
||||
requestManager.stopDownloads();
|
||||
}
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setTitle(t('download.queue.title'));
|
||||
setAction(
|
||||
<>
|
||||
<Tooltip title={t('download.queue.label.delete_all')}>
|
||||
<IconButton onClick={clearQueue} size="large" color="inherit">
|
||||
<DeleteSweepIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title={t(status === 'STOPPED' ? 'global.button.start' : 'global.button.stop')}>
|
||||
<IconButton onClick={toggleQueueStatus} size="large" disabled={isQueueEmpty} color="inherit">
|
||||
{status === 'STOPPED' ? <PlayArrowIcon /> : <PauseIcon />}
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</>,
|
||||
);
|
||||
|
||||
return () => {
|
||||
setTitle('');
|
||||
setAction(null);
|
||||
};
|
||||
}, [t, status, isQueueEmpty]);
|
||||
|
||||
useEffect(() => {
|
||||
const ignoreError = (e: WindowEventMap['error']) => {
|
||||
if (
|
||||
e.message === 'ResizeObserver loop completed with undelivered notifications.' ||
|
||||
e.message === 'ResizeObserver loop limit exceeded'
|
||||
) {
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
};
|
||||
|
||||
// Virtuoso's resize observer can throw this error,
|
||||
// which is caught by DnD and aborts dragging.
|
||||
window.addEventListener('error', ignoreError);
|
||||
|
||||
return () => window.removeEventListener('error', ignoreError);
|
||||
}, []);
|
||||
|
||||
const categoryReorder = (list: ChapterDownloadStatus[], from: number, to: number) => {
|
||||
if (from === to) {
|
||||
return;
|
||||
}
|
||||
|
||||
reorderDownload({ variables: { input: { chapterId: list[from].chapter.id, to } } }).catch(() => {
|
||||
revertReorder();
|
||||
});
|
||||
};
|
||||
|
||||
const onDragEnd = (result: DropResult) => {
|
||||
if (!result.destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
categoryReorder(queue, result.source.index, result.destination.index);
|
||||
};
|
||||
|
||||
const handleRetry = async (chapter: ChapterIdInfo) => {
|
||||
try {
|
||||
await requestManager.addChapterToDownloadQueue(chapter.id).response;
|
||||
} catch (e) {
|
||||
makeToast(t('download.queue.error.label.failed_to_remove'), 'error');
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (chapter: ChapterIdInfo) => {
|
||||
const isRunning = status === 'STARTED';
|
||||
|
||||
try {
|
||||
if (isRunning) {
|
||||
// required to stop before deleting otherwise the download kept going. Server issue?
|
||||
await requestManager.stopDownloads().response;
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
// remove from download queue
|
||||
requestManager.removeChapterFromDownloadQueue(chapter.id).response,
|
||||
// delete partial download, should be handle server side?
|
||||
// bug: The folder and the last image downloaded are not deleted
|
||||
requestManager.deleteDownloadedChapter(chapter.id).response,
|
||||
]);
|
||||
} catch (e) {
|
||||
makeToast(t('download.queue.error.label.failed_to_retry'), 'error');
|
||||
}
|
||||
|
||||
if (!isRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
requestManager.startDownloads().response.catch(defaultPromiseErrorHandler('DownloadQueue::startDownloads'));
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingPlaceholder />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<EmptyViewAbsoluteCentered
|
||||
message={t('global.error.label.failed_to_load_data')}
|
||||
messageExtra={error.message}
|
||||
retry={() => refetch().catch(defaultPromiseErrorHandler('DownloadQueue::refetch'))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (isQueueEmpty) {
|
||||
return <EmptyViewAbsoluteCentered message={t('download.queue.label.no_downloads')} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<DragDropContext onDragEnd={onDragEnd}>
|
||||
<StrictModeDroppable
|
||||
droppableId="droppable"
|
||||
mode="virtual"
|
||||
renderClone={(provided, snapshot, rubric) => (
|
||||
<DownloadChapterItem
|
||||
provided={provided}
|
||||
item={queue[rubric.source.index]}
|
||||
handleDelete={handleDelete}
|
||||
handleRetry={handleRetry}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
{(droppableProvided) => (
|
||||
<Box ref={droppableProvided.innerRef}>
|
||||
<Virtuoso
|
||||
useWindowScroll
|
||||
overscan={window.innerHeight * 0.5}
|
||||
data={queue}
|
||||
components={{
|
||||
Item: HeightPreservingItem,
|
||||
}}
|
||||
itemContent={(index, item) => (
|
||||
<Draggable
|
||||
key={`${item.manga.id}-${item.chapter.sourceOrder}`}
|
||||
draggableId={`${item.manga.id}-${item.chapter.sourceOrder}`}
|
||||
index={index}
|
||||
>
|
||||
{(draggableProvided) => (
|
||||
<DownloadChapterItem
|
||||
provided={draggableProvided}
|
||||
item={item}
|
||||
handleDelete={handleDelete}
|
||||
handleRetry={handleRetry}
|
||||
/>
|
||||
)}
|
||||
</Draggable>
|
||||
)}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
</StrictModeDroppable>
|
||||
</DragDropContext>
|
||||
);
|
||||
};
|
||||
248
src/modules/downloads/screens/DownloadSettings.tsx
Normal file
248
src/modules/downloads/screens/DownloadSettings.tsx
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* 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 { useContext, useLayoutEffect } from 'react';
|
||||
import List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import Switch from '@mui/material/Switch';
|
||||
import ListSubheader from '@mui/material/ListSubheader';
|
||||
import { TextSetting } from '@/modules/core/components/settings/text/TextSetting.tsx';
|
||||
import { NavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
||||
import { ServerSettings } from '@/typings.ts';
|
||||
import { requestManager } from '@/lib/requests/requests/RequestManager.ts';
|
||||
import { DownloadAheadSetting } from '@/modules/downloads/components/DownloadAheadSetting.tsx';
|
||||
import {
|
||||
createUpdateMetadataServerSettings,
|
||||
useMetadataServerSettings,
|
||||
} from '@/lib/metadata/metadataServerSettings.ts';
|
||||
import { makeToast } from '@/lib/ui/Toast.ts';
|
||||
import { DeleteChaptersWhileReadingSetting } from '@/modules/downloads/components/DeleteChaptersWhileReadingSetting.tsx';
|
||||
import { CategoriesInclusionSetting } from '@/modules/category/components/CategoriesInclusionSetting.tsx';
|
||||
import { NumberSetting } from '@/modules/core/components/settings/NumberSetting.tsx';
|
||||
import { LoadingPlaceholder } from '@/modules/core/components/placeholder/LoadingPlaceholder.tsx';
|
||||
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx';
|
||||
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
|
||||
import { GetCategoriesSettingsQuery, GetCategoriesSettingsQueryVariables } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { GET_CATEGORIES_SETTINGS } from '@/lib/graphql/queries/CategoryQuery.ts';
|
||||
import { MetadataDownloadSettings } from '@/modules/downloads/Downloads.types.ts';
|
||||
|
||||
type DownloadSettingsType = Pick<
|
||||
ServerSettings,
|
||||
| 'downloadAsCbz'
|
||||
| 'downloadsPath'
|
||||
| 'autoDownloadNewChapters'
|
||||
| 'autoDownloadNewChaptersLimit'
|
||||
| 'excludeEntryWithUnreadChapters'
|
||||
| 'autoDownloadIgnoreReUploads'
|
||||
>;
|
||||
|
||||
const extractDownloadSettings = (settings: ServerSettings): DownloadSettingsType => ({
|
||||
downloadAsCbz: settings.downloadAsCbz,
|
||||
downloadsPath: settings.downloadsPath,
|
||||
autoDownloadNewChapters: settings.autoDownloadNewChapters,
|
||||
autoDownloadNewChaptersLimit: settings.autoDownloadNewChaptersLimit,
|
||||
excludeEntryWithUnreadChapters: settings.excludeEntryWithUnreadChapters,
|
||||
autoDownloadIgnoreReUploads: settings.autoDownloadIgnoreReUploads,
|
||||
});
|
||||
|
||||
export const DownloadSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
const { setTitle, setAction } = useContext(NavBarContext);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setTitle(t('download.settings.title'));
|
||||
setAction(null);
|
||||
|
||||
return () => {
|
||||
setTitle('');
|
||||
setAction(null);
|
||||
};
|
||||
}, [t]);
|
||||
|
||||
const categories = requestManager.useGetCategories<GetCategoriesSettingsQuery, GetCategoriesSettingsQueryVariables>(
|
||||
GET_CATEGORIES_SETTINGS,
|
||||
);
|
||||
const serverSettings = requestManager.useGetServerSettings({ notifyOnNetworkStatusChange: true });
|
||||
const [mutateSettings] = requestManager.useUpdateServerSettings();
|
||||
const {
|
||||
settings: metadataSettings,
|
||||
loading: areMetadataServerSettingsLoading,
|
||||
request: { error: metadataServerSettingsError, refetch: refetchMetadataServerSettings },
|
||||
} = useMetadataServerSettings();
|
||||
|
||||
const loading = serverSettings.loading || areMetadataServerSettingsLoading || categories.loading;
|
||||
if (loading) {
|
||||
return <LoadingPlaceholder />;
|
||||
}
|
||||
|
||||
const error = serverSettings.error ?? metadataServerSettingsError ?? categories.error;
|
||||
if (error) {
|
||||
return (
|
||||
<EmptyViewAbsoluteCentered
|
||||
message={t('global.error.label.failed_to_load_data')}
|
||||
messageExtra={error.message}
|
||||
retry={() => {
|
||||
if (serverSettings.error) {
|
||||
serverSettings
|
||||
.refetch()
|
||||
.catch(defaultPromiseErrorHandler('DownloadSettings::refetchServerSettings'));
|
||||
}
|
||||
|
||||
if (metadataServerSettingsError) {
|
||||
refetchMetadataServerSettings().catch(
|
||||
defaultPromiseErrorHandler('refetchMetadataServerSettings::'),
|
||||
);
|
||||
}
|
||||
|
||||
if (categories.error) {
|
||||
categories.refetch().catch(defaultPromiseErrorHandler('LibrarySettings::refetchCategories'));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const downloadSettings = extractDownloadSettings(serverSettings.data!.settings);
|
||||
|
||||
const updateSetting = <Setting extends keyof DownloadSettingsType>(
|
||||
setting: Setting,
|
||||
value: DownloadSettingsType[Setting],
|
||||
) => {
|
||||
mutateSettings({ variables: { input: { settings: { [setting]: value } } } }).catch(() =>
|
||||
makeToast(t('global.error.label.failed_to_save_changes'), 'error'),
|
||||
);
|
||||
};
|
||||
|
||||
const updateMetadataSetting = createUpdateMetadataServerSettings<keyof MetadataDownloadSettings>(() =>
|
||||
makeToast(t('global.error.label.failed_to_save_changes'), 'error'),
|
||||
);
|
||||
|
||||
return (
|
||||
<List sx={{ pt: 0 }}>
|
||||
<TextSetting
|
||||
settingName={t('download.settings.download_path.label.title')}
|
||||
dialogDescription={t('download.settings.download_path.label.description')}
|
||||
value={downloadSettings?.downloadsPath}
|
||||
settingDescription={
|
||||
downloadSettings?.downloadsPath.length ? downloadSettings.downloadsPath : t('global.label.default')
|
||||
}
|
||||
handleChange={(path) => updateSetting('downloadsPath', path)}
|
||||
/>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.file_type.label.cbz')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={!!downloadSettings?.downloadAsCbz}
|
||||
onChange={(e) => updateSetting('downloadAsCbz', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="download-settings-auto-delete-downloads">
|
||||
{t('download.settings.delete_chapters.title')}
|
||||
</ListSubheader>
|
||||
}
|
||||
>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.delete_chapters.label.manually_marked_as_read')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={metadataSettings.deleteChaptersManuallyMarkedRead}
|
||||
onChange={(e) => updateMetadataSetting('deleteChaptersManuallyMarkedRead', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
<DeleteChaptersWhileReadingSetting
|
||||
chapterToDelete={metadataSettings.deleteChaptersWhileReading}
|
||||
handleChange={(chapterToDelete) =>
|
||||
updateMetadataSetting('deleteChaptersWhileReading', chapterToDelete)
|
||||
}
|
||||
/>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.delete_chapters.label.allow_deletion_of_bookmarked')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={metadataSettings.deleteChaptersWithBookmark}
|
||||
onChange={(e) => updateMetadataSetting('deleteChaptersWithBookmark', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
</List>
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="download-settings-auto-download">
|
||||
{t('download.settings.auto_download.title')}
|
||||
</ListSubheader>
|
||||
}
|
||||
>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.auto_download.label.new_chapters')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={!!downloadSettings?.autoDownloadNewChapters}
|
||||
onChange={(e) => updateSetting('autoDownloadNewChapters', e.target.checked)}
|
||||
/>
|
||||
</ListItem>
|
||||
<NumberSetting
|
||||
disabled={!downloadSettings?.autoDownloadNewChapters}
|
||||
settingTitle={t('download.settings.auto_download.download_limit.label.title')}
|
||||
dialogDescription={t('download.settings.auto_download.download_limit.label.description')}
|
||||
value={downloadSettings?.autoDownloadNewChaptersLimit ?? 0}
|
||||
settingValue={
|
||||
!downloadSettings.autoDownloadNewChaptersLimit
|
||||
? t('global.label.none')
|
||||
: t('download.settings.download_ahead.label.value', {
|
||||
chapters: downloadSettings.autoDownloadNewChaptersLimit,
|
||||
count: downloadSettings.autoDownloadNewChaptersLimit,
|
||||
})
|
||||
}
|
||||
defaultValue={0}
|
||||
minValue={0}
|
||||
maxValue={20}
|
||||
showSlider
|
||||
valueUnit={t('chapter.title_one')}
|
||||
handleUpdate={(autoDownloadNewChaptersLimit) =>
|
||||
updateSetting('autoDownloadNewChaptersLimit', autoDownloadNewChaptersLimit)
|
||||
}
|
||||
/>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.auto_download.label.ignore_with_unread_chapters')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={!!downloadSettings?.excludeEntryWithUnreadChapters}
|
||||
onChange={(e) => updateSetting('excludeEntryWithUnreadChapters', e.target.checked)}
|
||||
disabled={!downloadSettings?.autoDownloadNewChapters}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem>
|
||||
<ListItemText primary={t('download.settings.auto_download.label.ignore_re_uploads')} />
|
||||
<Switch
|
||||
edge="end"
|
||||
checked={!!downloadSettings?.autoDownloadIgnoreReUploads}
|
||||
onChange={(e) => updateSetting('autoDownloadIgnoreReUploads', e.target.checked)}
|
||||
disabled={!downloadSettings?.autoDownloadNewChapters}
|
||||
/>
|
||||
</ListItem>
|
||||
<CategoriesInclusionSetting
|
||||
categories={categories.data!.categories.nodes}
|
||||
includeField="includeInDownload"
|
||||
dialogText={t('download.settings.auto_download.categories.label.include_in_download')}
|
||||
/>
|
||||
</List>
|
||||
<List
|
||||
subheader={
|
||||
<ListSubheader component="div" id="download-settings-download-ahead">
|
||||
{t('download.settings.download_ahead.title')}
|
||||
</ListSubheader>
|
||||
}
|
||||
>
|
||||
<DownloadAheadSetting downloadAheadLimit={metadataSettings.downloadAheadLimit} />
|
||||
</List>
|
||||
</List>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user