Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

:sparkles: Allows sorting items by last used

Alicia Sykes11f5f8c9df9e
diff --git a/src/components/LinkItems/Item.vue b/src/components/LinkItems/Item.vue
index fc47ed76..8249815a 100644
--- a/src/components/LinkItems/Item.vue
+++ b/src/components/LinkItems/Item.vue
@@ -107,7 +107,9 @@ export default {
} else {
this.$emit('itemClicked');
}
+ // Update the most/ last used ledger, for smart-sorting
this.incrementMostUsedCount(this.id);
+ this.incrementLastUsedCount(this.id);
},
/* Open custom context menu, and set position */
openContextMenu(e) {
@@ -200,7 +202,7 @@ export default {
default: window.open(url, '_blank');
}
},
- /* Used for smart-sort when sorting items by most/ last used */
+ /* Used for smart-sort when sorting items by most used apps */
incrementMostUsedCount(itemId) {
const mostUsed = JSON.parse(localStorage.getItem(localStorageKeys.MOST_USED) || '{}');
let counter = mostUsed[itemId] || 0;
@@ -208,6 +210,12 @@ export default {
mostUsed[itemId] = counter;
localStorage.setItem(localStorageKeys.MOST_USED, JSON.stringify(mostUsed));
},
+ /* Used for smart-sort when sorting by last used apps */
+ incrementLastUsedCount(itemId) {
+ const lastUsed = JSON.parse(localStorage.getItem(localStorageKeys.LAST_USED) || '{}');
+ lastUsed[itemId] = new Date().getTime();
+ localStorage.setItem(localStorageKeys.LAST_USED, JSON.stringify(lastUsed));
+ },
},
mounted() {
// If ststus checking is enabled, then check service status
diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue
index a1429d90..c9977b6e 100644
--- a/src/components/LinkItems/Section.vue
+++ b/src/components/LinkItems/Section.vue
@@ -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>
diff --git a/src/utils/defaults.js b/src/utils/defaults.js
index b6e37233..5f169696 100644
--- a/src/utils/defaults.js
+++ b/src/utils/defaults.js
@@ -94,6 +94,7 @@ module.exports = {
HIDE_SETTINGS: 'hideSettings',
USERNAME: 'username',
MOST_USED: 'mostUsed',
+ LAST_USED: 'lastUsed',
},
/* Key names for cookie identifiers */
cookieKeys: {