Move download status subscription to "ChapterCard"
Only re-render chapters whose download status has changed instead of the whole list everytime a download status change was received
This commit is contained in:
@@ -11,7 +11,7 @@ import Box from '@mui/material/Box';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { DownloadState } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { ChapterDownloadStatus } from '@/modules/chapter/services/Chapters.ts';
|
||||
import { ChapterIdInfo, Chapters } from '@/modules/chapter/services/Chapters.ts';
|
||||
import { TranslationKey } from '@/Base.types.ts';
|
||||
|
||||
const DOWNLOAD_STATE_TO_TRANSLATION_KEY_MAP: { [state in DownloadState]: TranslationKey } = {
|
||||
@@ -21,9 +21,15 @@ const DOWNLOAD_STATE_TO_TRANSLATION_KEY_MAP: { [state in DownloadState]: Transla
|
||||
QUEUED: 'download.state.label.queued',
|
||||
} as const;
|
||||
|
||||
export const DownloadStateIndicator = ({ download }: { download: ChapterDownloadStatus }) => {
|
||||
export const DownloadStateIndicator = ({ chapterId }: { chapterId: ChapterIdInfo['id'] }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const download = Chapters.useDownloadStatusFromCache(chapterId);
|
||||
|
||||
if (!download) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isDownloading = download.state === DownloadState.Downloading;
|
||||
const isPartiallyDownloaded = download.progress !== 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user