feat: improve search functionality by normalizing input and character names
All checks were successful
Build Docker Image / build (push) Successful in 1m23s
All checks were successful
Build Docker Image / build (push) Successful in 1m23s
This commit is contained in:
@@ -11,6 +11,13 @@
|
|||||||
let highlightedIndex = 0;
|
let highlightedIndex = 0;
|
||||||
let dropdownContainer: HTMLDivElement;
|
let dropdownContainer: HTMLDivElement;
|
||||||
let searchContainer: HTMLDivElement;
|
let searchContainer: HTMLDivElement;
|
||||||
|
|
||||||
|
function normalizeSearchText(value: string): string {
|
||||||
|
return value
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Add click outside listener
|
// Add click outside listener
|
||||||
@@ -22,8 +29,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$: filteredCharacters = characters.filter(char => {
|
$: filteredCharacters = characters.filter(char => {
|
||||||
const searchTerm = searchInput.toLowerCase();
|
const searchTerm = normalizeSearchText(searchInput);
|
||||||
const nameMatches = char.name.toLowerCase().includes(searchTerm);
|
const nameMatches = normalizeSearchText(char.name).includes(searchTerm);
|
||||||
|
|
||||||
let epithetsMatches = false;
|
let epithetsMatches = false;
|
||||||
if (char.epithets) {
|
if (char.epithets) {
|
||||||
@@ -34,13 +41,13 @@
|
|||||||
|
|
||||||
if (Array.isArray(parsedEpithets)) {
|
if (Array.isArray(parsedEpithets)) {
|
||||||
epithetsMatches = parsedEpithets.some((epithet: string) =>
|
epithetsMatches = parsedEpithets.some((epithet: string) =>
|
||||||
epithet.toLowerCase().includes(searchTerm)
|
normalizeSearchText(epithet).includes(searchTerm)
|
||||||
);
|
);
|
||||||
} else if (typeof parsedEpithets === 'string') {
|
} else if (typeof parsedEpithets === 'string') {
|
||||||
epithetsMatches = parsedEpithets.toLowerCase().includes(searchTerm);
|
epithetsMatches = normalizeSearchText(parsedEpithets).includes(searchTerm);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
epithetsMatches = String(char.epithets).toLowerCase().includes(searchTerm);
|
epithetsMatches = normalizeSearchText(String(char.epithets)).includes(searchTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user