Rename "initialChapter" to "chapterForDuplicatesHandling"

This commit is contained in:
schroda
2025-02-01 20:03:02 +01:00
parent a80e8885fb
commit 91e8b70d35
5 changed files with 21 additions and 20 deletions

View File

@@ -16,7 +16,7 @@ import { IReaderSettings, ReaderStateChapters } from '@/modules/reader/types/Rea
export const useReaderSetChaptersState = (
chaptersResponse: ReturnType<typeof requestManager.useGetMangaChapters<GetChaptersReaderQuery>>,
chapterSourceOrder: number,
initialChapter: ReaderStateChapters['initialChapter'],
chapterForDuplicatesHandling: ReaderStateChapters['chapterForDuplicatesHandling'],
setReaderStateChapters: ReaderStateChapters['setReaderStateChapters'],
shouldSkipDupChapters: IReaderSettings['shouldSkipDupChapters'],
) => {
@@ -25,15 +25,15 @@ export const useReaderSetChaptersState = (
const newCurrentChapter = newMangaChapters
? (newMangaChapters[newMangaChapters.length - chapterSourceOrder] ?? null)
: undefined;
const newInitialChapter = initialChapter ?? newCurrentChapter;
const newChapterForDuplicatesHandling = chapterForDuplicatesHandling ?? newCurrentChapter;
setReaderStateChapters({
mangaChapters: newMangaChapters ?? [],
chapters:
newInitialChapter && newMangaChapters
? Chapters.removeDuplicates(newInitialChapter, newMangaChapters)
newChapterForDuplicatesHandling && newMangaChapters
? Chapters.removeDuplicates(newChapterForDuplicatesHandling, newMangaChapters)
: [],
initialChapter: newInitialChapter,
chapterForDuplicatesHandling: newChapterForDuplicatesHandling,
currentChapter: newCurrentChapter,
nextChapter:
newMangaChapters &&
@@ -41,7 +41,7 @@ export const useReaderSetChaptersState = (
Chapters.getNextChapter(newCurrentChapter, newMangaChapters, {
offset: DirectionOffset.NEXT,
skipDupe: shouldSkipDupChapters,
skipDupeChapter: newInitialChapter,
skipDupeChapter: newChapterForDuplicatesHandling,
}),
previousChapter:
newMangaChapters &&
@@ -49,7 +49,7 @@ export const useReaderSetChaptersState = (
Chapters.getNextChapter(newCurrentChapter, newMangaChapters, {
offset: DirectionOffset.PREVIOUS,
skipDupe: shouldSkipDupChapters,
skipDupeChapter: newInitialChapter,
skipDupeChapter: newChapterForDuplicatesHandling,
}),
});
}, [chaptersResponse.data?.chapters.nodes, chapterSourceOrder, shouldSkipDupChapters]);

View File

@@ -70,7 +70,7 @@ const BaseReader = ({
shouldShowReadingModePreview,
shouldShowTapZoneLayoutPreview,
setSettings,
initialChapter,
chapterForDuplicatesHandling,
currentChapter,
mangaChapters,
setReaderStateChapters,
@@ -94,7 +94,7 @@ const BaseReader = ({
'shouldSkipDupChapters' | 'backgroundColor' | 'shouldShowReadingModePreview' | 'shouldShowTapZoneLayoutPreview'
> &
Pick<IReaderSettingsWithDefaultFlag, 'readingMode' | 'tapZoneLayout' | 'tapZoneInvertMode'> &
Pick<ReaderStateChapters, 'initialChapter' | 'currentChapter' | 'mangaChapters' | 'setReaderStateChapters'> &
Pick<ReaderStateChapters, 'chapterForDuplicatesHandling' | 'currentChapter' | 'mangaChapters' | 'setReaderStateChapters'> &
Pick<
ReaderStatePages,
| 'totalPages'
@@ -232,7 +232,7 @@ const BaseReader = ({
useReaderSetChaptersState(
chaptersResponse,
chapterSourceOrder,
initialChapter,
chapterForDuplicatesHandling,
setReaderStateChapters,
shouldSkipDupChapters,
);
@@ -395,7 +395,7 @@ export const Reader = withPropsFrom(
'shouldShowReadingModePreview',
'shouldShowTapZoneLayoutPreview',
'setSettings',
'initialChapter',
'chapterForDuplicatesHandling',
'currentChapter',
'mangaChapters',
'setReaderStateChapters',

View File

@@ -405,7 +405,8 @@ export class ReaderControls {
endReached?: boolean,
) => void {
const { currentPageIndex, setCurrentPageIndex } = userReaderStatePagesContext();
const { initialChapter, currentChapter, nextChapter, mangaChapters } = useReaderStateChaptersContext();
const { chapterForDuplicatesHandling, currentChapter, nextChapter, mangaChapters } =
useReaderStateChaptersContext();
const updateChapter = ReaderService.useUpdateChapter();
const { shouldSkipDupChapters } = ReaderService.useSettings();
const {
@@ -413,16 +414,16 @@ export class ReaderControls {
} = useMetadataServerSettings();
const nextChapters = useMemo(() => {
if (!initialChapter || !currentChapter) {
if (!chapterForDuplicatesHandling || !currentChapter) {
return [];
}
return Chapters.getNextChapters(currentChapter, mangaChapters, {
offset: DirectionOffset.NEXT,
skipDupe: shouldSkipDupChapters,
skipDupeChapter: initialChapter,
skipDupeChapter: chapterForDuplicatesHandling,
});
}, [initialChapter?.id, currentChapter?.id, mangaChapters, shouldSkipDupChapters]);
}, [chapterForDuplicatesHandling?.id, currentChapter?.id, mangaChapters, shouldSkipDupChapters]);
return useCallback(
(pageIndex, debounceChapterUpdate = true, endReached = false) => {

View File

@@ -122,23 +122,23 @@ export class ReaderService {
static useUpdateChapter(): (patch: UpdateChapterPatchInput) => void {
const { manga } = useReaderStateMangaContext();
const { initialChapter, currentChapter, mangaChapters } = useReaderStateChaptersContext();
const { chapterForDuplicatesHandling, currentChapter, mangaChapters } = useReaderStateChaptersContext();
const { shouldSkipDupChapters } = ReaderService.useSettings();
const {
settings: { deleteChaptersWhileReading, deleteChaptersWithBookmark, updateProgressAfterReading },
} = useMetadataServerSettings();
const previousChapters = useMemo(() => {
if (!initialChapter || !currentChapter) {
if (!chapterForDuplicatesHandling || !currentChapter) {
return [];
}
return Chapters.getNextChapters(currentChapter, mangaChapters, {
offset: DirectionOffset.PREVIOUS,
skipDupe: shouldSkipDupChapters,
skipDupeChapter: initialChapter,
skipDupeChapter: chapterForDuplicatesHandling,
});
}, [initialChapter?.id, currentChapter?.id, mangaChapters, shouldSkipDupChapters]);
}, [chapterForDuplicatesHandling?.id, currentChapter?.id, mangaChapters, shouldSkipDupChapters]);
return useCallback(
(patch) => {

View File

@@ -188,7 +188,7 @@ export interface ReaderStateChapters {
* - removed duplicate chapters
*/
chapters: TChapterReader[];
initialChapter?: TChapterReader | null;
chapterForDuplicatesHandling?: TChapterReader | null;
currentChapter?: TChapterReader | null;
nextChapter?: TChapterReader;
previousChapter?: TChapterReader;