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 chapters not being marked as Downloaded in chapter list when download finishes #189

Merged
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
22 changes: 21 additions & 1 deletion src/components/chapter/ChapterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import React, {
useState, useEffect, useCallback, useMemo,
useState, useEffect, useCallback, useMemo, useRef,
} from 'react';
import { Box, styled } from '@mui/system';
import { Virtuoso } from 'react-virtuoso';
Expand Down Expand Up @@ -52,6 +52,7 @@ export default function ChapterList({ id, chaptersData, onRefresh }: IProps) {
chapterOptionsReducer, `${id}filterOptions`, defaultChapterOptions,
);

const prevQueueRef = useRef<IDownloadChapter[]>();
const queue = useSubscription<IQueue>('/api/v1/downloads').data?.queue;

const downloadStatusStringFor = useCallback((chapter: IChapter) => {
Expand All @@ -67,6 +68,25 @@ export default function ChapterList({ id, chaptersData, onRefresh }: IProps) {
return rtn;
}, [queue]);

useEffect(() => {
if (prevQueueRef.current && queue) {
const prevQueue = prevQueueRef.current;
const changedDownloads = queue.filter((cd) => {
const prevChapterDownload = prevQueue
.find((pcd) => cd.chapterIndex === pcd.chapterIndex
&& cd.mangaId === pcd.mangaId);
if (!prevChapterDownload) return true;
return cd.state !== prevChapterDownload.state;
});

if (changedDownloads.length > 0) {
onRefresh();
}
}

prevQueueRef.current = queue;
}, [queue]);

useEffect(() => {
const filtered = filterAndSortChapters(chapters, options);
setFilteredChapters(filtered);
Expand Down