/* eslint-disable @typescript-eslint/no-shadow */ /* eslint-disable react/destructuring-assignment */ /* * 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, CardActionArea, Stack } from '@mui/material'; import IconButton from '@mui/material/IconButton'; import NavbarContext from 'components/context/NavbarContext'; import EmptyView from 'components/util/EmptyView'; import React, { useContext, useEffect } from 'react'; import { DragDropContext, Draggable, Droppable, DropResult } from 'react-beautiful-dnd'; import client from 'util/client'; import Typography from '@mui/material/Typography'; import { Box } from '@mui/system'; import useSubscription from 'components/library/useSubscription'; import DownloadStateIndicator from 'components/molecules/DownloadStateIndicator'; import { NavbarToolbar } from 'components/navbar/DefaultNavBar'; import { Link } from 'react-router-dom'; import { BACK } from 'util/useBackTo'; import { useTranslation } from 'react-i18next'; import { IChapter, IQueue } from 'typings'; const initialQueue = { status: 'Stopped', queue: [], } as IQueue; const DownloadQueue: React.FC = () => { const { t } = useTranslation(); const { data: queueState } = useSubscription('/api/v1/downloads'); const { queue, status } = queueState ?? initialQueue; const { setTitle, setAction } = useContext(NavbarContext); const toggleQueueStatus = () => { if (status === 'Stopped') { client.get('/api/v1/downloads/start'); } else { client.get('/api/v1/downloads/stop'); } }; useEffect(() => { setTitle(t('download.queue.title')); setAction(null); }, [t]); // eslint-disable-next-line @typescript-eslint/no-unused-vars const onDragEnd = (result: DropResult) => {}; if (queue.length === 0) { return ; } 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([ // 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}`), ]), ); }; return ( <> {status === 'Stopped' ? : } {(provided) => ( {queue.map((item, index) => ( {(provided, snapshot) => ( {item.manga.title} {item.chapter.name} { e.preventDefault(); e.stopPropagation(); handleDelete(item.chapter); }} size="large" > )} ))} {provided.placeholder} )} ); }; export default DownloadQueue;