Remove unnecessary TFunction parameter
This commit is contained in:
@@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
import { MutableRefObject, RefObject, useCallback, useEffect } from 'react';
|
import { MutableRefObject, RefObject, useCallback, useEffect } from 'react';
|
||||||
import { Direction, useTheme } from '@mui/material/styles';
|
import { Direction, useTheme } from '@mui/material/styles';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { t as translate } from 'i18next';
|
||||||
import { TFunction } from 'i18next';
|
|
||||||
import {
|
import {
|
||||||
getNextIndexFromPage,
|
getNextIndexFromPage,
|
||||||
getNextPageIndex,
|
getNextPageIndex,
|
||||||
@@ -164,110 +163,103 @@ export class ReaderControls {
|
|||||||
doTransitionCheck?: boolean,
|
doTransitionCheck?: boolean,
|
||||||
scrollIntoView?: boolean,
|
scrollIntoView?: boolean,
|
||||||
) => void {
|
) => void {
|
||||||
const { t } = useTranslation();
|
return useCallback((offset, doTransitionCheck = true, scrollIntoView = true) => {
|
||||||
|
const {
|
||||||
|
chapters: {
|
||||||
|
currentChapter,
|
||||||
|
previousChapter,
|
||||||
|
nextChapter,
|
||||||
|
chapters,
|
||||||
|
visibleChapters: { lastLeadingChapterSourceOrder, lastTrailingChapterSourceOrder },
|
||||||
|
setReaderStateChapters,
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
shouldInformAboutMissingChapter,
|
||||||
|
shouldInformAboutScanlatorChange,
|
||||||
|
shouldUseInfiniteScroll,
|
||||||
|
},
|
||||||
|
} = getReaderStore();
|
||||||
|
|
||||||
return useCallback(
|
if (!currentChapter) {
|
||||||
(offset, doTransitionCheck = true, scrollIntoView = true) => {
|
return;
|
||||||
const {
|
}
|
||||||
chapters: {
|
|
||||||
currentChapter,
|
|
||||||
previousChapter,
|
|
||||||
nextChapter,
|
|
||||||
chapters,
|
|
||||||
visibleChapters: { lastLeadingChapterSourceOrder, lastTrailingChapterSourceOrder },
|
|
||||||
setReaderStateChapters,
|
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
shouldInformAboutMissingChapter,
|
|
||||||
shouldInformAboutScanlatorChange,
|
|
||||||
shouldUseInfiniteScroll,
|
|
||||||
},
|
|
||||||
} = getReaderStore();
|
|
||||||
|
|
||||||
if (!currentChapter) {
|
const isSpecificChapterMode = typeof offset === 'number';
|
||||||
return;
|
const isPreviousOffset = offset === 'previous';
|
||||||
}
|
|
||||||
|
|
||||||
const isSpecificChapterMode = typeof offset === 'number';
|
const doesPreviousChapterExist = isPreviousOffset && !!previousChapter;
|
||||||
const isPreviousOffset = offset === 'previous';
|
const doesNextChapterExist = !isPreviousOffset && !!nextChapter;
|
||||||
|
|
||||||
const doesPreviousChapterExist = isPreviousOffset && !!previousChapter;
|
const canOpenNextChapter = isSpecificChapterMode || doesPreviousChapterExist || doesNextChapterExist;
|
||||||
const doesNextChapterExist = !isPreviousOffset && !!nextChapter;
|
if (!canOpenNextChapter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const canOpenNextChapter = isSpecificChapterMode || doesPreviousChapterExist || doesNextChapterExist;
|
const doOpenChapter = async () => {
|
||||||
if (!canOpenNextChapter) {
|
const chapterToOpen = (() => {
|
||||||
return;
|
if (isSpecificChapterMode) {
|
||||||
}
|
return chapters.find((chapter) => chapter.id === offset);
|
||||||
|
|
||||||
const doOpenChapter = async () => {
|
|
||||||
const chapterToOpen = (() => {
|
|
||||||
if (isSpecificChapterMode) {
|
|
||||||
return chapters.find((chapter) => chapter.id === offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPreviousOffset) {
|
|
||||||
return previousChapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nextChapter;
|
|
||||||
})();
|
|
||||||
|
|
||||||
if (!chapterToOpen) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPreviousChapter = chapterToOpen.sourceOrder < currentChapter.sourceOrder;
|
if (isPreviousOffset) {
|
||||||
|
return previousChapter;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
return nextChapter;
|
||||||
if (doTransitionCheck) {
|
})();
|
||||||
await ReaderControls.checkNextChapterConsistency(
|
|
||||||
t,
|
|
||||||
isPreviousChapter ? 'previous' : 'next',
|
|
||||||
currentChapter,
|
|
||||||
chapterToOpen,
|
|
||||||
shouldInformAboutMissingChapter,
|
|
||||||
shouldInformAboutScanlatorChange,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isAlreadyLoaded =
|
if (!chapterToOpen) {
|
||||||
lastLeadingChapterSourceOrder <= chapterToOpen.sourceOrder &&
|
return;
|
||||||
lastTrailingChapterSourceOrder >= chapterToOpen.sourceOrder;
|
}
|
||||||
const keepRenderedChapters = shouldUseInfiniteScroll && (!scrollIntoView || isAlreadyLoaded);
|
|
||||||
|
|
||||||
if (keepRenderedChapters) {
|
const isPreviousChapter = chapterToOpen.sourceOrder < currentChapter.sourceOrder;
|
||||||
setReaderStateChapters((prevState) =>
|
|
||||||
updateReaderStateVisibleChapters(
|
|
||||||
isPreviousChapter,
|
|
||||||
prevState,
|
|
||||||
chapterToOpen.sourceOrder,
|
|
||||||
scrollIntoView,
|
|
||||||
isPreviousChapter ? false : undefined,
|
|
||||||
!isPreviousChapter ? false : undefined,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReaderService.navigateToChapter(chapterToOpen, {
|
try {
|
||||||
resumeMode: getReaderOpenChapterResumeMode(
|
if (doTransitionCheck) {
|
||||||
isSpecificChapterMode || !keepRenderedChapters,
|
await ReaderControls.checkNextChapterConsistency(
|
||||||
|
isPreviousChapter ? 'previous' : 'next',
|
||||||
|
currentChapter,
|
||||||
|
chapterToOpen,
|
||||||
|
shouldInformAboutMissingChapter,
|
||||||
|
shouldInformAboutScanlatorChange,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isAlreadyLoaded =
|
||||||
|
lastLeadingChapterSourceOrder <= chapterToOpen.sourceOrder &&
|
||||||
|
lastTrailingChapterSourceOrder >= chapterToOpen.sourceOrder;
|
||||||
|
const keepRenderedChapters = shouldUseInfiniteScroll && (!scrollIntoView || isAlreadyLoaded);
|
||||||
|
|
||||||
|
if (keepRenderedChapters) {
|
||||||
|
setReaderStateChapters((prevState) =>
|
||||||
|
updateReaderStateVisibleChapters(
|
||||||
isPreviousChapter,
|
isPreviousChapter,
|
||||||
|
prevState,
|
||||||
|
chapterToOpen.sourceOrder,
|
||||||
|
scrollIntoView,
|
||||||
|
isPreviousChapter ? false : undefined,
|
||||||
|
!isPreviousChapter ? false : undefined,
|
||||||
),
|
),
|
||||||
updateInitialChapter: !keepRenderedChapters,
|
);
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
defaultPromiseErrorHandler('ReaderControls#useOpenChapter#doOpenChapter:')(error);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
doOpenChapter().catch(defaultPromiseErrorHandler('ReaderControls#useOpenChapter'));
|
ReaderService.navigateToChapter(chapterToOpen, {
|
||||||
},
|
resumeMode: getReaderOpenChapterResumeMode(
|
||||||
[t],
|
isSpecificChapterMode || !keepRenderedChapters,
|
||||||
);
|
isPreviousChapter,
|
||||||
|
),
|
||||||
|
updateInitialChapter: !keepRenderedChapters,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
defaultPromiseErrorHandler('ReaderControls#useOpenChapter#doOpenChapter:')(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
doOpenChapter().catch(defaultPromiseErrorHandler('ReaderControls#useOpenChapter'));
|
||||||
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async checkNextChapterConsistency(
|
private static async checkNextChapterConsistency(
|
||||||
t: TFunction,
|
|
||||||
offset: 'previous' | 'next',
|
offset: 'previous' | 'next',
|
||||||
currentChapter: TChapterReader | null | undefined,
|
currentChapter: TChapterReader | null | undefined,
|
||||||
chapterToOpen: TChapterReader | null | undefined,
|
chapterToOpen: TChapterReader | null | undefined,
|
||||||
@@ -301,13 +293,13 @@ export class ReaderControls {
|
|||||||
|
|
||||||
const sameScanlator = isSameScanlator
|
const sameScanlator = isSameScanlator
|
||||||
? ''
|
? ''
|
||||||
: t(offsetToTranslationKeys[offset].scanlator, {
|
: translate(offsetToTranslationKeys[offset].scanlator, {
|
||||||
nextScanlator: chapterToOpen.scanlator,
|
nextScanlator: chapterToOpen.scanlator,
|
||||||
currentScanlator: currentChapter.scanlator,
|
currentScanlator: currentChapter.scanlator,
|
||||||
});
|
});
|
||||||
const continuousChapter = isContinuousChapter
|
const continuousChapter = isContinuousChapter
|
||||||
? ''
|
? ''
|
||||||
: t(offsetToTranslationKeys[offset].chapter_number, {
|
: translate(offsetToTranslationKeys[offset].chapter_number, {
|
||||||
count: missingChapters,
|
count: missingChapters,
|
||||||
nextChapter: `#${chapterToOpen.chapterNumber} ${chapterToOpen.name}`,
|
nextChapter: `#${chapterToOpen.chapterNumber} ${chapterToOpen.name}`,
|
||||||
currentChapter: `#${currentChapter.chapterNumber} ${currentChapter.name}`,
|
currentChapter: `#${currentChapter.chapterNumber} ${currentChapter.name}`,
|
||||||
@@ -316,11 +308,11 @@ export class ReaderControls {
|
|||||||
const warning = `${sameScanlator}${warningLineBreak}${continuousChapter}`;
|
const warning = `${sameScanlator}${warningLineBreak}${continuousChapter}`;
|
||||||
|
|
||||||
await awaitConfirmation({
|
await awaitConfirmation({
|
||||||
title: t('reader.chapter_transition.warning.title'),
|
title: translate('reader.chapter_transition.warning.title'),
|
||||||
message: warning,
|
message: warning,
|
||||||
actions: {
|
actions: {
|
||||||
confirm: {
|
confirm: {
|
||||||
title: t('global.button.open'),
|
title: translate('global.button.open'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user