fix(games): update search to handle roman numerals first, skip memoize on searchTerm
This commit is contained in:
parent
6236d925c5
commit
688e9fcf6d
@ -37,6 +37,7 @@ import {
|
|||||||
extractModData,
|
extractModData,
|
||||||
isModDataComplete,
|
isModDataComplete,
|
||||||
memoizedNormalizeSearchString,
|
memoizedNormalizeSearchString,
|
||||||
|
normalizeSearchString,
|
||||||
scrollIntoView
|
scrollIntoView
|
||||||
} from 'utils'
|
} from 'utils'
|
||||||
import { useCuratedSet } from 'hooks/useCuratedSet'
|
import { useCuratedSet } from 'hooks/useCuratedSet'
|
||||||
@ -503,7 +504,7 @@ const GamesResult = ({ searchTerm }: GamesResultProps) => {
|
|||||||
const filteredGames = useMemo(() => {
|
const filteredGames = useMemo(() => {
|
||||||
if (searchTerm === '') return []
|
if (searchTerm === '') return []
|
||||||
|
|
||||||
const normalizedSearchTerm = memoizedNormalizeSearchString(searchTerm)
|
const normalizedSearchTerm = normalizeSearchString(searchTerm)
|
||||||
|
|
||||||
return games.filter((game) =>
|
return games.filter((game) =>
|
||||||
memoizedNormalizeSearchString(game['Game Name']).includes(
|
memoizedNormalizeSearchString(game['Game Name']).includes(
|
||||||
|
@ -239,9 +239,10 @@ const romanRegex = new RegExp(
|
|||||||
|
|
||||||
export const normalizeSearchString = (str: string): string => {
|
export const normalizeSearchString = (str: string): string => {
|
||||||
str = str.toLowerCase()
|
str = str.toLowerCase()
|
||||||
|
str = str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match])
|
||||||
str = removeAccents(str)
|
str = removeAccents(str)
|
||||||
str = removeSpecialCharacters(str)
|
str = removeSpecialCharacters(str)
|
||||||
return str.replace(romanRegex, (match) => ROMAN_TO_ARABIC_MAP[match])
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memoization function to cache normalized results
|
// Memoization function to cache normalized results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user