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

View File

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

View File

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

View File

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

View File

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