Skip to content

Commit f17383a

Browse files
committed
update seach sort so sort by favourites/etc works while searching
1 parent 306adf3 commit f17383a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

js/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,22 @@ function refreshLibrary(options) {
686686
console.warn("Unknown search type "+searchType, searchValue);
687687
}
688688
// Now finally, filter, sort based on relevance and set the search result
689-
visibleApps = searchResult.filter(a => a.relevance>0).sort((a,b) => (b.relevance-(0|b.sortorder)) - (a.relevance-(0|a.sortorder))).map(a => a.app);
689+
visibleApps = searchResult.filter(a => a.relevance>0).sort((a,b) => {
690+
// sort by relevance and sort order
691+
let sort = (b.relevance-(0|b.sortorder)) - (a.relevance-(0|a.sortorder));
692+
if (sort) return sort;
693+
// if relevance is the same, sort by extraSort (eg created, modified, installs, favourites)
694+
if (["created","modified","installs","favourites"].includes(activeSort))
695+
return ((appSortInfo[b.app.id]||{})[activeSort]||0) -
696+
((appSortInfo[a.app.id]||{})[activeSort]||0);
697+
return 0;
698+
}).map(a => a.app);
690699
}
691700
// if not otherwise sorted, use 'sort by' option
692701
if (!sortedByRelevance)
693702
visibleApps.sort(appSorter);
694703

695-
if (activeSort && !searchValue) { // only sort if not searching (searching already sorts)
704+
if (activeSort && !sortedByRelevance) { // only sort if not searching (searching already sorts)
696705
if (["created","modified","installs","favourites"].includes(activeSort)) {
697706
visibleApps = visibleApps.sort((a,b) =>
698707
((appSortInfo[b.id]||{})[activeSort]||0) -

0 commit comments

Comments
 (0)