Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/download queue staying stopped when removing download #299

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
"label": {
"no_downloads": "No downloads"
},
"error": {
"label": {
"failed_to_remove": "Could not remove download from queue."
}
},
"title": "Download Queue"
},
"state": {
Expand Down
27 changes: 21 additions & 6 deletions src/screens/DownloadQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Link } from 'react-router-dom';
import { BACK } from 'util/useBackTo';
import { useTranslation } from 'react-i18next';
import { IChapter, IQueue } from 'typings';
import makeToast from 'components/util/Toast';

const initialQueue = {
status: 'Stopped',
Expand Down Expand Up @@ -59,17 +60,31 @@ const DownloadQueue: React.FC = () => {
return <EmptyView message={t('download.queue.label.no_downloads')} />;
}

const handleDelete = (chapter: IChapter) => {
// required to stop before deleting otherwise the download kept going. Server issue?
client.get('/api/v1/downloads/stop').then(() =>
Promise.all([
const handleDelete = async (chapter: IChapter) => {
const isRunning = status === 'Started';

try {
if (isRunning) {
// required to stop before deleting otherwise the download kept going. Server issue?
await client.get('/api/v1/downloads/stop');
}

await Promise.all([
// remove from download queue
client.delete(`/api/v1/download/${chapter.mangaId}/chapter/${chapter.index}`),
// delete partial download, should be handle server side?
// bug: The folder and the last image downloaded are not deleted
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 (
Expand Down