Skip to content

Commit 06d592e

Browse files
authored
refactor(search): implement normalizeAsUrl for key computation (#123)
### Description Refactor $addToRecentSearchesFn to use normalizeAsUrl ### Related Issue <!-- Please prefix the issue number with Fixes/Resolves - example: Fixes #123 or Resolves #123 --> Fixes #48 ### Screenshots/Screencasts <!-- Please provide screenshots or video recording that demos your changes (especially if it's a visual change) --> ### Notes to Reviewer <!-- Please state here if you added a new npm packages, or any extra information that can help reviewer better review you changes -->
1 parent 65e35d1 commit 06d592e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/lib/stores/search.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { atom, map } from "nanostores";
2+
import { normalizeAsUrl } from "../utils/index.js";
3+
24

35
export const $isSearchOpen = atom(false);
46

@@ -20,8 +22,8 @@ export function $addToRecentSearchesFn({ word, url }) {
2022
const storedSearches = JSON.parse(localStorage.getItem("jargons.dev:recent_searches")) || {};
2123
$recentSearches.set({ ...storedSearches });
2224

23-
const lowercaseKey = word.toLowerCase();
24-
const key = lowercaseKey.includes(" ") ? lowercaseKey.split(" ").join("-") : lowercaseKey;
25+
const key = normalizeAsUrl(word);
26+
2527

2628
const recentSearchesCopy = $recentSearches.get();
2729

0 commit comments

Comments
 (0)