import { useState, type FormEvent } from "react"; import { useMutation } from "@tanstack/react-query"; import { api, errMsg } from "../api"; import { pasteImage } from "../paste"; // PostForm verfasst einen Beitrag, mit replyTo eine Antwort darauf. export function PostForm({ replyTo, rows, placeholder, submitLabel, fallback, onDone }: { replyTo?: string; rows: number; placeholder: string; submitLabel: string; fallback: string; onDone: () => void; }) { const [pasteMsg, setPasteMsg] = useState(""); const create = useMutation({ mutationFn: (fd: FormData) => api.post("/entry/create", fd), }); const onSubmit = (e: FormEvent) => { e.preventDefault(); const form = e.currentTarget; const fd = new FormData(form); if (replyTo) fd.append("reply_to", replyTo); create.mutate(fd, { onSuccess: () => { form.reset(); setPasteMsg(""); onDone(); }, }); }; return ( <>
{ if (pasteImage(e)) setPasteMsg("Bild aus Zwischenablage übernommen."); }} > {" "}

{pasteMsg}

{" "} {" "}

{create.isError ? errMsg(create.error, fallback) : ""}

); }