synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
100 lines (99 loc) • 2.66 kB
JavaScript
import { jsx as n, Fragment as g, jsxs as f } from "react/jsx-runtime";
import { usePostReply as D, usePutReply as F } from "../../synapse-queries/forum/useReply.js";
import { useUpdateThreadTitle as W, useUpdateThreadMessage as q, useCreateThread as N } from "../../synapse-queries/forum/useThread.js";
import { Box as b, TextField as z } from "@mui/material";
import { useState as h } from "react";
import { ConfirmationDialog as A, ConfirmationButtons as G } from "../ConfirmationDialog/ConfirmationDialog.js";
import { MarkdownEditor as H } from "../Markdown/MarkdownEditor.js";
function Z(T) {
const {
initialText: a,
initialTitle: d,
id: o,
onClose: e,
isReply: i,
isDialog: P,
openDialog: y
} = T, [s, x] = h(d ?? ""), [r, C] = h(a ?? ""), { mutate: I, isPending: R } = W({
onSuccess: () => e()
}), { mutate: S, isPending: M } = q({
onSuccess: () => e()
}), { mutate: w, isPending: k } = N({
onSuccess: () => e()
}), { mutate: v, isPending: B } = D(
{
onSuccess: () => e()
}
), { mutate: E, isPending: U } = F({
onSuccess: () => e()
}), j = M || B || k || R || U, l = !i && d, c = (t, p) => {
i ? a ? E({
replyId: o,
messageMarkdown: t
}) : v({
threadId: o,
messageMarkdown: t
}) : l ? (I({
title: p,
threadId: o
}), S({
messageMarkdown: t,
threadId: o
})) : w({
forumId: o,
title: p,
messageMarkdown: t
});
}, m = /* @__PURE__ */ f("div", { children: [
!i && /* @__PURE__ */ n(
z,
{
fullWidth: !0,
sx: { my: 1 },
placeholder: "Title",
value: s,
onChange: (t) => x(t.target.value)
}
),
/* @__PURE__ */ n(
H,
{
placeholder: "Write a reply...",
text: r,
setText: C
}
)
] }), u = j ? "Saving" : "Post";
return /* @__PURE__ */ n(g, { children: P ? /* @__PURE__ */ n(
A,
{
maxWidth: "md",
open: y,
onCancel: e,
title: i ? "Edit Reply" : l ? "Edit Thread" : "New Thread",
content: m,
onConfirm: () => c(r, s),
confirmButtonProps: { children: u }
}
) : /* @__PURE__ */ f(g, { children: [
m,
/* @__PURE__ */ n(
b,
{
sx: { display: "flex", justifyContent: "flex-end", gap: 1, my: 1 },
children: /* @__PURE__ */ n(
G,
{
onCancel: e,
onConfirm: () => c(r, s),
confirmButtonProps: { children: u }
}
)
}
)
] }) });
}
export {
Z as ForumThreadEditor
};
//# sourceMappingURL=ForumThreadEditor.js.map