From 6cda59387cc88e07d15533253130750ba997f9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Mon, 15 Jun 2026 18:01:07 -0600 Subject: [PATCH] Public menu UX fixes: brand header, FABs, consultant add/carousel, modal safe-area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit B1 brand header: shorter banner (h-36), avatar centered over the banner's lower edge (z-10, no clipping/layout push), and a compact name-only header when neither banner nor logo is set (no giant gray gradient block). Banner stays edge-to-edge behind the island when an image exists. B2 FABs: reorganized into an ordered bottom-right vertical stack that never overlaps each other or covers dish names/prices; the global 'more' button is now a distinct ⋯ (was a '+', which clashed with the per-dish add '+'). Container padding-bottom raised (pb-48) so the last dish is never hidden behind the FABs. B3 consultant add-to-cart: each recommendation (direct and complement) resolves to a real product by name and shows an 'Agregar' button that adds to the shared cart (badge updates) — only when orders are enabled. B4 consultant carousel: reuses SuggestionCarousel at the bottom of the consultant, contextual to the cart, only when orders are on and pairings exist. B5 safe-area: new .safe-modal padding (top+bottom env insets) on the consultant and cart sheets so content clears the island and gesture bar; layout unchanged. Suggestion computation + name resolution lifted into PublicMenu and shared by the cart and consultant (no duplicated logic). No new i18n keys. Build passes; public page renders in both header modes with no runtime errors. --- src/app/globals.css | 5 + src/components/public/AiConsultant.tsx | 60 ++++++++--- src/components/public/BrandHeader.tsx | 75 ++++++++----- src/components/public/PublicMenu.tsx | 142 +++++++++++++++---------- 4 files changed, 186 insertions(+), 96 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index 1317d4e..8925a0b 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -122,4 +122,9 @@ body { .safe-abs-top { top: calc(env(safe-area-inset-top, 0px) + 0.5rem); } + /* full-screen modal/sheet overlays: keep content clear of island + gesture bar */ + .safe-modal { + padding-top: calc(env(safe-area-inset-top, 0px) + 0.75rem); + padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem); + } } diff --git a/src/components/public/AiConsultant.tsx b/src/components/public/AiConsultant.tsx index 706c37f..ccebada 100644 --- a/src/components/public/AiConsultant.tsx +++ b/src/components/public/AiConsultant.tsx @@ -2,11 +2,28 @@ import { useState } from 'react'; import { useLocale, useTranslations } from 'next-intl'; +import type { SnapshotProduct } from '@/lib/types'; +import SuggestionCarousel from './SuggestionCarousel'; type Recommendation = { dish: string; reason: string; type?: 'direct' | 'complement' }; -export default function AiConsultant({ slug, onClose }: { slug: string; onClose: () => void }) { +export default function AiConsultant({ + slug, + onClose, + ordersEnabled, + onAdd, + resolveDish, + suggestions, +}: { + slug: string; + onClose: () => void; + ordersEnabled: boolean; + onAdd: (p: SnapshotProduct) => void; + resolveDish: (name: string) => SnapshotProduct | undefined; + suggestions: SnapshotProduct[]; +}) { const t = useTranslations('ai'); + const tm = useTranslations('menu'); const locale = useLocale(); const [question, setQuestion] = useState(''); const [loading, setLoading] = useState(false); @@ -35,8 +52,28 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose: } } + function Card(r: Recommendation, key: number) { + const product = resolveDish(r.dish); + return ( +
+
+
{r.dish}
+

{r.reason}

