Today shows admins a self-ticking checklist (five dishes, main store, family, first round) with one button for the current step, every person the stage of the round with their next step, and new members three short cards once. The logic is pure and tested in lib/onboarding.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
82 lines
3.8 KiB
TypeScript
82 lines
3.8 KiB
TypeScript
// Führung durch die App (Kai, 7.11.2026: „Man weiß nicht, was man zuerst machen muss“).
|
|
// Rein, ohne Datenbank: Die Seite „Heute“ sammelt die Fakten, hier wird entschieden.
|
|
// 1. „Los geht's“ (Admins): Gerichte → Laden → Familie → erste Runde, aus den Daten abgehakt.
|
|
// 2. „Wo stehen wir?“ (alle): Wünschen → Planen → Einkaufen → Kochen → Bewerten.
|
|
|
|
export const POOL_GOAL = 5;
|
|
|
|
export type SetupFacts = {
|
|
poolDishes: number;
|
|
hasStore: boolean;
|
|
people: number; // ohne Gäste, mit mir
|
|
openInvites: number;
|
|
rounds: number; // je eröffnete Runden
|
|
skipped: string[]; // households.onboarding.skipped
|
|
};
|
|
|
|
export type SetupKey = "dishes" | "store" | "family" | "round";
|
|
export type SetupStep = { key: SetupKey; done: boolean; skipped?: boolean; n?: number; of?: number };
|
|
|
|
export function setupSteps(f: SetupFacts): SetupStep[] {
|
|
const familySkipped = f.skipped.includes("family");
|
|
return [
|
|
{ key: "dishes", done: f.poolDishes >= POOL_GOAL, n: Math.min(f.poolDishes, POOL_GOAL), of: POOL_GOAL },
|
|
{ key: "store", done: f.hasStore },
|
|
{ key: "family", done: f.people >= 2 || f.openInvites > 0 || familySkipped, skipped: familySkipped && f.people < 2 && f.openInvites === 0 },
|
|
{ key: "round", done: f.rounds > 0 },
|
|
];
|
|
}
|
|
|
|
/** Liste zeigen, einmal „Fertig“ zeigen, oder gar nicht (ausgeblendet oder schon bestätigt). */
|
|
export function checklistState(steps: SetupStep[], flags: { hidden: boolean; finishedSeen: boolean }): "show" | "finished" | "none" {
|
|
if (flags.hidden) return "none";
|
|
if (steps.every((s) => s.done)) return flags.finishedSeen ? "none" : "finished";
|
|
return "show";
|
|
}
|
|
|
|
export const STAGES = ["wish", "plan", "shop", "cook", "rate"] as const;
|
|
export type Stage = (typeof STAGES)[number];
|
|
|
|
export type RoundFacts = {
|
|
status: "open" | "planned" | "shopping" | "done" | null; // null: keine laufende Runde
|
|
slots: number;
|
|
cooked: number;
|
|
toRate: number; // offene Bewertungen dieser Person
|
|
};
|
|
|
|
/** Wo die Runde steht. Offene Bewertungen gehen vor; ohne Runde und ohne Bewertung: null. */
|
|
export function roundStage(f: RoundFacts): Stage | null {
|
|
if (f.toRate > 0 && (f.status === null || f.status === "done" || f.cooked > 0)) return "rate";
|
|
if (f.status === null || f.status === "done") return null;
|
|
if (f.status === "open") return f.slots > 0 ? "plan" : "wish";
|
|
if (f.cooked > 0 && f.cooked < f.slots) return "cook";
|
|
if (f.status === "shopping" && f.cooked === 0) return "shop";
|
|
return f.status === "planned" ? "shop" : "cook";
|
|
}
|
|
|
|
export type NextAction = { key: string; href: string | null; values?: Record<string, string | number> };
|
|
|
|
/** Der nächste Schritt *für diese Person*, je nach Rolle. */
|
|
export function nextAction(
|
|
stage: Stage | null,
|
|
who: { planner: boolean; shopper: boolean; cook: boolean; child: boolean },
|
|
extra: { tokensLeft: number; nextSlotId: string | null; nextTitle: string | null },
|
|
): NextAction {
|
|
switch (stage) {
|
|
case null:
|
|
return who.planner ? { key: "openRound", href: "/runde/neu" } : { key: "waitRound", href: null };
|
|
case "wish":
|
|
if (extra.tokensLeft > 0) return { key: "wish", href: "/wuenschen", values: { n: extra.tokensLeft } };
|
|
return who.planner ? { key: "makePlan", href: "/plan" } : { key: "wishedWait", href: null };
|
|
case "plan":
|
|
return who.planner ? { key: "approvePlan", href: "/plan" } : { key: "planComing", href: null };
|
|
case "shop":
|
|
return who.shopper ? { key: "shop", href: "/einkauf" } : { key: "shopping", href: null };
|
|
case "cook":
|
|
if (who.cook && extra.nextSlotId) return { key: "cook", href: `/kochen/${extra.nextSlotId}`, values: { title: extra.nextTitle ?? "" } };
|
|
return { key: "cookingSoon", href: null, values: { title: extra.nextTitle ?? "" } };
|
|
case "rate":
|
|
return { key: "rate", href: "#bewerten" };
|
|
}
|
|
}
|