Neue Migration 0002_labeling_notice.sql: settings.labeling_mode
("detailed"/"notice") + labeling_notice(_en/_pl). Auf der Seite
"Allergene & Zusatzstoffe" (LabelingNoticeEditor) kann zwischen der
detaillierten Auswahl je Gericht und einem editierbaren Hinweistext
umgeschaltet werden. Im Hinweismodus entfällt auf der öffentlichen
Speisekarte (Desktop + Mobile) die Legende und die Kürzel an den
Gerichten, in der Gerichte-Verwaltung wird die Chip-Auswahl beim
Bearbeiten ausgeblendet. Umschalten/Bearbeiten ist für staff und admin
freigegeben, Farben in /api/settings bleiben admin-only.
Version 1.8.0.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
187 lines
5.8 KiB
TypeScript
187 lines
5.8 KiB
TypeScript
"use client";
|
||
|
||
// Mobile Ansicht der öffentlichen Speisekarte: Tag (Standard) oder Woche,
|
||
// umschaltbar ohne Seiten-Reload. Ab dem "sm"-Breakpoint übernimmt die
|
||
// normale Wochentabelle (siehe app/page.tsx), diese Komponente blendet
|
||
// sich dort per CSS aus.
|
||
|
||
import Link from "next/link";
|
||
import { useRouter } from "next/navigation";
|
||
import { useState } from "react";
|
||
import {
|
||
addDays,
|
||
dishCodes,
|
||
entriesFor,
|
||
formatDateLong,
|
||
formatPrice,
|
||
mondayOf,
|
||
todayISO,
|
||
weekdayIndex,
|
||
} from "@/lib/menu";
|
||
import { localized } from "@/lib/types";
|
||
import type { MenuEntry, Section } from "@/lib/types";
|
||
import { useDict, useLocale } from "@/components/i18n/LocaleProvider";
|
||
import LanguageSwitcher from "@/components/i18n/LanguageSwitcher";
|
||
|
||
export default function PublicMobileMenu({
|
||
monday,
|
||
sections,
|
||
entries,
|
||
showLabeling,
|
||
}: {
|
||
monday: string;
|
||
sections: Section[];
|
||
entries: MenuEntry[];
|
||
showLabeling: boolean;
|
||
}) {
|
||
const router = useRouter();
|
||
const dict = useDict();
|
||
const locale = useLocale();
|
||
const days = dict.weekdays.long.map((weekday, i) => ({
|
||
weekday,
|
||
short: dict.weekdays.short[i],
|
||
iso: addDays(monday, i),
|
||
}));
|
||
const isCurrentWeek = monday === mondayOf(todayISO());
|
||
const todayIdx = isCurrentWeek ? weekdayIndex(todayISO()) : -1;
|
||
|
||
const [tab, setTab] = useState<"tag" | "woche">("tag");
|
||
const [selectedIdx, setSelectedIdx] = useState(todayIdx >= 0 ? todayIdx : 0);
|
||
|
||
function goToday() {
|
||
const currentMonday = mondayOf(todayISO());
|
||
if (currentMonday === monday) {
|
||
const idx = weekdayIndex(todayISO());
|
||
setSelectedIdx(idx >= 0 ? idx : 0);
|
||
setTab("tag");
|
||
} else {
|
||
router.push(`/?woche=${currentMonday}`);
|
||
}
|
||
}
|
||
|
||
function renderDay(day: { weekday: string; iso: string }) {
|
||
return (
|
||
<div key={day.iso} className="mb-4 last:mb-0">
|
||
<h3 className="font-bold text-[var(--c-primary)] mb-2">
|
||
{day.weekday} · {formatDateLong(day.iso, dict.dateLocale)}
|
||
</h3>
|
||
<div className="space-y-3">
|
||
{sections.map((s) => {
|
||
const items = entriesFor(entries, day.iso, s.key);
|
||
return (
|
||
<div
|
||
key={s.key}
|
||
className="rounded-md border border-gray-200 overflow-hidden"
|
||
>
|
||
<div className="bg-[var(--c-primary)] text-[var(--c-header-text)] px-3 py-1.5 text-sm">
|
||
<span className="font-semibold">{localized(s, locale)}</span>{" "}
|
||
<span className="opacity-80">· {s.time_range}</span>
|
||
</div>
|
||
<div className="bg-[var(--c-row-bg)] px-3 py-2 text-sm">
|
||
{items.length === 0 ? (
|
||
<p className="text-gray-500">{dict.publicMenu.noEntry}</p>
|
||
) : (
|
||
items.map((e) => {
|
||
const codes = dishCodes(e.dish);
|
||
return (
|
||
<p key={e.id} className="mb-1 last:mb-0">
|
||
<span className="font-semibold">
|
||
{localized(e.dish, locale)}
|
||
</span>
|
||
{showLabeling && codes && (
|
||
<sup className="dish-codes">{codes}</sup>
|
||
)}{" "}
|
||
– {formatPrice(e.dish.price)}
|
||
</p>
|
||
);
|
||
})
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<div className="sm:hidden mb-6">
|
||
<div className="flex justify-end mb-3">
|
||
<LanguageSwitcher variant="light" />
|
||
</div>
|
||
|
||
<div className="flex gap-2 mb-3">
|
||
<Link
|
||
href={`/?woche=${addDays(monday, -7)}`}
|
||
className="btn btn-add flex-1 justify-center"
|
||
>
|
||
{dict.publicMenu.prevWeekShort}
|
||
</Link>
|
||
<button
|
||
type="button"
|
||
onClick={goToday}
|
||
className="btn btn-primary flex-1"
|
||
>
|
||
{dict.publicMenu.today}
|
||
</button>
|
||
<Link
|
||
href={`/?woche=${addDays(monday, 7)}`}
|
||
className="btn btn-add flex-1 justify-center"
|
||
>
|
||
{dict.publicMenu.nextWeekShort}
|
||
</Link>
|
||
</div>
|
||
|
||
<div className="flex gap-2 mb-3" role="tablist" aria-label="Ansicht">
|
||
<button
|
||
type="button"
|
||
role="tab"
|
||
aria-selected={tab === "tag"}
|
||
onClick={() => setTab("tag")}
|
||
className={`btn flex-1 ${tab === "tag" ? "btn-primary" : "btn-neutral"}`}
|
||
>
|
||
{dict.publicMenu.dayTab}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
role="tab"
|
||
aria-selected={tab === "woche"}
|
||
onClick={() => setTab("woche")}
|
||
className={`btn flex-1 ${tab === "woche" ? "btn-primary" : "btn-neutral"}`}
|
||
>
|
||
{dict.publicMenu.weekTab}
|
||
</button>
|
||
</div>
|
||
|
||
{tab === "tag" ? (
|
||
<>
|
||
<div className="flex gap-1 mb-3">
|
||
{days.map((d, i) => (
|
||
<button
|
||
key={d.iso}
|
||
type="button"
|
||
onClick={() => setSelectedIdx(i)}
|
||
className={`flex-1 rounded-md py-1.5 text-sm font-semibold border transition-colors ${
|
||
i === selectedIdx
|
||
? "bg-[var(--c-primary)] text-white border-[var(--c-primary)]"
|
||
: "bg-white text-gray-600 border-gray-200"
|
||
} ${i === todayIdx ? "ring-2 ring-[var(--c-accent)] ring-offset-1" : ""}`}
|
||
>
|
||
{d.short}
|
||
</button>
|
||
))}
|
||
</div>
|
||
{renderDay(days[selectedIdx])}
|
||
</>
|
||
) : (
|
||
<div>{days.map((d) => renderDay(d))}</div>
|
||
)}
|
||
|
||
<Link href="/vorschlag" className="btn btn-neutral w-full justify-center mt-2">
|
||
{dict.publicMenu.suggestDish}
|
||
</Link>
|
||
</div>
|
||
);
|
||
}
|