Fix/download queue staying stopped when removing download (#299)
* [Cleanup] Use async/await * Show download queue removal error toast * Optionally restart download queue after removing download When removing a download while the download queue was running, the queue was never started again.
This commit is contained in:
@@ -142,6 +142,11 @@
|
|||||||
"label": {
|
"label": {
|
||||||
"no_downloads": "No downloads"
|
"no_downloads": "No downloads"
|
||||||
},
|
},
|
||||||
|
"error": {
|
||||||
|
"label": {
|
||||||
|
"failed_to_remove": "Could not remove download from queue."
|
||||||
|
}
|
||||||
|
},
|
||||||
"title": "Download Queue"
|
"title": "Download Queue"
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { Link } from 'react-router-dom';
|
|||||||
import { BACK } from 'util/useBackTo';
|
import { BACK } from 'util/useBackTo';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { IChapter, IQueue } from 'typings';
|
import { IChapter, IQueue } from 'typings';
|
||||||
|
import makeToast from 'components/util/Toast';
|
||||||
|
|
||||||
const initialQueue = {
|
const initialQueue = {
|
||||||
status: 'Stopped',
|
status: 'Stopped',
|
||||||
@@ -59,17 +60,31 @@ const DownloadQueue: React.FC = () => {
|
|||||||
return <EmptyView message={t('download.queue.label.no_downloads')} />;
|
return <EmptyView message={t('download.queue.label.no_downloads')} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDelete = (chapter: IChapter) => {
|
const handleDelete = async (chapter: IChapter) => {
|
||||||
|
const isRunning = status === 'Started';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isRunning) {
|
||||||
// required to stop before deleting otherwise the download kept going. Server issue?
|
// required to stop before deleting otherwise the download kept going. Server issue?
|
||||||
client.get('/api/v1/downloads/stop').then(() =>
|
await client.get('/api/v1/downloads/stop');
|
||||||
Promise.all([
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
// remove from download queue
|
// remove from download queue
|
||||||
client.delete(`/api/v1/download/${chapter.mangaId}/chapter/${chapter.index}`),
|
client.delete(`/api/v1/download/${chapter.mangaId}/chapter/${chapter.index}`),
|
||||||
// delete partial download, should be handle server side?
|
// delete partial download, should be handle server side?
|
||||||
// bug: The folder and the last image downloaded are not deleted
|
// bug: The folder and the last image downloaded are not deleted
|
||||||
client.delete(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`),
|
client.delete(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`),
|
||||||
]),
|
]);
|
||||||
);
|
} catch (error) {
|
||||||
|
makeToast(t('download.queue.error.label.failed_to_remove'), 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isRunning) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.get('/api/v1/downloads/start').catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user