+
+ {ordersEnabled && product && ( + + )} +
+ ); + } + return ( -
+

{t('title')}

@@ -46,9 +83,7 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose:
- {!answer && !loading && ( -

{t('intro')}

- )} + {!answer && !loading &&

{t('intro')}

} {loading &&

{t('thinking')}

} {error &&

⚠️

} {answer && ( @@ -57,15 +92,9 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose: {(() => { const direct = answer.recommendations.filter((r) => r.type !== 'complement'); const complement = answer.recommendations.filter((r) => r.type === 'complement'); - const Card = (r: Recommendation, i: number) => ( -
-
{r.dish}
-

{r.reason}

-
- ); return ( <> - {direct.map(Card)} + {direct.map((r, i) => Card(r, i))} {complement.length > 0 && ( <>

@@ -79,6 +108,13 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose: })()}

)} + + {/* Precomputed pairings carousel (reuses the cart component) */} + {ordersEnabled && suggestions.length > 0 && ( +
+ +
+ )}
diff --git a/src/components/public/BrandHeader.tsx b/src/components/public/BrandHeader.tsx index f356f73..67fc2be 100644 --- a/src/components/public/BrandHeader.tsx +++ b/src/components/public/BrandHeader.tsx @@ -44,15 +44,50 @@ export default function BrandHeader({ socialLinks?: SocialLink[]; }) { const links = (socialLinks ?? []).filter((l) => l.url); + const hasBanner = !!banner; + const hasLogo = !!logo; + + const socialRow = links.length > 0 && ( +
+ {links.map((l, i) => { + const Icon = iconFor(l.platform); + return ( + + + + ); + })} +
+ ); + + // No banner AND no logo → compact header (no empty gray block), just the name. + if (!hasBanner && !hasLogo) { + return ( +
+
+

{name}

+ +
+ {socialRow} +
+ ); + } return (
- {/* Banner — full-bleed, extends edge-to-edge behind the island. Falls back - to a palette gradient when no image is set. */} -
- {banner ? ( + {/* Banner — full-bleed, extends edge-to-edge behind the island. A short + palette gradient stands in when there's a logo but no banner image. */} +
+ {hasBanner ? ( // eslint-disable-next-line @next/next/no-img-element - + ) : (
- {/* Logo + name + socials, pulled up over the banner. */} -
-
- {logo ? ( + {/* Logo + name + socials, the avatar centered over the banner's lower edge. */} +
+
+ {hasLogo ? ( // eslint-disable-next-line @next/next/no-img-element - {name} + {name} ) : (
{name.charAt(0).toUpperCase()} @@ -78,25 +113,7 @@ export default function BrandHeader({ )}

{name}

- {links.length > 0 && ( -
- {links.map((l, i) => { - const Icon = iconFor(l.platform); - return ( - - - - ); - })} -
- )} + {socialRow}
); diff --git a/src/components/public/PublicMenu.tsx b/src/components/public/PublicMenu.tsx index a1b5341..9070e9c 100644 --- a/src/components/public/PublicMenu.tsx +++ b/src/components/public/PublicMenu.tsx @@ -15,6 +15,16 @@ import SuggestionCarousel from './SuggestionCarousel'; type ViewMode = 'cards' | 'list'; +// Normalize a dish name for matching consultant recommendations to real products. +function normName(s: string): string { + return s + .toLowerCase() + .normalize('NFD') + .replace(/\p{Diacritic}/gu, '') + .replace(/\s+/g, ' ') + .trim(); +} + type CartLine = { product: SnapshotProduct; qty: number; note?: string }; export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: string }) { @@ -45,12 +55,22 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s const [view, setView] = useState('cards'); const sectionRefs = useRef>({}); - // Flat index of active products for pairing lookups. + // Flat index of active products for pairing lookups (by id) and consultant + // add-to-cart resolution (by normalized name in either locale). const productIndex = useMemo(() => { const map = new Map(); for (const s of sections) for (const p of s.products) map.set(p.id, p); return map; }, [sections]); + const nameIndex = useMemo(() => { + const map = new Map(); + for (const s of sections) + for (const p of s.products) { + if (p.name.es) map.set(normName(p.name.es), p); + if (p.name.en) map.set(normName(p.name.en), p); + } + return map; + }, [sections]); const pairings = menu.restaurant.pairings ?? {}; const ordersEnabled = menu.restaurant.ordersEnabled; @@ -81,8 +101,25 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s const cartCount = cart.reduce((n, l) => n + l.qty, 0); + // Contextual pairings for what's in the cart (excluding items already added). + // Shared by the cart sheet and the consultant carousel — computed once here. + const cartSuggestions = useMemo(() => { + const inCart = new Set(cart.map((l) => l.product.id)); + const ids = new Set(); + for (const line of cart) { + for (const id of pairings[line.product.id] ?? []) { + if (!inCart.has(id)) ids.add(id); + } + } + return Array.from(ids) + .map((id) => productIndex.get(id)) + .filter((p): p is SnapshotProduct => !!p && p.isActive); + }, [cart, pairings, productIndex]); + + const resolveDish = (dishName: string) => nameIndex.get(normName(dishName)); + return ( -
+
{/* Brand header (banner + logo + name + social icons) */} ))} - {/* Floating actions */} -
+ {/* Floating actions — ordered vertical stack in the bottom-right corner so + they never overlap each other or cover dish names/prices. */} +
{actionsOpen && ( -
+
@@ -193,41 +231,40 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s window.scrollTo({ top: 0, behavior: 'smooth' }); setActionsOpen(false); }} - className="glass rounded-full px-5 py-3 text-sm font-medium" + className="glass rounded-full px-4 py-2.5 text-sm font-medium shadow" > {t('viewFull')}
)} -
+ + {ordersEnabled && ( - {ordersEnabled && ( - - )} - -
+ )} + {/* 'More' (waiter / back to top) — distinct ⋯ icon, not a '+', to avoid + confusion with the add-to-cart '+' inside each dish. */} +
{/* Modals */} @@ -238,14 +275,24 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s showMacros={gallery.showMacros} /> )} - {aiOpen && setAiOpen(false)} />} + {aiOpen && ( + setAiOpen(false)} + ordersEnabled={ordersEnabled} + onAdd={(p) => { + addToCart(p); + }} + resolveDish={resolveDish} + suggestions={cartSuggestions} + /> + )} {orderOpen && ( setOrderOpen(false)} onSent={() => { @@ -294,8 +341,7 @@ function OrderPanel({ slug, cart, setCart, - productIndex, - pairings, + suggestions, onAdd, onClose, onSent, @@ -303,8 +349,7 @@ function OrderPanel({ slug: string; cart: CartLine[]; setCart: React.Dispatch>; - productIndex: Map; - pairings: Record; + suggestions: SnapshotProduct[]; onAdd: (p: SnapshotProduct) => void; onClose: () => void; onSent: () => void; @@ -315,19 +360,6 @@ function OrderPanel({ const [generalNote, setGeneralNote] = useState(''); const [sending, setSending] = useState(false); - // Contextual pairings: complements of what's in the cart, excluding items - // already added. Read from precomputed associations — no AI call. - const inCart = new Set(cart.map((l) => l.product.id)); - const suggestionIds = new Set(); - for (const line of cart) { - for (const id of pairings[line.product.id] ?? []) { - if (!inCart.has(id)) suggestionIds.add(id); - } - } - const suggestions = Array.from(suggestionIds) - .map((id) => productIndex.get(id)) - .filter((p): p is SnapshotProduct => !!p && p.isActive); - function setQty(id: string, delta: number) { setCart((prev) => prev @@ -478,8 +510,8 @@ function Sheet({ children: React.ReactNode; }) { return ( -
-
+
+

{title}