Skip to content

Commit

Permalink
Merge pull request #217 from Suwayomi/main
Browse files Browse the repository at this point in the history
sort library by random
  • Loading branch information
Robonau authored Aug 11, 2024
2 parents 5e75ed0 + b7f5a7c commit 6b88c41
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/lib/simpleStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export enum sort {
ID = 'ID',
'Latest Read' = 'Latest Read',
'Latest Fetched' = 'Latest Fetched',
'Latest Uploaded' = 'Latest Uploaded'
'Latest Uploaded' = 'Latest Uploaded',
Random = 'Random'
}

export enum display {
Expand Down
79 changes: 49 additions & 30 deletions src/routes/(app)/(library)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,57 @@
return true;
});
function shuffle<T>(array: T[]) {
var tmp,
current,
top = array.length;
if (top)
while (--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
$: sortedMangas = filteredMangas
? [...filteredMangas].sort((a, b) => {
let tru = true;
switch ($Meta.Sort) {
case sort.ID:
tru = a.id > b.id;
break;
case sort.Unread:
tru = a.unreadCount > b.unreadCount;
break;
case sort.Alphabetical:
tru = a.title > b.title;
break;
case sort['Latest Read']:
tru =
parseInt(a.lastReadChapter?.lastReadAt ?? '0') >
parseInt(b.lastReadChapter?.lastReadAt ?? '0');
break;
case sort['Latest Fetched']:
tru =
parseInt(a.latestFetchedChapter?.fetchedAt ?? '0') >
parseInt(b.latestFetchedChapter?.fetchedAt ?? '0');
break;
case sort['Latest Uploaded']:
tru =
parseInt(a.latestUploadedChapter?.uploadDate ?? '0') >
parseInt(b.latestUploadedChapter?.uploadDate ?? '0');
}
? $Meta.Sort === sort.Random
? shuffle([...filteredMangas])
: [...filteredMangas].sort((a, b) => {
let tru = true;
switch ($Meta.Sort) {
case sort.ID:
tru = a.id > b.id;
break;
case sort.Unread:
tru = a.unreadCount > b.unreadCount;
break;
case sort.Alphabetical:
tru = a.title > b.title;
break;
case sort['Latest Read']:
tru =
parseInt(a.lastReadChapter?.lastReadAt ?? '0') >
parseInt(b.lastReadChapter?.lastReadAt ?? '0');
break;
case sort['Latest Fetched']:
tru =
parseInt(a.latestFetchedChapter?.fetchedAt ?? '0') >
parseInt(b.latestFetchedChapter?.fetchedAt ?? '0');
break;
case sort['Latest Uploaded']:
tru =
parseInt(a.latestUploadedChapter?.uploadDate ?? '0') >
parseInt(b.latestUploadedChapter?.uploadDate ?? '0');
break;
}
if ($Meta.Asc) tru = !tru;
return tru ? -1 : 1;
})
if ($Meta.Asc) tru = !tru;
return tru ? -1 : 1;
})
: undefined;
function selectAll() {
Expand Down
2 changes: 1 addition & 1 deletion versionToServerVersionMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
"tag": "v1.1.0",
"uiVersion": "r1101",
"uiVersion": "r1104",
"serverVersion": "r1502",
"comment": "the server version is between 1.0.0 and 1.1.0 release",
"comment2": "because its the preview version that implemented the breaking changes"
Expand Down

0 comments on commit 6b88c41

Please sign in to comment.