diff --git a/src/features/chapter/Chapter.types.ts b/src/features/chapter/Chapter.types.ts index 5b409317..e991a11a 100644 --- a/src/features/chapter/Chapter.types.ts +++ b/src/features/chapter/Chapter.types.ts @@ -11,14 +11,22 @@ import type { ChapterReaderFieldsFragment, DownloadStatusFieldsFragment } from ' export type ChapterSortMode = 'fetchedAt' | 'source' | 'chapterNumber' | 'uploadedAt'; -export interface ChapterListOptions { +export interface ChapterListFilterOptions { unread: NullAndUndefined; downloaded: NullAndUndefined; bookmarked: NullAndUndefined; + excludedScanlators: string[]; +} + +export interface ChapterListSortOptions { reverse: boolean; sortBy: ChapterSortMode; +} + +export interface ChapterListFilterSortOptions extends ChapterListFilterOptions, ChapterListSortOptions {} + +export interface ChapterListOptions extends ChapterListFilterSortOptions { showChapterNumber: boolean; - excludedScanlators: string[]; } export type TChapterReader = ChapterReaderFieldsFragment; diff --git a/src/features/chapter/utils/ChapterList.util.tsx b/src/features/chapter/utils/ChapterList.util.tsx index 98a63031..91180ca1 100644 --- a/src/features/chapter/utils/ChapterList.util.tsx +++ b/src/features/chapter/utils/ChapterList.util.tsx @@ -11,7 +11,10 @@ import type { ChapterType } from '@/lib/graphql/generated/graphql-base.types.ts' import type { ChapterBookmarkInfo, ChapterDownloadInfo, + ChapterListFilterOptions, + ChapterListFilterSortOptions, ChapterListOptions, + ChapterListSortOptions, ChapterNumberInfo, ChapterReadInfo, ChapterScanlatorInfo, @@ -63,10 +66,7 @@ function scanlatorFilter(excludedScanlators: string[], { scanlator }: ChapterSca } type TChapterSort = ChapterSourceOrderInfo & ChapterNumberInfo & Pick; -const sortChapters = ( - chapters: T[], - { sortBy, reverse }: Pick, -): T[] => { +const sortChapters = (chapters: T[], { sortBy, reverse }: ChapterListSortOptions): T[] => { const sortedChapters: T[] = [...chapters]; switch (sortBy) { @@ -96,7 +96,7 @@ const sortChapters = ( type TChapterFilter = ChapterReadInfo & ChapterDownloadInfo & ChapterBookmarkInfo & ChapterScanlatorInfo; export function filterChapters( chapters: Chapters[], - options: ChapterListOptions, + options: ChapterListFilterOptions, ): Chapters[] { return chapters.filter( (chp) => @@ -109,14 +109,14 @@ export function filterChapters( export function filterAndSortChapters( chapters: Chapters[], - options: ChapterListOptions, + options: ChapterListFilterSortOptions, ): Chapters[] { const filtered = filterChapters(chapters, options); return sortChapters(filtered, options); } -export const isFilterActive = (options: ChapterListOptions) => { +export const isFilterActive = (options: ChapterListFilterOptions) => { const { unread, downloaded, bookmarked, excludedScanlators } = options; return unread != null || downloaded != null || bookmarked != null || !!excludedScanlators.length; }; diff --git a/src/features/reader/hooks/useReaderSetChaptersState.ts b/src/features/reader/hooks/useReaderSetChaptersState.ts index 6dd8fd65..a1e585c6 100644 --- a/src/features/reader/hooks/useReaderSetChaptersState.ts +++ b/src/features/reader/hooks/useReaderSetChaptersState.ts @@ -17,7 +17,7 @@ import type { ReaderStateChapters, } from '@/features/reader/Reader.types.ts'; import { filterChapters } from '@/features/chapter/utils/ChapterList.util.tsx'; -import type { ChapterListOptions } from '@/features/chapter/Chapter.types.ts'; +import type { ChapterListFilterOptions } from '@/features/chapter/Chapter.types.ts'; import { getReaderChapterFromCache } from '@/features/reader/Reader.utils.ts'; import { DirectionOffset } from '@/base/Base.types.ts'; import { getReaderChaptersStore } from '@/features/reader/stores/ReaderStore.ts'; @@ -33,7 +33,7 @@ export const useReaderSetChaptersState = ( chapterForDuplicatesHandling: ReaderStateChapters['chapterForDuplicatesHandling'], shouldSkipDupChapters: IReaderSettings['shouldSkipDupChapters'], shouldSkipFilteredChapters: IReaderSettings['shouldSkipFilteredChapters'], - chapterListOptions: ChapterListOptions, + chapterListOptions: ChapterListFilterOptions, ) => { const navigate = useNavigate(); const locationState = useLocation().state;