Public menu UX fixes: brand header, FABs, consultant add/carousel, modal safe-area
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.
This commit is contained in:
1 parent
244adaee30
commit
6cda59387c
4 files changed
+186
-96
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 (
|
||||
<div key={key} className="glass-soft flex items-start gap-2 rounded-2xl p-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="font-semibold text-[var(--accent)]">{r.dish}</div>
|
||||
<p className="text-sm text-[var(--text)]/80">{r.reason}</p>
|
||||
</div>
|
||||
{ordersEnabled && product && (
|
||||
<button
|
||||
onClick={() => onAdd(product)}
|
||||
className="shrink-0 rounded-full bg-[var(--accent)] px-3 py-1.5 text-xs font-medium text-white"
|
||||
>
|
||||
{tm('addToOrder')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-end justify-center bg-black/40 p-3 backdrop-blur-sm sm:items-center">
|
||||
<div className="safe-modal fixed inset-0 z-50 flex items-end justify-center bg-black/40 px-3 backdrop-blur-sm sm:items-center">
|
||||
<div className="glass flex max-h-[85vh] w-full max-w-md flex-col gap-3 rounded-3xl p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="display text-lg font-semibold">{t('title')}</h3>
|
||||
@@ -46,9 +83,7 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose:
|
||||
</div>
|
||||
|
||||
<div className="min-h-[6rem] flex-1 overflow-y-auto">
|
||||
{!answer && !loading && (
|
||||
<p className="text-sm text-[var(--text)]/60">{t('intro')}</p>
|
||||
)}
|
||||
{!answer && !loading && <p className="text-sm text-[var(--text)]/60">{t('intro')}</p>}
|
||||
{loading && <p className="animate-pulse text-sm text-[var(--text)]/60">{t('thinking')}</p>}
|
||||
{error && <p className="text-sm text-red-600">⚠️</p>}
|
||||
{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) => (
|
||||
<div key={i} className="glass-soft rounded-2xl p-3">
|
||||
<div className="font-semibold text-[var(--accent)]">{r.dish}</div>
|
||||
<p className="text-sm text-[var(--text)]/80">{r.reason}</p>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
{direct.map(Card)}
|
||||
{direct.map((r, i) => Card(r, i))}
|
||||
{complement.length > 0 && (
|
||||
<>
|
||||
<p className="mt-1 text-xs font-semibold uppercase tracking-wide text-[var(--text)]/50">
|
||||
@@ -79,6 +108,13 @@ export default function AiConsultant({ slug, onClose }: { slug: string; onClose:
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Precomputed pairings carousel (reuses the cart component) */}
|
||||
{ordersEnabled && suggestions.length > 0 && (
|
||||
<div className="mt-4">
|
||||
<SuggestionCarousel products={suggestions} onAdd={onAdd} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
|
||||
@@ -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 && (
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
{links.map((l, i) => {
|
||||
const Icon = iconFor(l.platform);
|
||||
return (
|
||||
<a
|
||||
key={i}
|
||||
href={normalizeUrl(l.url)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={l.platform}
|
||||
className="glass-pill flex h-9 w-9 items-center justify-center rounded-full"
|
||||
>
|
||||
<Icon className="h-4 w-4 text-[var(--text)]" />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
||||
// No banner AND no logo → compact header (no empty gray block), just the name.
|
||||
if (!hasBanner && !hasLogo) {
|
||||
return (
|
||||
<header className="safe-pt-header mb-4 flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h1 className="display text-2xl font-semibold leading-tight">{name}</h1>
|
||||
<LanguageSwitch />
|
||||
</div>
|
||||
{socialRow}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="mb-4">
|
||||
{/* Banner — full-bleed, extends edge-to-edge behind the island. Falls back
|
||||
to a palette gradient when no image is set. */}
|
||||
<div className="relative -mx-4 h-44 overflow-hidden">
|
||||
{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. */}
|
||||
<div className="relative -mx-4 h-36 overflow-hidden">
|
||||
{hasBanner ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={banner} alt="" className="h-full w-full object-cover" />
|
||||
<img src={banner!} alt="" className="h-full w-full object-cover" />
|
||||
) : (
|
||||
<div
|
||||
className="h-full w-full"
|
||||
@@ -65,12 +100,12 @@ export default function BrandHeader({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Logo + name + socials, pulled up over the banner. */}
|
||||
<div className="-mt-12 flex flex-col items-center gap-2 px-2 text-center">
|
||||
<div className="h-24 w-24 overflow-hidden rounded-full border-4 border-white/70 bg-white/40 shadow-lg">
|
||||
{logo ? (
|
||||
{/* Logo + name + socials, the avatar centered over the banner's lower edge. */}
|
||||
<div className="relative z-10 -mt-12 flex flex-col items-center gap-2 px-2 text-center">
|
||||
<div className="h-24 w-24 overflow-hidden rounded-full border-4 border-white/70 bg-white/50 shadow-lg">
|
||||
{hasLogo ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={logo} alt={name} className="h-full w-full object-cover" />
|
||||
<img src={logo!} alt={name} className="h-full w-full object-cover" />
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center text-3xl font-semibold text-[var(--accent)]">
|
||||
{name.charAt(0).toUpperCase()}
|
||||
@@ -78,25 +113,7 @@ export default function BrandHeader({
|
||||
)}
|
||||
</div>
|
||||
<h1 className="display text-2xl font-semibold leading-tight">{name}</h1>
|
||||
{links.length > 0 && (
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
{links.map((l, i) => {
|
||||
const Icon = iconFor(l.platform);
|
||||
return (
|
||||
<a
|
||||
key={i}
|
||||
href={normalizeUrl(l.url)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={l.platform}
|
||||
className="glass-pill flex h-9 w-9 items-center justify-center rounded-full"
|
||||
>
|
||||
<Icon className="h-4 w-4 text-[var(--text)]" />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{socialRow}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -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<ViewMode>('cards');
|
||||
const sectionRefs = useRef<Record<string, HTMLElement | null>>({});
|
||||
|
||||
// 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<string, SnapshotProduct>();
|
||||
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<string, SnapshotProduct>();
|
||||
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<string>();
|
||||
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 (
|
||||
<div className="mx-auto min-h-screen max-w-2xl px-4 pb-32">
|
||||
<div className="mx-auto min-h-screen max-w-2xl px-4 pb-48">
|
||||
{/* Brand header (banner + logo + name + social icons) */}
|
||||
<BrandHeader
|
||||
name={menu.restaurant.name}
|
||||
@@ -175,16 +212,17 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
|
||||
</section>
|
||||
))}
|
||||
|
||||
{/* Floating actions */}
|
||||
<div className="safe-bottom-fab fixed left-1/2 z-30 flex -translate-x-1/2 flex-col items-center gap-3">
|
||||
{/* Floating actions — ordered vertical stack in the bottom-right corner so
|
||||
they never overlap each other or cover dish names/prices. */}
|
||||
<div className="safe-bottom-fab fixed right-4 z-40 flex flex-col items-end gap-2.5">
|
||||
{actionsOpen && (
|
||||
<div className="animate-spawn flex flex-col items-stretch gap-2">
|
||||
<div className="animate-spawn flex flex-col items-end gap-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
setWaiterOpen(true);
|
||||
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('callWaiter')}
|
||||
</button>
|
||||
@@ -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')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={() => setAiOpen(true)}
|
||||
className="glass rounded-full px-5 py-3 text-sm font-semibold shadow-lg"
|
||||
>
|
||||
✨ {t('askAi')}
|
||||
</button>
|
||||
{ordersEnabled && (
|
||||
<button
|
||||
onClick={() => setAiOpen(true)}
|
||||
className="glass rounded-full px-5 py-3 text-sm font-semibold shadow-lg"
|
||||
onClick={() => setOrderOpen(true)}
|
||||
className="relative flex items-center gap-2 rounded-full bg-[var(--accent)] px-5 py-3 text-sm font-semibold text-white shadow-lg"
|
||||
>
|
||||
✨ {t('askAi')}
|
||||
🛒 {t('cart')}
|
||||
{cartCount > 0 && (
|
||||
<span className="absolute -right-1 -top-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-white px-1 text-xs font-bold text-[var(--accent)] shadow">
|
||||
{cartCount}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
{ordersEnabled && (
|
||||
<button
|
||||
onClick={() => setOrderOpen(true)}
|
||||
className="relative flex h-12 items-center gap-2 rounded-full bg-[var(--accent)] px-5 text-sm font-semibold text-white shadow-lg"
|
||||
aria-label={t('cart')}
|
||||
>
|
||||
🛒 {t('cart')}
|
||||
{cartCount > 0 && (
|
||||
<span className="absolute -right-1 -top-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-white px-1 text-xs font-bold text-[var(--accent)] shadow">
|
||||
{cartCount}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setActionsOpen((o) => !o)}
|
||||
className="flex h-12 w-12 items-center justify-center rounded-full bg-[var(--accent)] text-2xl text-white shadow-lg transition"
|
||||
aria-label={t('actions')}
|
||||
>
|
||||
<span className={`transition-transform ${actionsOpen ? 'rotate-45' : ''}`}>+</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{/* 'More' (waiter / back to top) — distinct ⋯ icon, not a '+', to avoid
|
||||
confusion with the add-to-cart '+' inside each dish. */}
|
||||
<button
|
||||
onClick={() => setActionsOpen((o) => !o)}
|
||||
className="glass flex h-11 w-11 items-center justify-center rounded-full text-xl shadow-lg"
|
||||
aria-label={t('actions')}
|
||||
>
|
||||
{actionsOpen ? '✕' : '⋯'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Modals */}
|
||||
@@ -238,14 +275,24 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
|
||||
showMacros={gallery.showMacros}
|
||||
/>
|
||||
)}
|
||||
{aiOpen && <AiConsultant slug={slug} onClose={() => setAiOpen(false)} />}
|
||||
{aiOpen && (
|
||||
<AiConsultant
|
||||
slug={slug}
|
||||
onClose={() => setAiOpen(false)}
|
||||
ordersEnabled={ordersEnabled}
|
||||
onAdd={(p) => {
|
||||
addToCart(p);
|
||||
}}
|
||||
resolveDish={resolveDish}
|
||||
suggestions={cartSuggestions}
|
||||
/>
|
||||
)}
|
||||
{orderOpen && (
|
||||
<OrderPanel
|
||||
slug={slug}
|
||||
cart={cart}
|
||||
setCart={setCart}
|
||||
productIndex={productIndex}
|
||||
pairings={pairings}
|
||||
suggestions={cartSuggestions}
|
||||
onAdd={addToCart}
|
||||
onClose={() => 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<React.SetStateAction<CartLine[]>>;
|
||||
productIndex: Map<string, SnapshotProduct>;
|
||||
pairings: Record<string, string[]>;
|
||||
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<string>();
|
||||
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 (
|
||||
<div className="fixed inset-0 z-50 flex items-end justify-center bg-black/40 p-3 backdrop-blur-sm sm:items-center">
|
||||
<div className="glass flex w-full max-w-md flex-col gap-3 rounded-3xl p-4">
|
||||
<div className="safe-modal fixed inset-0 z-50 flex items-end justify-center bg-black/40 px-3 backdrop-blur-sm sm:items-center">
|
||||
<div className="glass flex max-h-[88vh] w-full max-w-md flex-col gap-3 overflow-y-auto rounded-3xl p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="display text-lg font-semibold">{title}</h3>
|
||||
<button onClick={onClose} className="glass-pill rounded-full px-3 py-1">
|
||||
|
||||
Reference in new issue
Block a user