diff --git a/pages/[subdomain]/collection/[username]/[slugName].tsx b/pages/[subdomain]/collection/[username]/[slugName].tsx index afea7820e..7acd4ff97 100644 --- a/pages/[subdomain]/collection/[username]/[slugName].tsx +++ b/pages/[subdomain]/collection/[username]/[slugName].tsx @@ -95,7 +95,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { search: search ? search.toString() : '', statFilter: statFilter ? statFilter.toString() as StatFilter : StatFilter.All, timeRange: TimeRange[TimeRange.All], - sortBy: 'sortField', + sortBy: 'collectionOrder', sortDir: 'asc', // TODO: when filtering, the original collection order is not maintained and instead we sort here // maybe need a separate doCollectionQuery function diff --git a/pages/api/search/index.ts b/pages/api/search/index.ts index 8e53f7f85..df1533b62 100644 --- a/pages/api/search/index.ts +++ b/pages/api/search/index.ts @@ -226,8 +226,8 @@ export async function doQuery(gameId: GameId, query: SearchQuery, reqUser?: User lookupUserBeforeSort = true; } else if (query.sortBy === 'name') { sortObj.push(['name', sortDirection]); - } else if (query.sortBy === 'sortField') { - sortObj.push(['sortField', sortDirection]); + } else if (query.sortBy === 'collectionOrder') { + sortObj.push(['collectionOrder', sortDirection]); } else if (query.sortBy === 'leastMoves') { sortObj.push(['leastMoves', sortDirection]); } else if (query.sortBy === 'ts') { @@ -433,7 +433,7 @@ export async function doQuery(gameId: GameId, query: SearchQuery, reqUser?: User { $project: { ...projection } }, { $addFields: { - sortField: { + collectionOrder: { $indexOfArray: [query.includeLevelIds?.split(','), { $toString: '$_id' }], } }