Skip to content

Commit

Permalink
Merge pull request #247 from Suwayomi/main
Browse files Browse the repository at this point in the history
fix sorting
  • Loading branch information
Robonau authored Dec 8, 2024
2 parents 5c5a35e + e2f5535 commit 9721a88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/lib/simpleStores.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ export enum Layout {
Edge = 'Edge'
}

export enum sort {
Unread = 'Unread',
Alphabetical = 'Alphabetical',
ID = 'ID',
Added = 'Latest Added',
Read = 'Latest Read',
Fetched = 'Latest Fetched',
Uploaded = 'Latest Uploaded',
Random = 'Random'
}
export const sort = {
Unread: 'Unread',
Alphabetical: 'Alphabetical',
ID: 'ID',
Added: 'Latest Added',
Read: 'Latest Read',
Fetched: 'Latest Fetched',
Uploaded: 'Latest Uploaded',
Random: 'Random'
} as const;

export enum display {
Compact = 'Compact',
Expand Down Expand Up @@ -103,7 +103,7 @@ const trueDefaults = {
theme: 'skeleton' as Themes,
dark: true,
Display: display.Compact,
Sort: sort.ID,
Sort: 'ID' as keyof typeof sort,
Asc: true,
Unread: 'intermediate' as TriState,
Downloaded: 'intermediate' as TriState,
Expand Down
18 changes: 9 additions & 9 deletions src/routes/(app)/(library)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import IntersectionObserver from '$lib/components/IntersectionObserver.svelte';
import MangaCard from '$lib/components/MangaCard.svelte';
import { longPress } from '$lib/press';
import { display, gmState, sort } from '$lib/simpleStores.svelte';
import { display, gmState } from '$lib/simpleStores.svelte';
import { Tab, TabGroup } from '@skeletonlabs/skeleton';
import { queryParam, ssp } from 'sveltekit-search-params';
import LibraryActions from './libraryActions.svelte';
Expand Down Expand Up @@ -311,36 +311,36 @@
});
let sortedMangas = $derived(
filteredMangas
? gmState.value.Sort === sort.Random
? gmState.value.Sort === 'Random'
? shuffle([...filteredMangas])
: [...filteredMangas].sort((a, b) => {
let tru = true;
switch (gmState.value.Sort) {
case sort.ID:
case 'ID':
tru = a.id > b.id;
break;
case sort.Unread:
case 'Unread':
tru = a.unreadCount > b.unreadCount;
break;
case sort.Alphabetical:
case 'Alphabetical':
tru = a.title > b.title;
break;
case sort.Read:
case 'Read':
tru =
parseInt(a.lastReadChapter?.lastReadAt ?? '0') >
parseInt(b.lastReadChapter?.lastReadAt ?? '0');
break;
case sort.Fetched:
case 'Fetched':
tru =
parseInt(a.latestFetchedChapter?.fetchedAt ?? '0') >
parseInt(b.latestFetchedChapter?.fetchedAt ?? '0');
break;
case sort.Uploaded:
case 'Uploaded':
tru =
parseInt(a.latestUploadedChapter?.uploadDate ?? '0') >
parseInt(b.latestUploadedChapter?.uploadDate ?? '0');
break;
case sort.Added:
case 'Added':
tru =
parseInt(a.inLibraryAt ?? '0') >
parseInt(b.inLibraryAt ?? '0');
Expand Down

0 comments on commit 9721a88

Please sign in to comment.