diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index c262cae9e3..1d7ccb479b 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -141,10 +141,12 @@ "queue": { "error": { "label": { - "failed_to_remove": "Could not remove download from queue." + "failed_to_remove": "Could not remove the download from the queue.", + "failed_delete_all": "Could not remove all downloads from the queue" } }, "label": { + "delete_all": "Delete all", "no_downloads": "No downloads" }, "title": "Download Queue" diff --git a/src/screens/DownloadQueue.tsx b/src/screens/DownloadQueue.tsx index be829ee4a5..88f7366c9e 100644 --- a/src/screens/DownloadQueue.tsx +++ b/src/screens/DownloadQueue.tsx @@ -14,14 +14,13 @@ import { Card, CardActionArea, Stack, Box, Tooltip } from '@mui/material'; import IconButton from '@mui/material/IconButton'; import React, { useContext, useEffect } from 'react'; import { DragDropContext, Draggable } 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 { requestManager } from '@/lib/requests/RequestManager.ts'; import { StrictModeDroppable } from '@/lib/StrictModeDroppable'; import { makeToast } from '@/components/util/Toast'; -import { NavbarToolbar } from '@/components/navbar/DefaultNavBar'; import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndicator'; import { EmptyView } from '@/components/util/EmptyView'; import { DownloadType } from '@/lib/graphql/generated/graphql.ts'; @@ -34,9 +33,18 @@ export const DownloadQueue: React.FC = () => { const { data: downloaderData } = requestManager.useDownloadSubscription(); const queue = (downloaderData?.downloadChanged.queue as DownloadType[]) ?? []; const status = downloaderData?.downloadChanged.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(); @@ -47,14 +55,24 @@ export const DownloadQueue: React.FC = () => { useEffect(() => { setTitle(t('download.queue.title')); - setAction(null); - }, [t]); + setAction( + <> + + + + + - const onDragEnd = () => {}; + + + {status === 'STOPPED' ? : } + + + , + ); + }, [t, status, isQueueEmpty]); - if (queue.length === 0) { - return ; - } + const onDragEnd = () => {}; const handleDelete = async (chapter: TChapter) => { const isRunning = status === 'STARTED'; @@ -83,79 +101,74 @@ export const DownloadQueue: React.FC = () => { requestManager.startDownloads().response.catch(() => {}); }; + if (isQueueEmpty) { + return ; + } + return ( - <> - - - - {status === 'STOPPED' ? : } - - - - - - {(droppableProvided) => ( - - {queue.map((item, index) => ( - - {(draggableProvided, snapshot) => ( - + + {(droppableProvided) => ( + + {queue.map((item, index) => ( + + {(draggableProvided, snapshot) => ( + + - - - - + + + + + {item.chapter.manga.title} + + {item.chapter.name} + + + + + { + e.preventDefault(); + e.stopPropagation(); + handleDelete(item.chapter); + }} + size="large" + > + - - {item.chapter.manga.title} - - {item.chapter.name} - - - - - { - e.preventDefault(); - e.stopPropagation(); - handleDelete(item.chapter); - }} - size="large" - > - - - - - - - )} - - ))} - {droppableProvided.placeholder} - - )} - - - + + + + + )} + + ))} + {droppableProvided.placeholder} + + )} + + ); };