Add retry button for failed downloads

This commit is contained in:
schroda
2024-09-12 16:02:20 +02:00
parent 8fc6900148
commit 6c01c222c3
4 changed files with 60 additions and 4 deletions

View File

@@ -157,7 +157,8 @@
"error": { "error": {
"label": { "label": {
"failed_delete_all": "Could not remove all downloads from the queue", "failed_delete_all": "Could not remove all downloads from the queue",
"failed_to_remove": "Could not remove the download from the queue." "failed_to_remove": "Could not remove the download from the queue.",
"failed_to_retry": "Could not retry failed download."
} }
}, },
"label": { "label": {

View File

@@ -13,6 +13,7 @@ import {
ChapterReadInfo, ChapterReadInfo,
Chapters, Chapters,
} from '@/lib/data/Chapters.ts'; } from '@/lib/data/Chapters.ts';
import { DownloadState } from '@/lib/graphql/generated/graphql.ts';
export type ChapterWithMetaType< export type ChapterWithMetaType<
Chapter extends ChapterDownloadInfo & ChapterReadInfo & ChapterBookmarkInfo = ChapterDownloadInfo & Chapter extends ChapterDownloadInfo & ChapterReadInfo & ChapterBookmarkInfo = ChapterDownloadInfo &
@@ -50,7 +51,10 @@ export class ChaptersWithMeta {
} }
static getDownloadable<Chapter extends ChapterWithMetaType>(chapters: Chapter[]): Chapter[] { static getDownloadable<Chapter extends ChapterWithMetaType>(chapters: Chapter[]): Chapter[] {
return chapters.filter(({ chapter, downloadChapter }) => !Chapters.isDownloaded(chapter) && !downloadChapter); return chapters.filter(
({ chapter, downloadChapter }) =>
!Chapters.isDownloaded(chapter) && downloadChapter?.state !== DownloadState.Error,
);
} }
static getBookmarked<Chapter extends ChapterWithMetaType>(chapters: Chapter[]): Chapter[] { static getBookmarked<Chapter extends ChapterWithMetaType>(chapters: Chapter[]): Chapter[] {

View File

@@ -24,6 +24,7 @@ import { useTranslation } from 'react-i18next';
import DeleteSweepIcon from '@mui/icons-material/DeleteSweep'; import DeleteSweepIcon from '@mui/icons-material/DeleteSweep';
import { Virtuoso } from 'react-virtuoso'; import { Virtuoso } from 'react-virtuoso';
import CardContent from '@mui/material/CardContent'; import CardContent from '@mui/material/CardContent';
import Refresh from '@mui/icons-material/Refresh';
import { requestManager } from '@/lib/requests/RequestManager.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts';
import { StrictModeDroppable } from '@/lib/StrictModeDroppable'; import { StrictModeDroppable } from '@/lib/StrictModeDroppable';
import { makeToast } from '@/components/util/Toast'; import { makeToast } from '@/components/util/Toast';
@@ -33,6 +34,7 @@ import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { ChapterDownloadStatus, ChapterIdInfo } from '@/lib/data/Chapters.ts'; import { ChapterDownloadStatus, ChapterIdInfo } from '@/lib/data/Chapters.ts';
import { DownloadState } from '@/lib/graphql/generated/graphql.ts';
const HeightPreservingItem = ({ children, ...props }: BoxProps) => ( const HeightPreservingItem = ({ children, ...props }: BoxProps) => (
// the height is necessary to prevent the item container from collapsing, which confuses Virtuoso measurements // the height is necessary to prevent the item container from collapsing, which confuses Virtuoso measurements
@@ -45,10 +47,12 @@ const DownloadChapterItem = ({
provided, provided,
item, item,
handleDelete, handleDelete,
handleRetry,
}: { }: {
provided: DraggableProvided; provided: DraggableProvided;
item: ChapterDownloadStatus; item: ChapterDownloadStatus;
handleDelete: (chapter: ChapterIdInfo) => void; handleDelete: (chapter: ChapterIdInfo) => void;
handleRetry: (chapter: ChapterIdInfo) => void;
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -80,6 +84,20 @@ const DownloadChapterItem = ({
</Typography> </Typography>
</Stack> </Stack>
<DownloadStateIndicator download={item} /> <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')}> <Tooltip title={t('chapter.action.download.delete.label.action')}>
<IconButton <IconButton
onClick={(e) => { onClick={(e) => {
@@ -193,6 +211,14 @@ export const DownloadQueue: React.FC = () => {
categoryReorder(queue, result.source.index, result.destination.index); 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 handleDelete = async (chapter: ChapterIdInfo) => {
const isRunning = status === 'STARTED'; const isRunning = status === 'STARTED';
@@ -210,7 +236,7 @@ export const DownloadQueue: React.FC = () => {
requestManager.deleteDownloadedChapter(chapter.id).response, requestManager.deleteDownloadedChapter(chapter.id).response,
]); ]);
} catch (e) { } catch (e) {
makeToast(t('download.queue.error.label.failed_to_remove'), 'error'); makeToast(t('download.queue.error.label.failed_to_retry'), 'error');
} }
if (!isRunning) { if (!isRunning) {
@@ -248,6 +274,7 @@ export const DownloadQueue: React.FC = () => {
provided={provided} provided={provided}
item={queue[rubric.source.index]} item={queue[rubric.source.index]}
handleDelete={handleDelete} handleDelete={handleDelete}
handleRetry={handleRetry}
/> />
)} )}
> >
@@ -271,6 +298,7 @@ export const DownloadQueue: React.FC = () => {
provided={draggableProvided} provided={draggableProvided}
item={item} item={item}
handleDelete={handleDelete} handleDelete={handleDelete}
handleRetry={handleRetry}
/> />
)} )}
</Draggable> </Draggable>

View File

@@ -18,11 +18,12 @@ import Typography from '@mui/material/Typography';
import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { Link, useLocation } from 'react-router-dom'; import { Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Refresh from '@mui/icons-material/Refresh';
import { requestManager } from '@/lib/requests/RequestManager.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
import { EmptyViewAbsoluteCentered } from '@/components/util/EmptyViewAbsoluteCentered.tsx'; import { EmptyViewAbsoluteCentered } from '@/components/util/EmptyViewAbsoluteCentered.tsx';
import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndicator'; import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndicator';
import { ChapterType } from '@/lib/graphql/generated/graphql.ts'; import { ChapterType, DownloadState } from '@/lib/graphql/generated/graphql.ts';
import { NavBarContext } from '@/components/context/NavbarContext.tsx'; import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { UpdateChecker } from '@/components/library/UpdateChecker.tsx'; import { UpdateChecker } from '@/components/library/UpdateChecker.tsx';
import { StyledGroupedVirtuoso } from '@/components/virtuoso/StyledGroupedVirtuoso.tsx'; import { StyledGroupedVirtuoso } from '@/components/virtuoso/StyledGroupedVirtuoso.tsx';
@@ -102,6 +103,14 @@ export const Updates: React.FC = () => {
return queue.find((q) => sourceOrder === q.chapter.sourceOrder && mangaId === q.manga.id); return queue.find((q) => sourceOrder === q.chapter.sourceOrder && mangaId === q.manga.id);
}; };
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 downloadChapter = (chapter: ChapterIdInfo) => { const downloadChapter = (chapter: ChapterIdInfo) => {
requestManager requestManager
.addChapterToDownloadQueue(chapter.id) .addChapterToDownloadQueue(chapter.id)
@@ -228,6 +237,20 @@ export const Updates: React.FC = () => {
</Box> </Box>
</Box> </Box>
{download && <DownloadStateIndicator download={download} />} {download && <DownloadStateIndicator download={download} />}
{download?.state === DownloadState.Error && (
<Tooltip title={t('global.button.retry')}>
<IconButton
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleRetry(download.chapter);
}}
size="large"
>
<Refresh />
</IconButton>
</Tooltip>
)}
{download == null && !chapter.isDownloaded && ( {download == null && !chapter.isDownloaded && (
<Tooltip title={t('chapter.action.download.add.label.action')}> <Tooltip title={t('chapter.action.download.add.label.action')}>
<IconButton <IconButton