fix(menu-app): show a product once in search when it's listed in several categories
Platform v2 step 1.13 (D-23): the site's menu snapshot can list the same product under several categories. Search flattened all categories, so such a product appeared twice (and with a duplicate React key). Category sections still show it in each category; cart lookups already used the first match. npm run build passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -484,7 +484,12 @@ function SearchOverlay({ open, onClose, categories, lang, t, onOpen, onAdd, cart
|
|||||||
useEffect(() => { if (open && inputRef.current) inputRef.current.focus() }, [open])
|
useEffect(() => { if (open && inputRef.current) inputRef.current.focus() }, [open])
|
||||||
useEffect(() => { if (!open) setQ('') }, [open])
|
useEffect(() => { if (!open) setQ('') }, [open])
|
||||||
|
|
||||||
const allProducts = useMemo(() => categories.flatMap(c => c.products), [categories])
|
// A product can be listed in several categories (platform v2, D-23): search shows it once,
|
||||||
|
// under the first category it appears in.
|
||||||
|
const allProducts = useMemo(() => {
|
||||||
|
const seen = new Set()
|
||||||
|
return categories.flatMap(c => c.products).filter(p => !seen.has(p.id) && seen.add(p.id))
|
||||||
|
}, [categories])
|
||||||
|
|
||||||
const results = useMemo(() => {
|
const results = useMemo(() => {
|
||||||
const term = q.trim().toLowerCase()
|
const term = q.trim().toLowerCase()
|
||||||
|
|||||||
Reference in New Issue
Block a user