Add per-restaurant macros toggle and public list view

Feature 1 — showMacros toggle:
- Restaurant.showMacros boolean (default false) so existing menus (e.g. NOCNEX)
  never publish with empty macros (migration 0004; default applies to existing rows)
- Editor toggle in the Palette tab, saved via the existing /settings endpoint
- Read live (not from the snapshot) in the public page and /menu API so it takes
  effect immediately without republishing; old snapshots default off
- When off, the public menu hides every macro layer: card flip + 'tap to see
  macros', the gallery macros, and the macro color-code legend

Feature 2 — public list view:
- Card/list toggle in the public menu; preference is NOT persisted (always starts
  on cards)
- New ListRow: compact traditional rows (name + price + allergen tags); tap the
  name to expand image + description (accordion); tap the image to reveal macros
  (only when showMacros is on)

i18n: viewCards/viewList (menu) and showMacros/showMacrosHint (editor) in es/en at parity.
Glassmorphism, mobile-first and safe areas preserved. Existing features untouched
(versioning, import, consultant, QR, i18n).

Verified: build passes; 4 migrations apply in order; existing rows default false;
toggling via /settings updates /menu live without republish.
This commit is contained in:
Jorem Juárez committed 2026-06-15 14:32:44 -06:00
1 parent d71ede3d00
commit 084a191061
17 files changed
+241 -28

No files matched your search

