Allows sorting items by last used

This commit is contained in:
Alicia Sykes
2021-09-05 01:00:44 +01:00
parent 955985071f
commit 11f5f8c9df
3 changed files with 20 additions and 1 deletions

View File

@@ -75,6 +75,7 @@ export default {
sortOrder() {
return this.displayData.sortBy || defaultSortOrder;
},
/* If the sortBy attribute is specified, then return sorted data */
sortedItems() {
let { items } = this;
if (this.sortOrder === 'alphabetical') {
@@ -83,6 +84,8 @@ export default {
items.sort((a, b) => (a.title < b.title ? 1 : -1));
} else if (this.sortOrder === 'most-used') {
items = this.sortByMostUsed(items);
} else if (this.sortOrder === 'last-used') {
items = this.sortBLastUsed(items);
}
return items;
},
@@ -134,6 +137,13 @@ export default {
items.reverse().sort((a, b) => (gmu(a) < gmu(b) ? 1 : -1));
return items;
},
/* Sorts items by most recently used */
sortBLastUsed(items) {
const usageCount = JSON.parse(localStorage.getItem(localStorageKeys.LAST_USED) || '{}');
const glu = (item) => usageCount[this.makeId(item.title)] || 0;
items.reverse().sort((a, b) => (glu(a) < glu(b) ? 1 : -1));
return items;
},
},
};
</script>