Add sort by total chapter count
This commit is contained in:
@@ -21,22 +21,26 @@ export enum GridLayout {
|
||||
}
|
||||
|
||||
export const DefaultLibraryOptions: LibraryOptions = {
|
||||
// display options
|
||||
showContinueReadingButton: false,
|
||||
showDownloadBadge: false,
|
||||
showUnreadBadge: false,
|
||||
gridLayout: GridLayout.Compact,
|
||||
SourcegridLayout: GridLayout.Compact,
|
||||
|
||||
downloaded: undefined,
|
||||
bookmarked: undefined,
|
||||
showTabSize: false,
|
||||
|
||||
// sort options
|
||||
sortDesc: undefined,
|
||||
sorts: undefined,
|
||||
|
||||
// filter options
|
||||
downloaded: undefined,
|
||||
bookmarked: undefined,
|
||||
unread: undefined,
|
||||
hasDuplicateChapters: undefined,
|
||||
tracker: {},
|
||||
status: {} as LibraryOptions['status'],
|
||||
|
||||
showTabSize: false,
|
||||
};
|
||||
|
||||
export const LibraryOptionsContext = React.createContext<ContextType>({
|
||||
|
||||
@@ -31,6 +31,7 @@ const TITLES: { [key in 'filter' | 'sort' | 'display']: TranslationKey } = {
|
||||
|
||||
const SORT_OPTIONS: [LibrarySortMode, TranslationKey][] = [
|
||||
['sortToRead', 'library.option.sort.label.by_unread_chapters'],
|
||||
['sortTotalChapters', 'library.option.sort.label.by_total_chapters'],
|
||||
['sortAlph', 'library.option.sort.label.alphabetically'],
|
||||
['sortDateAdded', 'library.option.sort.label.by_date_added'],
|
||||
['sortLastRead', 'library.option.sort.label.by_last_read'],
|
||||
|
||||
@@ -12,7 +12,7 @@ import { LibraryOptions, LibrarySortMode, NullAndUndefined } from '@/typings.ts'
|
||||
import { useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext.tsx';
|
||||
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
|
||||
import { ChapterType, MangaType, SourceType, TrackRecordType } from '@/lib/graphql/generated/graphql.ts';
|
||||
import { MangaIdInfo } from '@/lib/data/Mangas.ts';
|
||||
import { MangaChapterCountInfo, MangaIdInfo } from '@/lib/data/Mangas.ts';
|
||||
import { enhancedCleanup } from '@/lib/data/Strings.ts';
|
||||
|
||||
const triStateFilter = (
|
||||
@@ -136,11 +136,12 @@ const sortByNumber = (a: number | string = 0, b: number | string = 0) => Number(
|
||||
|
||||
const sortByString = (a: string, b: string): number => a.localeCompare(b);
|
||||
|
||||
type TMangaSort = Pick<MangaType, 'title' | 'inLibraryAt' | 'unreadCount'> & {
|
||||
lastReadChapter?: Pick<ChapterType, 'lastReadAt'> | null;
|
||||
latestUploadedChapter?: Pick<ChapterType, 'uploadDate'> | null;
|
||||
latestFetchedChapter?: Pick<ChapterType, 'fetchedAt'> | null;
|
||||
};
|
||||
type TMangaSort = Pick<MangaType, 'title' | 'inLibraryAt' | 'unreadCount'> &
|
||||
MangaChapterCountInfo & {
|
||||
lastReadChapter?: Pick<ChapterType, 'lastReadAt'> | null;
|
||||
latestUploadedChapter?: Pick<ChapterType, 'uploadDate'> | null;
|
||||
latestFetchedChapter?: Pick<ChapterType, 'fetchedAt'> | null;
|
||||
};
|
||||
const sortManga = <Manga extends TMangaSort>(
|
||||
manga: Manga[],
|
||||
sort: NullAndUndefined<LibrarySortMode>,
|
||||
@@ -169,6 +170,9 @@ const sortManga = <Manga extends TMangaSort>(
|
||||
case 'sortLatestFetchedChapter':
|
||||
result.sort((a, b) => sortByNumber(a.latestFetchedChapter?.fetchedAt, b.latestFetchedChapter?.fetchedAt));
|
||||
break;
|
||||
case 'sortTotalChapters':
|
||||
result.sort((a, b) => sortByNumber(a.chapters.totalCount, b.chapters.totalCount));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,8 @@ export type LibrarySortMode =
|
||||
| 'sortDateAdded'
|
||||
| 'sortLastRead'
|
||||
| 'sortLatestFetchedChapter'
|
||||
| 'sortLatestUploadedChapter';
|
||||
| 'sortLatestUploadedChapter'
|
||||
| 'sortTotalChapters';
|
||||
|
||||
enum GridLayout {
|
||||
Compact = 0,
|
||||
@@ -273,13 +274,15 @@ export interface LibraryOptions {
|
||||
gridLayout: GridLayout;
|
||||
SourcegridLayout: GridLayout;
|
||||
|
||||
// sort options
|
||||
sorts: NullAndUndefined<LibrarySortMode>;
|
||||
sortDesc: NullAndUndefined<boolean>;
|
||||
|
||||
// filter options
|
||||
downloaded: NullAndUndefined<boolean>;
|
||||
bookmarked: NullAndUndefined<boolean>;
|
||||
unread: NullAndUndefined<boolean>;
|
||||
hasDuplicateChapters: NullAndUndefined<boolean>;
|
||||
sorts: NullAndUndefined<LibrarySortMode>;
|
||||
sortDesc: NullAndUndefined<boolean>;
|
||||
showTabSize: boolean;
|
||||
tracker: Record<TrackerType['id'], NullAndUndefined<boolean>>;
|
||||
status: Record<MangaStatus, NullAndUndefined<boolean>>;
|
||||
|
||||
Reference in New Issue
Block a user