+1
View File
@@ -37,6 +37,7 @@ export default async function EditorPage({
slug: restaurant.slug,
name: restaurant.name,
ordersEnabled: restaurant.ordersEnabled,
showMacros: restaurant.showMacros,
defaultLocale: restaurant.defaultLocale as 'es' | 'en',
palette: (restaurant.palette as Palette) ?? {},
qrConfig: (restaurant.qrConfig as QrConfig) ?? {},
+6 -1
View File
@@ -21,11 +21,16 @@ async function getPublishedMenu(slug: string): Promise<MenuSnapshot | null> {
palette: (restaurant.palette as MenuSnapshot['restaurant']['palette']) ?? {},
ordersEnabled: restaurant.ordersEnabled,
defaultLocale: restaurant.defaultLocale as 'es' | 'en',
showMacros: restaurant.showMacros,
},
sections: [],
};
}
return restaurant.publishedVersion.snapshot as unknown as MenuSnapshot;
const snapshot = restaurant.publishedVersion.snapshot as unknown as MenuSnapshot;
// showMacros is read live (not from the snapshot) so toggling it takes effect
// immediately without republishing — and old snapshots without the flag default off.
snapshot.restaurant.showMacros = restaurant.showMacros;
return snapshot;
}
export default async function PublicMenuPage({ params }: { params: { slug: string } }) {
+4 -1
View File
@@ -16,5 +16,8 @@ export async function GET(_req: Request, { params }: { params: { slug: string }
if (!restaurant.publishedVersion) {
return NextResponse.json({ error: 'not_published' }, { status: 404 });
}
return NextResponse.json(restaurant.publishedVersion.snapshot as unknown as MenuSnapshot);
const snapshot = restaurant.publishedVersion.snapshot as unknown as MenuSnapshot;
// Read showMacros live so the toggle applies without republishing.
snapshot.restaurant.showMacros = restaurant.showMacros;
return NextResponse.json(snapshot);
}
+2 -1
View File
@@ -8,8 +8,9 @@ export async function PATCH(req: Request, { params }: { params: { slug: string }
if ('error' in guard) return guard.error;
const body = await req.json().catch(() => null);
const data: { ordersEnabled?: boolean; defaultLocale?: string } = {};
const data: { ordersEnabled?: boolean; defaultLocale?: string; showMacros?: boolean } = {};
if (typeof body?.ordersEnabled === 'boolean') data.ordersEnabled = body.ordersEnabled;
if (typeof body?.showMacros === 'boolean') data.showMacros = body.showMacros;
if (body?.defaultLocale === 'es' || body?.defaultLocale === 'en') {
data.defaultLocale = body.defaultLocale;
}
+7 -1
View File
@@ -49,7 +49,13 @@ export default function Editor({ data, baseUrl }: { data: EditorData; baseUrl: s
onRestored={(name) => setPublishedName(name)}
/>
)}
{tab === 'palette' && <PaletteTab slug={data.slug} initialPalette={data.palette} />}
{tab === 'palette' && (
<PaletteTab
slug={data.slug}
initialPalette={data.palette}
initialShowMacros={data.showMacros}
/>
)}
{tab === 'orders' && (
<OrdersTab
slug={data.slug}
+30
View File
@@ -15,9 +15,11 @@ const FIELDS: { key: keyof Palette; label: string }[] = [
export default function PaletteTab({
slug,
initialPalette,
initialShowMacros,
}: {
slug: string;
initialPalette: Palette;
initialShowMacros: boolean;
}) {
const t = useTranslations('editor');
const tc = useTranslations('common');
@@ -25,9 +27,16 @@ export default function PaletteTab({
...PALETTE_PRESETS[0].palette,
...initialPalette,
});
const [showMacros, setShowMacros] = useState(initialShowMacros);
const [saving, setSaving] = useState(false);
const [saved, setSaved] = useState(false);
async function toggleMacros() {
const next = !showMacros;
setShowMacros(next);
await api(slug, '/settings', { method: 'PATCH', json: { showMacros: next } });
}
function update(next: Palette) {
setPalette(next);
setSaved(false);
@@ -102,6 +111,27 @@ export default function PaletteTab({
<p className="text-xs text-[var(--text)]/55">⚠️ {t('paletteHint')}</p>
{/* Show-macros toggle (controls whether the public menu exposes any macro layer) */}
<div className="glass flex items-center justify-between gap-3 rounded-3xl p-4">
<div className="min-w-0">
<div className="text-sm font-medium">{t('showMacros')}</div>
<div className="text-xs text-[var(--text)]/55">{t('showMacrosHint')}</div>
</div>
<button
onClick={toggleMacros}
aria-pressed={showMacros}
className={`relative h-7 w-12 shrink-0 rounded-full transition ${
showMacros ? 'bg-green-500' : 'bg-gray-300'
}`}
>
<span
className={`absolute top-1 h-5 w-5 rounded-full bg-white transition-all ${
showMacros ? 'left-6' : 'left-1'
}`}
/>
</button>
</div>
<button
onClick={save}
disabled={saving}
+1
View File
@@ -40,6 +40,7 @@ export type EditorData = {
slug: string;
name: string;
ordersEnabled: boolean;
showMacros: boolean;
defaultLocale: Locale;
palette: Palette;
qrConfig: QrConfig;
+25 -16
View File
@@ -14,12 +14,14 @@ export default function DishCard({
onOpenGallery,
onAdd,
ordersEnabled,
showMacros,
}: {
product: SnapshotProduct;
index: number;
onOpenGallery: (p: SnapshotProduct) => void;
onAdd?: (p: SnapshotProduct) => void;
ordersEnabled: boolean;
showMacros: boolean;
}) {
const locale = useLocale() as Locale;
const t = useTranslations('menu');
@@ -74,22 +76,29 @@ export default function DishCard({
</span>
))}
</div>
<div className="mt-1 flex items-center gap-2">
<button
onClick={() => setFlipped(true)}
className="glass-pill flex-1 rounded-full py-2 text-sm font-medium"
>
{t('tapToFlip')}
</button>
{ordersEnabled && onAdd && (
<button
onClick={() => onAdd(product)}
className="rounded-full bg-[var(--accent)] px-4 py-2 text-sm font-medium text-white"
>
+
</button>
)}
</div>
{(showMacros || (ordersEnabled && onAdd)) && (
<div className="mt-1 flex items-center gap-2">
{showMacros && (
<button
onClick={() => setFlipped(true)}
className="glass-pill flex-1 rounded-full py-2 text-sm font-medium"
>
{t('tapToFlip')}
</button>
)}
{ordersEnabled && onAdd && (
<button
onClick={() => onAdd(product)}
aria-label={t('addToOrder')}
className={`rounded-full bg-[var(--accent)] px-4 py-2 text-sm font-medium text-white ${
showMacros ? '' : 'flex-1'
}`}
>
{showMacros ? '+' : t('addToOrder')}
</button>
)}
</div>
)}
</div>
</div>
+3 -1
View File
@@ -10,9 +10,11 @@ import MacrosBack from './MacrosBack';
export default function Gallery({
product,
onClose,
showMacros,
}: {
product: SnapshotProduct;
onClose: () => void;
showMacros: boolean;
}) {
const locale = useLocale() as Locale;
const name = pickText(product.name, locale);
@@ -60,7 +62,7 @@ export default function Gallery({
)}
</div>
<MacrosBack macros={product.macros} />
{showMacros && <MacrosBack macros={product.macros} />}
</div>
</div>
);
+101
View File
@@ -0,0 +1,101 @@
'use client';
import { useState } from 'react';
import { useLocale, useTranslations } from 'next-intl';
import type { Locale } from '@/i18n/config';
import type { SnapshotProduct } from '@/lib/types';
import { pickText } from '@/lib/text';
import MediaThumb from './MediaThumb';
import MacrosBack from './MacrosBack';
// Traditional-list row with two-level interaction:
// tap NAME -> accordion reveals image + description
// tap IMAGE -> reveals macros (only when the restaurant enabled showMacros)
export default function ListRow({
product,
showMacros,
ordersEnabled,
onAdd,
}: {
product: SnapshotProduct;
showMacros: boolean;
ordersEnabled: boolean;
onAdd?: (p: SnapshotProduct) => void;
}) {
const locale = useLocale() as Locale;
const t = useTranslations('menu');
const [open, setOpen] = useState(false);
const [macrosOpen, setMacrosOpen] = useState(false);
const name = pickText(product.name, locale);
const description = pickText(product.description, locale);
const media = [...product.media].sort((a, b) => a.order - b.order);
const cover = media[0];
return (
<div className="glass-soft overflow-hidden rounded-2xl">
<button
onClick={() => setOpen((o) => !o)}
aria-expanded={open}
className="flex w-full items-center gap-3 px-4 py-3 text-left"
>
<span className="display min-w-0 flex-1 font-medium">{name}</span>
<span className="shrink-0 font-semibold text-[var(--accent)]">${product.price.toFixed(2)}</span>
<span className={`shrink-0 text-[var(--text)]/40 transition-transform ${open ? 'rotate-180' : ''}`}>
⌄
</span>
</button>
{/* allergen tags visible at a glance in the collapsed row */}
{product.allergens.length > 0 && (
<div className="-mt-1 flex flex-wrap gap-1.5 px-4 pb-2.5">
{product.allergens.map((a) => (
<span key={a} className="rounded-full bg-amber-100/60 px-2 py-0.5 text-[11px] text-amber-800">
{a}
</span>
))}
</div>
)}
{open && (
<div className="animate-fade-up flex flex-col gap-3 px-4 pb-4">
<button
onClick={() => showMacros && setMacrosOpen((m) => !m)}
className="relative block overflow-hidden rounded-xl"
aria-label={showMacros ? t('tapToFlip') : name}
>
<MediaThumb media={cover} alt={name} className="h-44 w-full" />
{showMacros && (
<span className="glass-pill absolute bottom-2 right-2 rounded-full px-2 py-0.5 text-[11px]">
{t('tapToFlip')}
</span>
)}
</button>
{description && <p className="text-sm text-[var(--text)]/75">{description}</p>}
{product.dietTags.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{product.dietTags.map((tag) => (
<span key={tag} className="glass-soft rounded-full px-2 py-0.5 text-[11px]">
{tag}
</span>
))}
</div>
)}
{showMacros && macrosOpen && <MacrosBack macros={product.macros} />}
{ordersEnabled && onAdd && (
<button
onClick={() => onAdd(product)}
className="rounded-2xl bg-[var(--accent)] py-2 text-sm font-medium text-white"
>
{t('addToOrder')}
</button>
)}
</div>
)}
</div>
);
}
+43 -3
View File
@@ -7,10 +7,13 @@ import type { MenuSnapshot, SnapshotProduct } from '@/lib/types';
import { pickText } from '@/lib/text';
import LanguageSwitch from '@/components/LanguageSwitch';
import DishCard from './DishCard';
import ListRow from './ListRow';
import MacroLegend from './MacroLegend';
import Gallery from './Gallery';
import AiConsultant from './AiConsultant';
type ViewMode = 'cards' | 'list';
type CartLine = { product: SnapshotProduct; qty: number };
export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: string }) {
@@ -35,9 +38,12 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
const [orderOpen, setOrderOpen] = useState(false);
const [waiterOpen, setWaiterOpen] = useState(false);
const [toast, setToast] = useState<string | null>(null);
// View preference is intentionally not persisted — always starts on cards.
const [view, setView] = useState<ViewMode>('cards');
const sectionRefs = useRef<Record<string, HTMLElement | null>>({});
const ordersEnabled = menu.restaurant.ordersEnabled;
const showMacros = menu.restaurant.showMacros;
function scrollToSection(id: string) {
setActiveSection(id);
@@ -85,8 +91,27 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
</nav>
)}
<div className="mb-4">
<MacroLegend />
{/* View toggle (cards vs traditional list). Not persisted. */}
<div className="mb-4 flex items-center justify-end gap-3">
{showMacros && <div className="min-w-0 flex-1"><MacroLegend /></div>}
<div className="glass-pill inline-flex shrink-0 rounded-full p-1 text-sm">
<button
onClick={() => setView('cards')}
className={`rounded-full px-3 py-1 font-medium transition ${
view === 'cards' ? 'bg-white/70 text-[var(--text)] shadow' : 'text-[var(--text)]/60'
}`}
>
{t('viewCards')}
</button>
<button
onClick={() => setView('list')}
className={`rounded-full px-3 py-1 font-medium transition ${
view === 'list' ? 'bg-white/70 text-[var(--text)] shadow' : 'text-[var(--text)]/60'
}`}
>
{t('viewList')}
</button>
</div>
</div>
{/* Sections */}
@@ -101,6 +126,18 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
<h2 className="display mb-3 text-xl font-semibold">{pickText(s.name, locale)}</h2>
{s.products.length === 0 ? (
<p className="text-sm text-[var(--text)]/50">{t('empty')}</p>
) : view === 'list' ? (
<div className="flex flex-col gap-2">
{s.products.map((p) => (
<ListRow
key={p.id}
product={p}
showMacros={showMacros}
ordersEnabled={ordersEnabled}
onAdd={ordersEnabled ? addToCart : undefined}
/>
))}
</div>
) : (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
{s.products.map((p, i) => (
@@ -111,6 +148,7 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
onOpenGallery={setGallery}
onAdd={ordersEnabled ? addToCart : undefined}
ordersEnabled={ordersEnabled}
showMacros={showMacros}
/>
))}
</div>
@@ -171,7 +209,9 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
</div>
{/* Modals */}
{gallery && <Gallery product={gallery} onClose={() => setGallery(null)} />}
{gallery && (
<Gallery product={gallery} onClose={() => setGallery(null)} showMacros={showMacros} />
)}
{aiOpen && <AiConsultant slug={slug} onClose={() => setAiOpen(false)} />}
{orderOpen && (
<OrderPanel
+1
View File
@@ -32,6 +32,7 @@ export async function buildSnapshot(restaurantId: string): Promise<MenuSnapshot>
palette: (restaurant.palette as Palette) ?? {},
ordersEnabled: restaurant.ordersEnabled,
defaultLocale: restaurant.defaultLocale as Locale,
showMacros: restaurant.showMacros,
},
sections: sections.map(
(s): SnapshotSection => ({
+1
View File
@@ -35,6 +35,7 @@ export type MenuSnapshot = {
palette: Palette;
ordersEnabled: boolean;
defaultLocale: Locale;
showMacros: boolean;
};
sections: SnapshotSection[];
};