Check download queue for changes and reload chapters if any chapter download changes state. (#189)
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import React, {
|
import React, {
|
||||||
useState, useEffect, useCallback, useMemo,
|
useState, useEffect, useCallback, useMemo, useRef,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { Box, styled } from '@mui/system';
|
import { Box, styled } from '@mui/system';
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
@@ -52,6 +52,7 @@ export default function ChapterList({ id, chaptersData, onRefresh }: IProps) {
|
|||||||
chapterOptionsReducer, `${id}filterOptions`, defaultChapterOptions,
|
chapterOptionsReducer, `${id}filterOptions`, defaultChapterOptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const prevQueueRef = useRef<IDownloadChapter[]>();
|
||||||
const queue = useSubscription<IQueue>('/api/v1/downloads').data?.queue;
|
const queue = useSubscription<IQueue>('/api/v1/downloads').data?.queue;
|
||||||
|
|
||||||
const downloadStatusStringFor = useCallback((chapter: IChapter) => {
|
const downloadStatusStringFor = useCallback((chapter: IChapter) => {
|
||||||
@@ -67,6 +68,25 @@ export default function ChapterList({ id, chaptersData, onRefresh }: IProps) {
|
|||||||
return rtn;
|
return rtn;
|
||||||
}, [queue]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
const filtered = filterAndSortChapters(chapters, options);
|
const filtered = filterAndSortChapters(chapters, options);
|
||||||
setFilteredChapters(filtered);
|
setFilteredChapters(filtered);
|
||||||
|
|||||||
Reference in New Issue
Block a user