Skip to content

Commit

Permalink
feat: sort continue watching by last updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Aug 20, 2024
1 parent f88cca3 commit 5cf2357
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions common/modules/anilist.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ class AnilistClient {
body: JSON.stringify({
query: query.replace(/\s/g, '').replaceAll(' ', ' '),
variables: {
sort: 'TRENDING_DESC',
page: 1,
perPage: 30,
status_in: '[CURRENT,PLANNING]',
Expand Down Expand Up @@ -550,7 +549,7 @@ class AnilistClient {
variables.id = userId
const query = /* js */`
query($id: Int) {
MediaListCollection(userId: $id, type: ANIME, forceSingleCompletedList: true) {
MediaListCollection(userId: $id, type: ANIME, forceSingleCompletedList: true, sort: UPDATED_TIME_DESC) {
lists {
status,
entries {
Expand Down
12 changes: 10 additions & 2 deletions common/modules/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function createSections () {
{
title: 'Continue Watching',
load: (page = 1, perPage = 50, variables = {}) => {
const res = anilistClient.userLists.value.then(res => {
const res = anilistClient.userLists.value.then(async res => {
const mediaList = res.data.MediaListCollection.lists.reduce((filtered, { status, entries }) => {
return (status === 'CURRENT' || status === 'REPEATING') ? filtered.concat(entries) : filtered
}, [])
Expand All @@ -93,7 +93,15 @@ function createSections () {
return media.mediaListEntry?.progress < media.nextAiringEpisode?.episode - 1
}).map(({ media }) => media.id)
if (!ids.length) return {}
return anilistClient.searchIDS({ page, perPage, id: ids, ...SectionsManager.sanitiseObject(variables) })
// if custom search is used, respect it, otherwise sort by last updated
if (Object.values(variables).length !== 0) {
return anilistClient.searchIDS({ page, perPage, id: ids, ...SectionsManager.sanitiseObject(variables) })
}

const index = (page - 1) * perPage
const idsRes = await anilistClient.searchIDS({ page, perPage, id: ids.slice(index, index + perPage), ...SectionsManager.sanitiseObject(variables) })
idsRes.data.Page.media.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id))
return idsRes
})
return SectionsManager.wrapResponse(res, perPage)
},
Expand Down

0 comments on commit 5cf2357

Please sign in to comment.