Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search fixes #1099

Merged
merged 6 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: don't save duplicate searches to recents
sunnyzanchi committed Oct 16, 2024
commit fb08e7647edc8f9f144e16ce7ea7035950747928
7 changes: 7 additions & 0 deletions packages/gatsby-theme-newrelic/src/components/GlobalSearch.js
Original file line number Diff line number Diff line change
@@ -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);