From 1623f80e88a13b4805b3e6c75a5e369c6bf252de Mon Sep 17 00:00:00 2001 From: en Date: Mon, 3 Feb 2025 20:14:55 +0100 Subject: [PATCH] fix(games): update search to handle roman numerals first, skip memoize on searchTerm --- src/pages/search.tsx | 3 ++- src/utils/utils.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 8b365dc..78e44b0 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -37,6 +37,7 @@ import { extractModData, isModDataComplete, memoizedNormalizeSearchString, + normalizeSearchString, scrollIntoView } from 'utils' import { useCuratedSet } from 'hooks/useCuratedSet' @@ -503,7 +504,7 @@ const GamesResult = ({ searchTerm }: GamesResultProps) => { const filteredGames = useMemo(() => { if (searchTerm === '') return [] - const normalizedSearchTerm = memoizedNormalizeSearchString(searchTerm) + const normalizedSearchTerm = normalizeSearchString(searchTerm) return games.filter((game) => memoizedNormalizeSearchString(game['Game Name']).includes( diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 19fc9bb..ed2a3e1 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -239,9 +239,10 @@ const romanRegex = new RegExp( export const normalizeSearchString = (str: string): string => { str = str.toLowerCase() + str = str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match]) str = removeAccents(str) str = removeSpecialCharacters(str) - return str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match]) + return str } // Memoization function to cache normalized results