Skip to content

Commit

Permalink
fix: don't save duplciate searches to recents
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyzanchi committed Oct 16, 2024
1 parent ea47361 commit bbeeec8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/gatsby-theme-newrelic/src/components/GlobalSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,16 @@ GlobalSearch.propTypes = {
const SAVED_SEARCH_KEY = 'gatsby-theme-newrelic:saved-searches';

const saveSearch = (value) => {
value = value.trim();
const savedSearches = JSON.parse(
localStorage.getItem(SAVED_SEARCH_KEY) ?? '[]'
);
const set = new Set(savedSearches);

if (set.has(value)) {
return;
}

savedSearches.push(value);
// only save the four most recent searches
const updated = savedSearches.slice(-4);
Expand Down

0 comments on commit bbeeec8

Please sign in to comment.