Skip to content

Commit

Permalink
Updated to have search history disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dhochbaum-dcp committed Apr 9, 2024
1 parent 2bd9e32 commit 819281a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions addon/components/labs-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export default Component.extend({
return `${host}/${route}?${helpers}q=${searchTerms}`;
}),

host: 'https://search-api-production.herokuapp.com',
route: 'search',

useSearchHistory: false,

searchHistory: window.localStorage["search-history"] ? JSON.parse(window.localStorage["search-history"]) : [],

searchPlaceholder: 'Search...',
Expand Down Expand Up @@ -202,9 +207,11 @@ export default Component.extend({
},

addSearchToSearchHistory(result) {
const h = [...this.searchHistory].filter((search) => search.label !== result.label);
this.set('searchHistory', [{...result, typeTitle: "Search History"}, ...h]);
this.send('saveSearchHistory');
if(this.useSearchHistory) {
const h = [...this.searchHistory].filter((search) => search.label !== result.label);
this.set('searchHistory', [{...result, typeTitle: "Search History"}, ...h]);
this.send('saveSearchHistory');
}
},

removeSearchFromSearchHistory(result) {
Expand All @@ -220,8 +227,10 @@ export default Component.extend({
},

filterSearchHistory(query) {
const h = [...this.searchHistory].filter((search) => search.label.toUpperCase().includes(query.toUpperCase())).slice(0, 5);
this.set('filteredSearchHistory', h)
if(this.useSearchHistory) {
const h = [...this.searchHistory].filter((search) => search.label.toUpperCase().includes(query.toUpperCase())).slice(0, 5);
this.set('filteredSearchHistory', h)
}
},
},
});

0 comments on commit 819281a

Please sign in to comment.