"use client"; import { useState } from "react"; import { useTranslations } from "next-intl"; import { Lock } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; export function RecipeNotes({ recipeId, initialContent, }: { recipeId: string; initialContent: string; }) { const t = useTranslations("recipeNotes"); const [content, setContent] = useState(initialContent); const [savedContent, setSavedContent] = useState(initialContent); const [saving, setSaving] = useState(false); const dirty = content !== savedContent; async function save() { setSaving(true); try { const res = await fetch(`/api/v1/recipes/${recipeId}/notes`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ content }), }); if (!res.ok) { toast.error(t("saveFailed")); return; } const data = (await res.json()) as { note: { content: string } | null }; const newContent = data.note?.content ?? ""; setContent(newContent); setSavedContent(newContent); toast.success(t("saved")); } finally { setSaving(false); } } return (
{t("visibilityHint")}