Add sort by total chapter count
This commit is contained in:
@@ -514,6 +514,7 @@
|
|||||||
"by_last_read": "Recently read",
|
"by_last_read": "Recently read",
|
||||||
"by_latest_fetched_chapter": "Latest fetched chapter",
|
"by_latest_fetched_chapter": "Latest fetched chapter",
|
||||||
"by_latest_uploaded_chapter": "Latest uploaded chapter",
|
"by_latest_uploaded_chapter": "Latest uploaded chapter",
|
||||||
|
"by_total_chapters": "Total chapters",
|
||||||
"by_unread_chapters": "Unread chapters"
|
"by_unread_chapters": "Unread chapters"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -707,10 +708,10 @@
|
|||||||
"status": {
|
"status": {
|
||||||
"cancelled": "Cancelled",
|
"cancelled": "Cancelled",
|
||||||
"completed": "Completed",
|
"completed": "Completed",
|
||||||
"publishing_finished": "Publishing finished",
|
|
||||||
"hiatus": "Hiatus",
|
"hiatus": "Hiatus",
|
||||||
"licensed": "Licensed",
|
"licensed": "Licensed",
|
||||||
"ongoing": "Ongoing",
|
"ongoing": "Ongoing",
|
||||||
|
"publishing_finished": "Publishing finished",
|
||||||
"unknown": "$t(global.label.unknown)"
|
"unknown": "$t(global.label.unknown)"
|
||||||
},
|
},
|
||||||
"title_one": "Manga",
|
"title_one": "Manga",
|
||||||
|
|||||||
@@ -21,22 +21,26 @@ export enum GridLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DefaultLibraryOptions: LibraryOptions = {
|
export const DefaultLibraryOptions: LibraryOptions = {
|
||||||
|
// display options
|
||||||
showContinueReadingButton: false,
|
showContinueReadingButton: false,
|
||||||
showDownloadBadge: false,
|
showDownloadBadge: false,
|
||||||
showUnreadBadge: false,
|
showUnreadBadge: false,
|
||||||
gridLayout: GridLayout.Compact,
|
gridLayout: GridLayout.Compact,
|
||||||
SourcegridLayout: GridLayout.Compact,
|
SourcegridLayout: GridLayout.Compact,
|
||||||
|
|
||||||
downloaded: undefined,
|
showTabSize: false,
|
||||||
bookmarked: undefined,
|
|
||||||
|
// sort options
|
||||||
sortDesc: undefined,
|
sortDesc: undefined,
|
||||||
sorts: undefined,
|
sorts: undefined,
|
||||||
|
|
||||||
|
// filter options
|
||||||
|
downloaded: undefined,
|
||||||
|
bookmarked: undefined,
|
||||||
unread: undefined,
|
unread: undefined,
|
||||||
hasDuplicateChapters: undefined,
|
hasDuplicateChapters: undefined,
|
||||||
tracker: {},
|
tracker: {},
|
||||||
status: {} as LibraryOptions['status'],
|
status: {} as LibraryOptions['status'],
|
||||||
|
|
||||||
showTabSize: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LibraryOptionsContext = React.createContext<ContextType>({
|
export const LibraryOptionsContext = React.createContext<ContextType>({
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const TITLES: { [key in 'filter' | 'sort' | 'display']: TranslationKey } = {
|
|||||||
|
|
||||||
const SORT_OPTIONS: [LibrarySortMode, TranslationKey][] = [
|
const SORT_OPTIONS: [LibrarySortMode, TranslationKey][] = [
|
||||||
['sortToRead', 'library.option.sort.label.by_unread_chapters'],
|
['sortToRead', 'library.option.sort.label.by_unread_chapters'],
|
||||||
|
['sortTotalChapters', 'library.option.sort.label.by_total_chapters'],
|
||||||
['sortAlph', 'library.option.sort.label.alphabetically'],
|
['sortAlph', 'library.option.sort.label.alphabetically'],
|
||||||
['sortDateAdded', 'library.option.sort.label.by_date_added'],
|
['sortDateAdded', 'library.option.sort.label.by_date_added'],
|
||||||
['sortLastRead', 'library.option.sort.label.by_last_read'],
|
['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 { useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext.tsx';
|
||||||
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
|
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
|
||||||
import { ChapterType, MangaType, SourceType, TrackRecordType } from '@/lib/graphql/generated/graphql.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';
|
import { enhancedCleanup } from '@/lib/data/Strings.ts';
|
||||||
|
|
||||||
const triStateFilter = (
|
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);
|
const sortByString = (a: string, b: string): number => a.localeCompare(b);
|
||||||
|
|
||||||
type TMangaSort = Pick<MangaType, 'title' | 'inLibraryAt' | 'unreadCount'> & {
|
type TMangaSort = Pick<MangaType, 'title' | 'inLibraryAt' | 'unreadCount'> &
|
||||||
|
MangaChapterCountInfo & {
|
||||||
lastReadChapter?: Pick<ChapterType, 'lastReadAt'> | null;
|
lastReadChapter?: Pick<ChapterType, 'lastReadAt'> | null;
|
||||||
latestUploadedChapter?: Pick<ChapterType, 'uploadDate'> | null;
|
latestUploadedChapter?: Pick<ChapterType, 'uploadDate'> | null;
|
||||||
latestFetchedChapter?: Pick<ChapterType, 'fetchedAt'> | null;
|
latestFetchedChapter?: Pick<ChapterType, 'fetchedAt'> | null;
|
||||||
};
|
};
|
||||||
const sortManga = <Manga extends TMangaSort>(
|
const sortManga = <Manga extends TMangaSort>(
|
||||||
manga: Manga[],
|
manga: Manga[],
|
||||||
sort: NullAndUndefined<LibrarySortMode>,
|
sort: NullAndUndefined<LibrarySortMode>,
|
||||||
@@ -169,6 +170,9 @@ const sortManga = <Manga extends TMangaSort>(
|
|||||||
case 'sortLatestFetchedChapter':
|
case 'sortLatestFetchedChapter':
|
||||||
result.sort((a, b) => sortByNumber(a.latestFetchedChapter?.fetchedAt, b.latestFetchedChapter?.fetchedAt));
|
result.sort((a, b) => sortByNumber(a.latestFetchedChapter?.fetchedAt, b.latestFetchedChapter?.fetchedAt));
|
||||||
break;
|
break;
|
||||||
|
case 'sortTotalChapters':
|
||||||
|
result.sort((a, b) => sortByNumber(a.chapters.totalCount, b.chapters.totalCount));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,7 +257,8 @@ export type LibrarySortMode =
|
|||||||
| 'sortDateAdded'
|
| 'sortDateAdded'
|
||||||
| 'sortLastRead'
|
| 'sortLastRead'
|
||||||
| 'sortLatestFetchedChapter'
|
| 'sortLatestFetchedChapter'
|
||||||
| 'sortLatestUploadedChapter';
|
| 'sortLatestUploadedChapter'
|
||||||
|
| 'sortTotalChapters';
|
||||||
|
|
||||||
enum GridLayout {
|
enum GridLayout {
|
||||||
Compact = 0,
|
Compact = 0,
|
||||||
@@ -273,13 +274,15 @@ export interface LibraryOptions {
|
|||||||
gridLayout: GridLayout;
|
gridLayout: GridLayout;
|
||||||
SourcegridLayout: GridLayout;
|
SourcegridLayout: GridLayout;
|
||||||
|
|
||||||
|
// sort options
|
||||||
|
sorts: NullAndUndefined<LibrarySortMode>;
|
||||||
|
sortDesc: NullAndUndefined<boolean>;
|
||||||
|
|
||||||
// filter options
|
// filter options
|
||||||
downloaded: NullAndUndefined<boolean>;
|
downloaded: NullAndUndefined<boolean>;
|
||||||
bookmarked: NullAndUndefined<boolean>;
|
bookmarked: NullAndUndefined<boolean>;
|
||||||
unread: NullAndUndefined<boolean>;
|
unread: NullAndUndefined<boolean>;
|
||||||
hasDuplicateChapters: NullAndUndefined<boolean>;
|
hasDuplicateChapters: NullAndUndefined<boolean>;
|
||||||
sorts: NullAndUndefined<LibrarySortMode>;
|
|
||||||
sortDesc: NullAndUndefined<boolean>;
|
|
||||||
showTabSize: boolean;
|
showTabSize: boolean;
|
||||||
tracker: Record<TrackerType['id'], NullAndUndefined<boolean>>;
|
tracker: Record<TrackerType['id'], NullAndUndefined<boolean>>;
|
||||||
status: Record<MangaStatus, NullAndUndefined<boolean>>;
|
status: Record<MangaStatus, NullAndUndefined<boolean>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user