From ecca993c54990ab55031ea2266a53983dc395e74 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 24 May 2025 21:27:28 +0200 Subject: [PATCH] Simplify chapter util types --- src/modules/chapter/Chapter.types.ts | 12 ++++++------ src/modules/chapter/services/Chapters.ts | 18 +++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/modules/chapter/Chapter.types.ts b/src/modules/chapter/Chapter.types.ts index 5735874b..6f6f58c7 100644 --- a/src/modules/chapter/Chapter.types.ts +++ b/src/modules/chapter/Chapter.types.ts @@ -34,16 +34,16 @@ export type ChapterIdInfo = Pick; export type ChapterMangaInfo = Pick; -export type ChapterDownloadInfo = ChapterIdInfo & Pick; +export type ChapterDownloadInfo = Pick; -export type ChapterBookmarkInfo = ChapterIdInfo & Pick; +export type ChapterBookmarkInfo = Pick; -export type ChapterReadInfo = ChapterIdInfo & Pick; +export type ChapterReadInfo = Pick; -export type ChapterNumberInfo = ChapterIdInfo & Pick; +export type ChapterNumberInfo = Pick; -export type ChapterSourceOrderInfo = ChapterIdInfo & Pick; +export type ChapterSourceOrderInfo = Pick; -export type ChapterScanlatorInfo = ChapterIdInfo & Pick; +export type ChapterScanlatorInfo = Pick; export type ChapterRealUrlInfo = Pick; diff --git a/src/modules/chapter/services/Chapters.ts b/src/modules/chapter/services/Chapters.ts index f24aaf8f..3e11d0a2 100644 --- a/src/modules/chapter/services/Chapters.ts +++ b/src/modules/chapter/services/Chapters.ts @@ -31,6 +31,7 @@ import { ChapterAction, ChapterBookmarkInfo, ChapterDownloadInfo, + ChapterIdInfo, ChapterMangaInfo, ChapterNumberInfo, ChapterReadInfo, @@ -118,12 +119,12 @@ export class Chapters { return chapters.filter(Chapters.isDownloaded); } - static isDownloadable(chapter: Chapter): boolean { + static isDownloadable(chapter: Chapter): boolean { const downloadStatus = Chapters.getDownloadStatusFromCache(chapter.id); return !Chapters.isDownloaded(chapter) && (!downloadStatus || downloadStatus.state === DownloadState.Error); } - static getDownloadable(chapters: Chapter[]): Chapter[] { + static getDownloadable(chapters: Chapter[]): Chapter[] { return chapters.filter(this.isDownloadable); } @@ -199,7 +200,7 @@ export class Chapters { } static async markAsRead( - chapters: (ChapterDownloadInfo & ChapterBookmarkInfo)[], + chapters: (ChapterIdInfo & ChapterDownloadInfo & ChapterBookmarkInfo)[], wasManuallyMarkedAsRead: boolean = false, trackProgressMangaId?: MangaIdInfo['id'], ): Promise { @@ -276,7 +277,7 @@ export class Chapters { ? { wasManuallyMarkedAsRead: boolean; trackProgressMangaId?: MangaIdInfo['id']; - chapters: (ChapterDownloadInfo & ChapterBookmarkInfo & ChapterReadInfo)[]; + chapters: (ChapterIdInfo & ChapterDownloadInfo & ChapterBookmarkInfo & ChapterReadInfo)[]; } : { wasManuallyMarkedAsRead?: never; @@ -316,7 +317,10 @@ export class Chapters { .flat(); } - static removeDuplicates(currentChapter: T, chapters: T[]): T[] { + static removeDuplicates( + currentChapter: T, + chapters: T[], + ): T[] { const chapterNumberToChapters = Object.groupBy(chapters, ({ chapterNumber }) => chapterNumber); const uniqueChapters = Object.values(chapterNumberToChapters).map( @@ -333,7 +337,7 @@ export class Chapters { .filter((chapter): chapter is T => !!chapter); } - static getNextChapter( + static getNextChapter( currentChapter: Chapter, chapters: Chapter[], { @@ -350,7 +354,7 @@ export class Chapters { return nextChapters.slice(sliceStartIndex, sliceEndIndex)[0]; } - static getNextChapters( + static getNextChapters( fromChapter: Chapter, chapters: Chapter[], {