Skip to content

Commit 466d99f

Browse files
authored
🔀 Merge pull request #1353 from deneor/issue_1145
Optimized search
2 parents 8a821c2 + e888adb commit 466d99f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/mixins/HomeMixin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ const HomeMixin = {
135135
}
136136
},
137137
/* Returns true if there is more than 1 sub-result visible during searching */
138-
checkIfResults() {
139-
if (!this.sections) return false;
138+
checkIfResults(sections) {
139+
if (!sections) return false;
140140
else {
141141
let itemsFound = true;
142-
this.sections.forEach((section) => {
142+
sections.forEach((section) => {
143143
if (section.widgets && section.widgets.length > 0) itemsFound = false;
144-
if (this.filterTiles(section.items, this.searchValue).length > 0) itemsFound = false;
144+
if (section.filteredItems.length > 0) itemsFound = false;
145145
});
146146
return itemsFound;
147147
}

src/views/Home.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,29 @@
2727
+ (singleSectionView ? 'single-section-view ' : '')
2828
+ (this.colCount ? `col-count-${this.colCount} ` : '')"
2929
>
30-
<template v-for="(section, index) in filteredTiles">
30+
<template v-for="(section, index) in filteredSections">
3131
<Section
3232
:key="index"
3333
:index="index"
3434
:title="section.name"
3535
:icon="section.icon || undefined"
3636
:displayData="getDisplayData(section)"
3737
:groupId="`${pageId}-section-${index}`"
38-
:items="filterTiles(section.items, searchValue)"
38+
:items="section.filteredItems"
3939
:widgets="section.widgets"
4040
:searchTerm="searchValue"
4141
:itemSize="itemSizeBound"
4242
@itemClicked="finishedSearching()"
4343
@change-modal-visibility="updateModalVisibility"
4444
:isWide="!!singleSectionView || layoutOrientation === 'horizontal'"
45-
:class="
46-
(searchValue && filterTiles(section.items, searchValue).length === 0) ? 'no-results' : ''"
45+
:class="(searchValue && section.filteredItems.length === 0) ? 'no-results' : ''"
4746
/>
4847
</template>
4948
<!-- Show add new section button, in edit mode -->
5049
<AddNewSection v-if="isEditMode && !singleSectionView" />
5150
</div>
5251
<!-- Show message when there's no data to show -->
53-
<div v-if="checkIfResults() && !isEditMode" class="no-data">
52+
<div v-if="checkIfResults(filteredSections) && !isEditMode" class="no-data">
5453
{{searchValue ? $t('home.no-results') : $t('home.no-data')}}
5554
</div>
5655
<!-- Show banner at bottom of screen, for Saving config changes -->
@@ -100,10 +99,14 @@ export default {
10099
if (colCount > 8) colCount = 8;
101100
return colCount;
102101
},
103-
/* Return all sections, that match users search term */
104-
filteredTiles() {
102+
/* Return sections with filtered items, that match users search term */
103+
filteredSections() {
105104
const sections = this.singleSectionView || this.sections;
106-
return sections.filter((section) => this.filterTiles(section.items, this.searchValue));
105+
return sections.map((_section) => {
106+
const section = _section;
107+
section.filteredItems = this.filterTiles(section.items, this.searchValue);
108+
return section;
109+
});
107110
},
108111
/* Updates layout (when button clicked), and saves in local storage */
109112
layoutOrientation() {

0 commit comments

Comments
 (0)