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!

✨ Allows for sub-item and section search

Alicia Sykesb617589d4c04
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index 1ce2fad0..12e2fa91 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -17,7 +17,8 @@
"search-placeholder": "Start typing to filter",
"clear-search-tooltip": "Clear Search",
"enter-to-search-web": "Press enter to search the web",
- "enter-to-open-url": "Press enter to open URL"
+ "enter-to-open-url": "Press enter to open URL",
+ "enter-to-launch-first": "Press enter to launch first match"
},
"splash-screen": {
"loading": "Loading"
diff --git a/src/components/Settings/SearchBar.vue b/src/components/Settings/SearchBar.vue
index e96af739..4cddd443 100644
--- a/src/components/Settings/SearchBar.vue
+++ b/src/components/Settings/SearchBar.vue
@@ -64,8 +64,8 @@ export default {
},
searchNote() {
if (this.urlDetected) return this.$t('search.enter-to-open-url');
- if (!this.searchPrefs.disableWebSearch) return this.$t('search.enter-to-search-web');
- return '';
+ if (this.searchPrefs.disableWebSearch) return this.$t('search.enter-to-launch-first');
+ return this.$t('search.enter-to-search-web');
},
},
mounted() {
@@ -205,7 +205,7 @@ export default {
form.normal {
display: flex;
- align-items: center;
+ align-items: baseline;
border-radius: 0 0 var(--curve-factor-navbar) 0;
padding: 0 0.2rem 0.2rem 0;
background: var(--search-container-background);
diff --git a/src/mixins/HomeMixin.js b/src/mixins/HomeMixin.js
index 969d2eeb..09ea0115 100644
--- a/src/mixins/HomeMixin.js
+++ b/src/mixins/HomeMixin.js
@@ -88,14 +88,14 @@ const HomeMixin = {
return (sections && sections.length >= 1) || (localSections && localSections.length >= 1);
},
/* Returns only the tiles that match the users search query */
- filterTiles(allTiles) {
+ filterTiles(allTiles, sectionName) {
if (!allTiles) return [];
const currentUser = getCurrentUser();
const isGuest = isLoggedInAsGuest();
const visibleTiles = allTiles.filter(
(tile) => isVisibleToUser(tile.displayData || {}, currentUser, isGuest),
);
- return searchTiles(visibleTiles, this.searchValue);
+ return searchTiles(visibleTiles, this.searchValue, sectionName || '');
},
/* Checks if any sections or items use icons from a given CDN */
checkIfIconLibraryNeeded(prefix) {
diff --git a/src/utils/Search.js b/src/utils/Search.js
index 5317571f..e3feabb7 100644
--- a/src/utils/Search.js
+++ b/src/utils/Search.js
@@ -12,10 +12,13 @@ const haystackCache = new WeakMap();
const buildHaystack = (tile) => {
const {
- title, description, provider, url, tags,
+ title, description, provider, url, tags, subItems,
} = tile;
const tagsStr = Array.isArray(tags) ? tags.join(' ') : (tags || '');
- return normalize(`${title || ''} ${provider || ''} ${description || ''} ${tagsStr} ${url || ''}`);
+ const subText = Array.isArray(subItems)
+ ? subItems.map((s) => `${s.title || ''} ${s.url || ''}`).join(' ')
+ : '';
+ return normalize(`${title || ''} ${provider || ''} ${description || ''} ${tagsStr} ${url || ''} ${subText}`);
};
const getHaystack = (tile) => {
@@ -35,14 +38,15 @@ const getHaystack = (tile) => {
* @param {string} searchTerm The users search term
* @returns A filtered array of tiles
*/
-export const searchTiles = (allTiles, searchTerm) => {
+export const searchTiles = (allTiles, searchTerm, extraHaystack = '') => {
if (!searchTerm) return allTiles;
if (!allTiles) return [];
const words = normalize(searchTerm).split(/\s+/).filter(Boolean);
if (!words.length) return allTiles;
+ const extra = normalize(extraHaystack);
return allTiles.filter((tile) => {
const haystack = getHaystack(tile);
- return words.every((word) => haystack.includes(word));
+ return words.every((word) => haystack.includes(word) || extra.includes(word));
});
};
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 0d730cd9..7133ef74 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -112,7 +112,7 @@ export default {
const sections = this.singleSectionView || this.sections;
return sections.map((section) => ({
...section,
- filteredItems: this.filterTiles(section.items),
+ filteredItems: this.filterTiles(section.items, section.name),
}));
},
/* Updates layout (when button clicked), and saves in local storage */
diff --git a/src/views/Minimal.vue b/src/views/Minimal.vue
index 74d03d36..46b8364c 100644
--- a/src/views/Minimal.vue
+++ b/src/views/Minimal.vue
@@ -105,7 +105,7 @@ export default {
filteredSections() {
return (this.sections || []).map((section) => ({
...section,
- filteredItems: this.filterTiles(section.items),
+ filteredItems: this.filterTiles(section.items, section.name),
}));
},
},