fix(catalogue): recherche insensible aux accents — filtrage côté client v0.4.11
Le backend utilisait ILIKE (insensible à la casse uniquement) — "iles" ne trouvait pas "Îles flottantes". Passage au filtrage client avec matchesSearch (normalize NFD) identique au bottom sheet. Charge tous les produits une fois puis filtre sur name, brand et category sans aller-retour serveur. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "homehub-frontend",
|
||||
"private": true,
|
||||
"version": "0.4.10",
|
||||
"version": "0.4.11",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useEffect, useRef } from 'react'
|
||||
import type { Product, ProductCreate, Store } from '../../api/shopping'
|
||||
import { searchProducts, createProduct, updateProduct, deleteProduct } from '../../api/shopping'
|
||||
import Modal from '../Modal'
|
||||
import { matchesSearch } from '../../utils/search'
|
||||
|
||||
interface CatalogueModalProps {
|
||||
stores: Store[]
|
||||
@@ -43,16 +44,20 @@ export default function CatalogueModal({ stores, onClose }: CatalogueModalProps)
|
||||
|
||||
useEffect(() => {
|
||||
void loadProducts()
|
||||
}, [search])
|
||||
}, [])
|
||||
|
||||
async function loadProducts() {
|
||||
try {
|
||||
setProducts(await searchProducts(search || undefined))
|
||||
setProducts(await searchProducts())
|
||||
} catch {
|
||||
setError('Erreur de chargement')
|
||||
}
|
||||
}
|
||||
|
||||
const filteredProducts = products.filter(p =>
|
||||
!search.trim() || matchesSearch(p.name, search) || matchesSearch(p.brand ?? '', search) || matchesSearch(p.category ?? '', search)
|
||||
)
|
||||
|
||||
function startCreate() {
|
||||
setForm(emptyForm)
|
||||
setEditing(null)
|
||||
@@ -289,12 +294,12 @@ export default function CatalogueModal({ stores, onClose }: CatalogueModalProps)
|
||||
</div>
|
||||
|
||||
<div style={{ maxHeight: 400, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
{products.length === 0 && (
|
||||
{filteredProducts.length === 0 && (
|
||||
<p style={{ color: 'var(--ink-3)', textAlign: 'center', padding: 20, fontFamily: 'var(--font-ui)', fontSize: 13 }}>
|
||||
Aucun article{search ? ` pour "${search}"` : ''}
|
||||
</p>
|
||||
)}
|
||||
{products.map(p => (
|
||||
{filteredProducts.map(p => (
|
||||
<div
|
||||
key={p.id}
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user