diff --git a/messages/en.json b/messages/en.json index 719d78c..2fa5f67 100644 --- a/messages/en.json +++ b/messages/en.json @@ -27,7 +27,9 @@ "waiterCalled": "The waiter is on the way", "orderSent": "Your order was sent", "macroLegend": "Macro color code", - "tapToFlip": "Tap to see macros" + "tapToFlip": "Tap to see macros", + "viewCards": "Cards", + "viewList": "List" }, "macros": { "protein": "Protein", @@ -85,7 +87,9 @@ "publicLink": "Public link", "copyLink": "Copy link", "copied": "Copied", - "paletteHint": "This does not affect the macro color code" + "paletteHint": "This does not affect the macro color code", + "showMacros": "Show macros on the menu", + "showMacrosHint": "When off, the public menu shows no macro layer at all." }, "qr": { "templates": "Templates", diff --git a/messages/es.json b/messages/es.json index e14b6ff..5fd9a1e 100644 --- a/messages/es.json +++ b/messages/es.json @@ -27,7 +27,9 @@ "waiterCalled": "El mesero va en camino", "orderSent": "Tu orden fue enviada", "macroLegend": "Código de color de macros", - "tapToFlip": "Toca para ver macros" + "tapToFlip": "Toca para ver macros", + "viewCards": "Tarjetas", + "viewList": "Lista" }, "macros": { "protein": "Proteína", @@ -85,7 +87,9 @@ "publicLink": "Link público", "copyLink": "Copiar link", "copied": "Copiado", - "paletteHint": "Esto no afecta el código de color de macros" + "paletteHint": "Esto no afecta el código de color de macros", + "showMacros": "Mostrar macros en el menú", + "showMacrosHint": "Si está apagado, el menú público no muestra ninguna capa de macros." }, "qr": { "templates": "Plantillas", diff --git a/prisma/migrations/0004_restaurant_show_macros/migration.sql b/prisma/migrations/0004_restaurant_show_macros/migration.sql new file mode 100644 index 0000000..40ca7d1 --- /dev/null +++ b/prisma/migrations/0004_restaurant_show_macros/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Restaurant" ADD COLUMN "showMacros" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dba2ca8..ff5cdd5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -20,6 +20,8 @@ model Restaurant { palette Json @default("{}") qrConfig Json @default("{}") // artistic QR styling (qr-code-styling config) ordersEnabled Boolean @default(false) + showMacros Boolean @default(false) // when false, the public menu hides all macro layers + defaultLocale String @default("es") active Boolean @default(true) publishedVersionId String? @unique diff --git a/src/app/[slug]/editor/page.tsx b/src/app/[slug]/editor/page.tsx index 9c8faa1..d25e179 100644 --- a/src/app/[slug]/editor/page.tsx +++ b/src/app/[slug]/editor/page.tsx @@ -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) ?? {}, diff --git a/src/app/[slug]/page.tsx b/src/app/[slug]/page.tsx index 5081bee..5269be9 100644 --- a/src/app/[slug]/page.tsx +++ b/src/app/[slug]/page.tsx @@ -21,11 +21,16 @@ async function getPublishedMenu(slug: string): Promise { 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 } }) { diff --git a/src/app/api/[slug]/menu/route.ts b/src/app/api/[slug]/menu/route.ts index 3d7d57a..7721636 100644 --- a/src/app/api/[slug]/menu/route.ts +++ b/src/app/api/[slug]/menu/route.ts @@ -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); } diff --git a/src/app/api/[slug]/settings/route.ts b/src/app/api/[slug]/settings/route.ts index ecad385..12d93c9 100644 --- a/src/app/api/[slug]/settings/route.ts +++ b/src/app/api/[slug]/settings/route.ts @@ -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; } diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx index facf47d..d7c2ad8 100644 --- a/src/components/editor/Editor.tsx +++ b/src/components/editor/Editor.tsx @@ -49,7 +49,13 @@ export default function Editor({ data, baseUrl }: { data: EditorData; baseUrl: s onRestored={(name) => setPublishedName(name)} /> )} - {tab === 'palette' && } + {tab === 'palette' && ( + + )} {tab === 'orders' && ( ⚠️ {t('paletteHint')}

+ {/* Show-macros toggle (controls whether the public menu exposes any macro layer) */} +
+
+
{t('showMacros')}
+
{t('showMacrosHint')}
+
+ +
+ - {ordersEnabled && onAdd && ( - - )} - + {(showMacros || (ordersEnabled && onAdd)) && ( +
+ {showMacros && ( + + )} + {ordersEnabled && onAdd && ( + + )} +
+ )} diff --git a/src/components/public/Gallery.tsx b/src/components/public/Gallery.tsx index b6f9830..6ccae0f 100644 --- a/src/components/public/Gallery.tsx +++ b/src/components/public/Gallery.tsx @@ -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({ )} - + {showMacros && } ); diff --git a/src/components/public/ListRow.tsx b/src/components/public/ListRow.tsx new file mode 100644 index 0000000..75e588d --- /dev/null +++ b/src/components/public/ListRow.tsx @@ -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 ( +
+ + + {/* allergen tags visible at a glance in the collapsed row */} + {product.allergens.length > 0 && ( +
+ {product.allergens.map((a) => ( + + {a} + + ))} +
+ )} + + {open && ( +
+ + + {description &&

{description}

} + + {product.dietTags.length > 0 && ( +
+ {product.dietTags.map((tag) => ( + + {tag} + + ))} +
+ )} + + {showMacros && macrosOpen && } + + {ordersEnabled && onAdd && ( + + )} +
+ )} +
+ ); +} diff --git a/src/components/public/PublicMenu.tsx b/src/components/public/PublicMenu.tsx index ebe9b3b..7e2d5ed 100644 --- a/src/components/public/PublicMenu.tsx +++ b/src/components/public/PublicMenu.tsx @@ -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(null); + // View preference is intentionally not persisted — always starts on cards. + const [view, setView] = useState('cards'); const sectionRefs = useRef>({}); 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 )} -
- + {/* View toggle (cards vs traditional list). Not persisted. */} +
+ {showMacros &&
} +
+ + +
{/* Sections */} @@ -101,6 +126,18 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s

{pickText(s.name, locale)}

{s.products.length === 0 ? (

{t('empty')}

+ ) : view === 'list' ? ( +
+ {s.products.map((p) => ( + + ))} +
) : (
{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} /> ))}
@@ -171,7 +209,9 @@ export default function PublicMenu({ menu, slug }: { menu: MenuSnapshot; slug: s
{/* Modals */} - {gallery && setGallery(null)} />} + {gallery && ( + setGallery(null)} showMacros={showMacros} /> + )} {aiOpen && setAiOpen(false)} />} {orderOpen && ( palette: (restaurant.palette as Palette) ?? {}, ordersEnabled: restaurant.ordersEnabled, defaultLocale: restaurant.defaultLocale as Locale, + showMacros: restaurant.showMacros, }, sections: sections.map( (s): SnapshotSection => ({ diff --git a/src/lib/types.ts b/src/lib/types.ts index f4ef079..05a4cda 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -35,6 +35,7 @@ export type MenuSnapshot = { palette: Palette; ordersEnabled: boolean; defaultLocale: Locale; + showMacros: boolean; }; sections: SnapshotSection[]; };