mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix(search): place searches find a name typed without its accents (#3075)
"Obidos" did not find "Óbidos", nor "Sao Bras" "São Brás". The search of the places list, a collection, the saved-place picker, the import from a trip and the location picker now compare without case and Latin accents, with letters such as ß, ø or ł folded to their plain spelling. Marks outside Latin script stay, since there they change the word.
This commit is contained in:
@@ -53,6 +53,17 @@ const HOLE = undefined as unknown as CollectionPlace;
|
||||
describe('collectionsModel', () => {
|
||||
// ── filterPlaces ────────────────────────────────────────────────────────────
|
||||
describe('filterPlaces', () => {
|
||||
it('FE-COLLECTIONS-MODEL-045: the search finds Óbidos and São Brás typed without accents (#3075)', () => {
|
||||
const places = [
|
||||
cp({ id: 1, name: 'Óbidos', status: 'idea' }),
|
||||
cp({ id: 2, name: 'São Brás de Alportel', status: 'idea' }),
|
||||
cp({ id: 3, name: 'Lagos', status: 'idea', address: 'Rua de Évora' }),
|
||||
];
|
||||
expect(filterPlaces(places, 'all', 'obidos').map(p => p.id)).toEqual([1]);
|
||||
expect(filterPlaces(places, 'all', 'Sao Bras').map(p => p.id)).toEqual([2]);
|
||||
expect(filterPlaces(places, 'all', 'evora').map(p => p.id)).toEqual([3]);
|
||||
});
|
||||
|
||||
it('FE-COLLECTIONS-MODEL-001: status filter keeps only the matching status', () => {
|
||||
const places = [
|
||||
cp({ id: 1, name: 'A', status: 'idea' }),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CollectionPlace, CollectionLabel } from '@trek/shared'
|
||||
import type { StatusFilter, CollectionSortMode } from '../../store/collectionStore'
|
||||
import { textMatchesSearch } from '../../utils/placeSearch'
|
||||
|
||||
/**
|
||||
* Pure data shaping + presentation metadata for the Collections page. No React
|
||||
@@ -36,7 +37,6 @@ export function filterPlaces(
|
||||
labelFilter: number[] = [],
|
||||
ratingFilter: number | 'all' = 'all',
|
||||
): CollectionPlace[] {
|
||||
const q = search.trim().toLowerCase()
|
||||
return places.filter(p => {
|
||||
if (!p) return false
|
||||
if (statusFilter !== 'all' && p.status !== statusFilter) return false
|
||||
@@ -44,12 +44,7 @@ export function filterPlaces(
|
||||
// Minimum-average-stars filter (#1435): unrated places drop out once a floor is set.
|
||||
if (ratingFilter !== 'all' && (p.rating_avg == null || p.rating_avg < ratingFilter)) return false
|
||||
if (labelFilter.length && !labelFilter.some(id => (p.label_ids ?? []).includes(id))) return false
|
||||
if (!q) return true
|
||||
return (
|
||||
p.name.toLowerCase().includes(q) ||
|
||||
(p.address ?? '').toLowerCase().includes(q) ||
|
||||
(p.notes ?? '').toLowerCase().includes(q)
|
||||
)
|
||||
return textMatchesSearch([p.name, p.address, p.notes], search)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user