Read chapter download status from cache
Instead of getting the whole download status, which contains all queued/active downloads, the download status should be read from the cache for only the required chapters
This commit is contained in:
@@ -12,14 +12,14 @@ import { IChapterWithMeta } from '@/modules/chapter/components/ChapterList.tsx';
|
||||
import { ChapterCard } from '@/modules/chapter/components/cards/ChapterCard.tsx';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { ReaderStateChapters } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { Chapters } from '@/modules/chapter/services/Chapters';
|
||||
|
||||
export const ReaderChapterList = ({
|
||||
currentChapter,
|
||||
chapters,
|
||||
style,
|
||||
}: Pick<ReaderStateChapters, 'chapters' | 'currentChapter'> & Pick<VirtuosoProps<any, any>, 'style'>) => {
|
||||
const { data: downloaderData } = requestManager.useGetDownloadStatus();
|
||||
const queue = downloaderData?.downloadStatus.queue ?? [];
|
||||
const downloadSubscription = requestManager.useDownloadSubscription();
|
||||
|
||||
const currentChapterIndex = useMemo(
|
||||
() => currentChapter && chapters.findIndex((chapter) => chapter.id === currentChapter.id),
|
||||
@@ -29,7 +29,7 @@ export const ReaderChapterList = ({
|
||||
const chaptersWithMeta: IChapterWithMeta[] = useMemo(
|
||||
() =>
|
||||
chapters.map((chapter) => {
|
||||
const downloadChapter = queue?.find((cd) => cd.chapter.id === chapter.id);
|
||||
const downloadChapter = Chapters.getDownloadStatusFromCache(chapter.id);
|
||||
|
||||
return {
|
||||
chapter,
|
||||
@@ -37,7 +37,7 @@ export const ReaderChapterList = ({
|
||||
selected: null,
|
||||
};
|
||||
}),
|
||||
[queue, chapters],
|
||||
[downloadSubscription.data?.downloadStatusChanged, chapters],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -21,18 +21,16 @@ import { actionToTranslationKey, ChapterAction, Chapters } from '@/modules/chapt
|
||||
import { ReaderStateChapters } from '@/modules/reader/types/Reader.types.ts';
|
||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { DownloadStateIndicator } from '@/modules/core/components/DownloadStateIndicator.tsx';
|
||||
import { DownloadStatusFieldsFragment } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
|
||||
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
||||
import { useReaderStateChaptersContext } from '@/modules/reader/contexts/state/ReaderStateChaptersContext.tsx';
|
||||
import { userReaderStatePagesContext } from '@/modules/reader/contexts/state/ReaderStatePagesContext.tsx';
|
||||
import { ChapterWithMetaType } from '@/modules/chapter/services/ChaptersWithMeta.ts';
|
||||
|
||||
const DownloadButton = ({
|
||||
currentChapter,
|
||||
downloadChapter,
|
||||
}: Required<Pick<ReaderStateChapters, 'currentChapter'>> & {
|
||||
downloadChapter?: DownloadStatusFieldsFragment['queue'][number];
|
||||
}) => {
|
||||
}: Required<Pick<ReaderStateChapters, 'currentChapter'>> & Pick<ChapterWithMetaType, 'downloadChapter'>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (currentChapter && Chapters.isDownloaded(currentChapter)) {
|
||||
@@ -76,13 +74,15 @@ const BaseReaderNavBarDesktopActions = memo(
|
||||
|
||||
const pageRetryKeyPrefix = useRef<number>(0);
|
||||
|
||||
const { data: downloaderData } = requestManager.useGetDownloadStatus();
|
||||
const queue = downloaderData?.downloadStatus.queue ?? [];
|
||||
const downloadSubscription = requestManager.useDownloadSubscription();
|
||||
|
||||
const downloadChapter = useMemo(
|
||||
() => queue.find((queueItem) => queueItem.chapter.id === currentChapter?.id),
|
||||
[queue, id],
|
||||
);
|
||||
const downloadChapter = useMemo(() => {
|
||||
if (!currentChapter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Chapters.getDownloadStatusFromCache(currentChapter?.id);
|
||||
}, [downloadSubscription.data?.downloadStatusChanged, id]);
|
||||
|
||||
const haveSomePagesFailedToLoad = useMemo(
|
||||
() => pageLoadStates.some((pageLoadState) => pageLoadState.error),
|
||||
|
||||
Reference in New Issue
Block a user