Split up chapter list options type
This commit is contained in:
@@ -11,14 +11,22 @@ import type { ChapterReaderFieldsFragment, DownloadStatusFieldsFragment } from '
|
||||
|
||||
export type ChapterSortMode = 'fetchedAt' | 'source' | 'chapterNumber' | 'uploadedAt';
|
||||
|
||||
export interface ChapterListOptions {
|
||||
export interface ChapterListFilterOptions {
|
||||
unread: NullAndUndefined<boolean>;
|
||||
downloaded: NullAndUndefined<boolean>;
|
||||
bookmarked: NullAndUndefined<boolean>;
|
||||
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;
|
||||
|
||||
@@ -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<ChapterType, 'fetchedAt' | 'uploadDate'>;
|
||||
const sortChapters = <T extends TChapterSort>(
|
||||
chapters: T[],
|
||||
{ sortBy, reverse }: Pick<ChapterListOptions, 'sortBy' | 'reverse'>,
|
||||
): T[] => {
|
||||
const sortChapters = <T extends TChapterSort>(chapters: T[], { sortBy, reverse }: ChapterListSortOptions): T[] => {
|
||||
const sortedChapters: T[] = [...chapters];
|
||||
|
||||
switch (sortBy) {
|
||||
@@ -96,7 +96,7 @@ const sortChapters = <T extends TChapterSort>(
|
||||
type TChapterFilter = ChapterReadInfo & ChapterDownloadInfo & ChapterBookmarkInfo & ChapterScanlatorInfo;
|
||||
export function filterChapters<Chapters extends TChapterFilter>(
|
||||
chapters: Chapters[],
|
||||
options: ChapterListOptions,
|
||||
options: ChapterListFilterOptions,
|
||||
): Chapters[] {
|
||||
return chapters.filter(
|
||||
(chp) =>
|
||||
@@ -109,14 +109,14 @@ export function filterChapters<Chapters extends TChapterFilter>(
|
||||
|
||||
export function filterAndSortChapters<Chapters extends TChapterSort & TChapterFilter>(
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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<ReaderOpenChapterLocationState>().state;
|
||||
|
||||
Reference in New Issue
Block a user