diff --git a/CLAUDE.md b/CLAUDE.md
index 8c01f70..a1819fc 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -7,7 +7,7 @@
> **Plattform:** Olares One (Kubernetes), Repo und CI auf Gitea — kein Supabase,
> kein Vercel (E-0001). Eigene Gestaltung, nicht AImighty (E-0002).
> Verteilung über den Markt, Repo öffentlich (E-0005).
-> **Status:** 26.11.44 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut:
+> **Status:** 26.11.45 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut:
> Anmeldung (Passkeys, Kinder mit Gerät + PIN), Gerichte (Link, Kochbuchfoto, AI über den
> Olares Router), Wünschen, Plan, Einkaufsliste (Echtzeit, offline), Kochmodus mit
> Bewertung, Web-App; Einzahl bei Stück-Mengen (26.11.15), Preise und Kosten mit Ampel
@@ -21,9 +21,10 @@
> eigene Zutaten und Lieblingsprodukt je Haushalt (26.11.38, E-0015), Löffel und Gebinde
> (26.11.39, E-0016), Anmelden per Mail-Link über Resend (26.11.40, E-0017; nur
> anmelden, keine Geräte oder Passkeys aus einer Mail-Sitzung), Leiste bleibt nach der
-> Tastatur unten (26.11.41), Icon Kochmütze mit Herz (26.11.42), Fotos aus der Mediathek (26.11.43), gleich große Karten (26.11.44). Offen: Kai trägt
-> den Resend-Schlüssel unter Mehr › Mails verschicken ein.
-> **Letzte Aktualisierung:** 7. November 2026
+> Tastatur unten (26.11.41), Icon Kochmütze mit Herz (26.11.42), Fotos aus der Mediathek (26.11.43), gleich große Karten (26.11.44), Runde beenden/löschen/ändern,
+> Tage je Gericht von Hand und Kalender-Abo je Haushalt (26.11.45, E-0018). Offen: Kai trägt
+> den Resend-Schlüssel unter Mehr › Mails verschicken ein und abonniert den Kalender-Link einmal auf dem iPhone.
+> **Letzte Aktualisierung:** 8. November 2026
Diese Datei ist das Gedächtnis jeder Sitzung. Entscheidungen stehen in
`docs/entscheidungen.md` und gelten vor dem Konzept. Bei Unsicherheit: stoppen
diff --git a/OlaresManifest.yaml b/OlaresManifest.yaml
index 3f2fa84..9baccd1 100644
--- a/OlaresManifest.yaml
+++ b/OlaresManifest.yaml
@@ -21,7 +21,7 @@ metadata:
title: foodplanhero
description: Plan. Cook. Smile. The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box.
icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
- version: 26.11.44
+ version: 26.11.45
categories:
- Applications
@@ -61,7 +61,7 @@ permission:
appData: true
spec:
- versionName: '26.11.44'
+ versionName: '26.11.45'
featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png
promoteImage:
diff --git a/app/(app)/mehr/page.tsx b/app/(app)/mehr/page.tsx
index 19fe7b4..1e5e708 100644
--- a/app/(app)/mehr/page.tsx
+++ b/app/(app)/mehr/page.tsx
@@ -13,6 +13,7 @@ import { aiFor } from "@/lib/ai-settings";
import { InstallHint } from "@/components/install-hint";
import { BudgetSettings } from "@/components/more/budget-settings";
import { MailSignIn } from "@/components/more/mail-sign-in";
+import { CalendarSettings } from "@/components/more/calendar-settings";
import { can, WITH_PASSKEY } from "@/lib/auth/roles";
import { withHousehold } from "@/lib/db";
import { isLocale } from "@/lib/locale";
@@ -32,7 +33,7 @@ export default async function MorePage() {
const t = await getTranslations("more");
const tc = await getTranslations("costs.settings");
const locale = await getLocale();
- const { members, passkeys, founder, kids, kidDevices, money, mail, dedication } = await withHousehold(session.householdId, async (client) => {
+ const { members, passkeys, founder, kids, kidDevices, money, mail, calendar, dedication } = await withHousehold(session.householdId, async (client) => {
const members = (await client.query("select id, display_name, role from members order by created_at")).rows;
const founder = (await client.query("select created_by from households")).rows[0]?.created_by as string | null;
const passkeys = (
@@ -58,7 +59,10 @@ export default async function MorePage() {
).rows[0]?.email as string | undefined;
const sending = (await client.query("select from_address from household_mail where password_enc is not null")).rows[0]?.from_address as string | undefined;
const mail = { verified: me?.verified ? (me.email as string) : null, pending: pending ?? null, sending: sending ?? null };
- return { members, passkeys, founder, kids, kidDevices, money, mail, dedication: await getDedication(client) };
+ const calendar = (
+ await client.query("select calendar_token_hash is not null as active, to_char(meal_time, 'HH24:MI') as time, meal_minutes as minutes from households")
+ ).rows[0] as { active: boolean; time: string; minutes: number };
+ return { members, passkeys, founder, kids, kidDevices, money, mail, calendar, dedication: await getDedication(client) };
});
const aiReady = !!(await aiFor(session.householdId));
const date = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
@@ -140,6 +144,12 @@ export default async function MorePage() {
>
) : null}
+ {session.role === "admin" ? (
+
- {[t("portions", { n: next.portions }), next.cookName ? t("cook", { name: next.cookName }) : null].filter(Boolean).join(" · ")} + {[dayLabel(next.plannedDay, locale), t("portions", { n: next.portions }), next.cookName ? t("cook", { name: next.cookName }) : null].filter(Boolean).join(" · ")}
{t("noRound")}
diff --git a/app/api/household/calendar/route.ts b/app/api/household/calendar/route.ts new file mode 100644 index 0000000..d771d0b --- /dev/null +++ b/app/api/household/calendar/route.ts @@ -0,0 +1,53 @@ +import { getLocale } from "next-intl/server"; +import { z } from "zod"; +import { newCalendarToken, removeCalendarToken } from "@/lib/auth/calendar"; +import { guardWrite, isResponse, noMailSession } from "@/lib/auth/guard"; +import { fail, json, readJson } from "@/lib/auth/http"; +import { withAuth, withHousehold } from "@/lib/db"; +import { loadInstance } from "@/lib/auth/webauthn"; + +export const dynamic = "force-dynamic"; + +// Kalender-Abo (26.11.45), nur für Admins und nie aus einer Mail-Sitzung: Der +// Link zeigt den Plan jedem, der ihn hat. +async function admin(request: Request) { + const session = await guardWrite(request, ["admin"]); + if (isResponse(session)) return session; + return noMailSession(session) ?? session; +} + +/** Neuen Link erzeugen (auch: den alten ersetzen). Der Link kommt nur hier einmal heraus. */ +export async function POST(request: Request) { + const session = await admin(request); + if (isResponse(session)) return session; + const locale = await getLocale(); + const token = await withHousehold(session.householdId, (c) => newCalendarToken(c, session.householdId, locale)); + const instance = await withAuth(loadInstance); + const url = `${instance!.origin}/kalender/${token}.ics`; + return json({ url }, 201); +} + +const timeInput = z.object({ + mealTime: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/), + mealMinutes: z.number().int().min(15).max(240), +}); + +/** Essenszeit für die Termine. */ +export async function PATCH(request: Request) { + const session = await admin(request); + if (isResponse(session)) return session; + const body = timeInput.safeParse(await readJson(request)); + if (!body.success) return fail("invalid", 400); + await withHousehold(session.householdId, (c) => + c.query("update households set meal_time = $2, meal_minutes = $3 where id = $1", [session.householdId, body.data.mealTime, body.data.mealMinutes]), + ); + return json({ ok: true }); +} + +/** Abo beenden: Der Link gilt nicht mehr. */ +export async function DELETE(request: Request) { + const session = await admin(request); + if (isResponse(session)) return session; + await withHousehold(session.householdId, (c) => removeCalendarToken(c, session.householdId)); + return json({ ok: true }); +} diff --git a/app/api/plan/slots/route.ts b/app/api/plan/slots/route.ts index 42aa32a..5154479 100644 --- a/app/api/plan/slots/route.ts +++ b/app/api/plan/slots/route.ts @@ -12,6 +12,8 @@ const change = z.object({ portions: z.number().int().min(1).max(30).optional(), cookMemberId: id.nullable().optional(), locked: z.boolean().optional(), + // Wochentag von Hand (26.11.45); null nimmt ihn weg. + plannedDay: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable().optional(), }); async function dishExists(c: import("pg").PoolClient, dishId: string) { diff --git a/app/api/rounds/delete/route.ts b/app/api/rounds/delete/route.ts new file mode 100644 index 0000000..97d868c --- /dev/null +++ b/app/api/rounds/delete/route.ts @@ -0,0 +1,24 @@ +import { guardWrite, isResponse } from "@/lib/auth/guard"; +import { fail, json } from "@/lib/auth/http"; +import { withHousehold } from "@/lib/db"; +import { currentRound, deleteRound, RoundHasCooked } from "@/lib/rounds"; + +export const dynamic = "force-dynamic"; + +// Runde ganz löschen (26.11.45) — nur solange nichts gekocht ist. Wünsche, +// Plan und Einkaufsliste gehen mit (on delete cascade). +export async function POST(request: Request) { + const session = await guardWrite(request); + if (isResponse(session)) return session; + return withHousehold(session.householdId, async (c) => { + const round = await currentRound(c); + if (!round) return fail("noRound", 409); + try { + await deleteRound(c, round.id); + } catch (error) { + if (error instanceof RoundHasCooked) return fail("cooked", 409); + throw error; + } + return json({ ok: true }); + }); +} diff --git a/app/api/rounds/end/route.ts b/app/api/rounds/end/route.ts new file mode 100644 index 0000000..851a98f --- /dev/null +++ b/app/api/rounds/end/route.ts @@ -0,0 +1,18 @@ +import { guardWrite, isResponse } from "@/lib/auth/guard"; +import { fail, json } from "@/lib/auth/http"; +import { withHousehold } from "@/lib/db"; +import { currentRound, endRound } from "@/lib/rounds"; + +export const dynamic = "force-dynamic"; + +// Runde beenden (26.11.45): Gekochtes bleibt Geschichte, danach ist Platz für die nächste. +export async function POST(request: Request) { + const session = await guardWrite(request); + if (isResponse(session)) return session; + return withHousehold(session.householdId, async (c) => { + const round = await currentRound(c); + if (!round) return fail("noRound", 409); + await endRound(c, round.id); + return json({ ok: true }); + }); +} diff --git a/app/api/rounds/route.ts b/app/api/rounds/route.ts index 70ff0c2..b830c4b 100644 --- a/app/api/rounds/route.ts +++ b/app/api/rounds/route.ts @@ -1,7 +1,9 @@ import { guardWrite, isResponse } from "@/lib/auth/guard"; import { fail, json, readJson } from "@/lib/auth/http"; import { withHousehold } from "@/lib/db"; -import { openRound, RoundExists, roundInput } from "@/lib/rounds"; +import { getLocale } from "next-intl/server"; +import { currentRound, openRound, RoundExists, roundInput, updateRound } from "@/lib/rounds"; +import { syncList } from "@/lib/shopping"; export const dynamic = "force-dynamic"; @@ -19,3 +21,21 @@ export async function POST(request: Request) { throw error; } } + +// Einstellungen der laufenden Runde ändern (26.11.45). Vorhandene Gerichte bleiben; +// die Einkaufsliste rechnet sich neu, wenn es sie schon gibt. +export async function PATCH(request: Request) { + const session = await guardWrite(request); + if (isResponse(session)) return session; + const body = roundInput.safeParse(await readJson(request)); + if (!body.success) return fail("invalid", 400); + const locale = await getLocale(); + return withHousehold(session.householdId, async (c) => { + const round = await currentRound(c); + if (!round) return fail("noRound", 409); + await updateRound(c, round.id, body.data); + const next = await currentRound(c); + if (next && next.status !== "open") await syncList(c, session.householdId, next, locale); + return json({ ok: true }); + }); +} diff --git a/app/kalender/[token]/route.ts b/app/kalender/[token]/route.ts new file mode 100644 index 0000000..9ef2cef --- /dev/null +++ b/app/kalender/[token]/route.ts @@ -0,0 +1,54 @@ +import { getTranslations } from "next-intl/server"; +import { householdForCalendar } from "@/lib/auth/calendar"; +import { clientIp } from "@/lib/auth/request"; +import { loadInstance } from "@/lib/auth/webauthn"; +import { buildCalendar, type CalendarEvent } from "@/lib/calendar"; +import { withAuth, withHousehold } from "@/lib/db"; + +export const dynamic = "force-dynamic"; + +// Kalender-Abo (26.11.45): öffentlich, aber nur mit gültigem Link. Nur lesend, +// nur Titel, Tag, Koch und Portionen — keine Zutaten, keine Wünsche. +export async function GET(request: Request, { params }: { params: Promise<{ token: string }> }) { + const raw = (await params).token.replace(/\.ics$/, ""); + const notFound = () => new Response("Not found", { status: 404, headers: { "cache-control": "no-store" } }); + if (!/^[A-Za-z0-9_-]{43}$/.test(raw)) return notFound(); + const found = await householdForCalendar(raw, clientIp(request)); + if (found === "tooMany") return new Response("Too many requests", { status: 429, headers: { "retry-after": "900" } }); + if (!found) return notFound(); + + const instance = await withAuth(loadInstance); + const { household, slots } = await withHousehold(found.id, async (c) => ({ + household: ( + await c.query("select name, to_char(meal_time, 'HH24:MI') as time, meal_minutes as minutes, calendar_locale as locale from households where id = $1", [found.id]) + ).rows[0] as { name: string; time: string; minutes: number; locale: string }, + // Laufende Runde und was in den letzten 60 Tagen einen Tag hatte. + slots: ( + await c.query( + `select s.id, to_char(s.planned_day, 'YYYY-MM-DD') as day, s.portions, d.id as "dishId", d.title, m.display_name as cook + from slots s join dishes d on d.id = s.dish_id left join members m on m.id = s.cook_member_id + where s.planned_day is not null and s.planned_day >= current_date - 60 + order by s.planned_day, s.position`, + ) + ).rows as { id: string; day: string; portions: number; dishId: string; title: string; cook: string | null }[], + })); + const t = await getTranslations({ locale: household.locale, namespace: "calendar" }); + const events: CalendarEvent[] = slots.map((s) => ({ + uid: `${s.id}@foodplanhero`, + day: s.day, + start: household.time, + minutes: household.minutes, + summary: s.title, + description: [s.cook ? t("cook", { name: s.cook }) : null, t("portions", { n: s.portions }), instance ? t("open", { url: `${instance.origin}/gerichte/${s.dishId}` }) : null] + .filter(Boolean) + .join("\n"), + url: instance ? `${instance.origin}/gerichte/${s.dishId}` : null, + })); + return new Response(buildCalendar(t("name", { household: household.name }), events), { + headers: { + "content-type": "text/calendar; charset=utf-8", + "content-disposition": 'inline; filename="foodplanhero.ics"', + "cache-control": "private, max-age=900", + }, + }); +} diff --git a/app/kueche/page.tsx b/app/kueche/page.tsx index 8e589e5..0c2baa0 100644 --- a/app/kueche/page.tsx +++ b/app/kueche/page.tsx @@ -1,13 +1,14 @@ import { ChefHat } from "lucide-react"; import Link from "next/link"; import { redirect } from "next/navigation"; -import { getTranslations } from "next-intl/server"; +import { getLocale, getTranslations } from "next-intl/server"; import { DishPhoto } from "@/components/dishes/dish-tile"; import { AutoRefresh } from "@/components/kitchen/auto-refresh"; import { currentKitchenDisplay } from "@/lib/auth/kids"; import { getSession } from "@/lib/auth/session"; import { withHousehold } from "@/lib/db"; import { kitchenOverview } from "@/lib/kitchen"; +import { dayLabel } from "@/lib/plan"; export const dynamic = "force-dynamic"; @@ -19,6 +20,7 @@ export default async function KitchenPage() { const t = await getTranslations("kitchen"); const { next, dishes } = await withHousehold(device.householdId, kitchenOverview); const [today, ...later] = next; + const locale = await getLocale(); return ({dayLabel(today.plannedDay, locale)}
: null}{today.title}
{today.cookName ? t("portionsCook", { n: today.portions, name: today.cookName }) : t("portions", { n: today.portions })}
diff --git a/components/more/calendar-settings.tsx b/components/more/calendar-settings.tsx
new file mode 100644
index 0000000..bfb19b1
--- /dev/null
+++ b/components/more/calendar-settings.tsx
@@ -0,0 +1,126 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { useTranslations } from "next-intl";
+import { useState } from "react";
+import { Button, buttonVariants } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { ErrorNotice } from "@/components/ui/notice";
+import { cn } from "@/lib/utils";
+
+async function call(method: string, body?: object) {
+ const res = await fetch("/api/household/calendar", { method, headers: { "content-type": "application/json" }, body: body ? JSON.stringify(body) : undefined });
+ return { ok: res.ok, data: await res.json().catch(() => ({})) };
+}
+
+// Kalender abonnieren (26.11.45): Essenszeit, Link erzeugen, ersetzen, beenden.
+// Der Link steht nur einmal da — gespeichert ist nur sein Hash.
+export function CalendarSettings({ active, mealTime, mealMinutes, locked }: { active: boolean; mealTime: string; mealMinutes: number; locked: boolean }) {
+ const t = useTranslations("more.calendar");
+ const router = useRouter();
+ const [time, setTime] = useState(mealTime);
+ const [minutes, setMinutes] = useState(String(mealMinutes));
+ const [url, setUrl] = useState {t("locked")} {t("hint")} {t("renewHint")}
{days.find((d) => d.value === slot.plannedDay)?.label}
: null} {cooked ?{t("cooked")}
: null}{t("hint")}
+ {current ? null :{t("hint")}
} {error ?