synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
152 lines (151 loc) • 6.18 kB
JavaScript
import { jsx as o, Fragment as p, jsxs as t } from "react/jsx-runtime";
import "../../synapse-client/SynapseClient.js";
import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode";
import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse";
import "@sage-bionetworks/synapse-client/util/SynapseClientError";
import { ObjectType as D } from "@sage-bionetworks/synapse-types";
import "../../utils/functions/EntityTypeUtils.js";
import { copyStringToClipboard as I } from "../../utils/functions/StringUtils.js";
import "../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../utils/PermissionLevelToAccessType.js";
import { useState as c, useRef as M, useEffect as x } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Box as T } from "@mui/material";
import "../../utils/hooks/useCookiePreferences.js";
import "../../utils/hooks/useSourceAppConfigs.js";
import "universal-cookie";
import "../../utils/AppUtils/session/ApplicationSessionContext.js";
import "../../utils/context/FullContextProvider.js";
import "../../utils/context/DocumentMetadataContext.js";
import '../../style/components/_spinner.css';/* empty css */
import "@tanstack/query-core";
import "lodash-es/isEmpty";
import "lodash-es/isEqual";
import "lodash-es/xorWith";
import "react-router";
import "@sage-bionetworks/synapse-client";
import "../../utils/types/IsType.js";
import E from "../../synapse-queries/entity/useEntityBundle.js";
import { useGetCurrentUserProfile as S } from "../../synapse-queries/user/useUserBundle.js";
import { useGetReply as B, useDeleteReply as U } from "../../synapse-queries/forum/useReply.js";
import { formatDate as j } from "../../utils/functions/DateFormatter.js";
import v from "dayjs";
import m from "../IconSvg/IconSvg.js";
import { Markdown as A } from "../Markdown/MarkdownSynapse.js";
import { SkeletonTable as Y } from "../Skeleton/SkeletonTable.js";
import { WarningDialog as P } from "../SynapseForm/WarningDialog.js";
import { displayToast as u } from "../ToastMessage/ToastMessage.js";
import { UserBadge as $ } from "../UserCard/UserBadge.js";
import { ForumThreadEditor as L } from "./ForumThreadEditor.js";
import { REPLY_ID_PARAM_KEY as f } from "./DiscussionConstants.js";
const _ = (i) => {
const n = `${`${window.location.origin}${window.location.pathname}`}?${f}=${i}`;
I(n).then(
() => u("Reply link copied to clipboard", "info")
);
};
function Ue(i) {
const { reply: e, isReplyAuthorModerator: n = !1 } = i, [y, d] = c(!1), [h, l] = c(!1), { data: b } = S(), { data: w } = E(e.projectId), { data: s, isLoading: C } = B(e), r = M(null), { mutate: g } = U({
onSuccess: () => {
l(!1), u("A reply has been deleted.", "info");
}
}), R = e.createdBy == b?.ownerId;
return x(() => {
const k = new URLSearchParams(window.location.search).get(f);
let a;
return k === e.id && r.current && (r.current.style.transition = "background-color 1s ease", r.current.style.backgroundColor = "#fbf4e0", r.current.style.borderColor = "#f4dda3", a = setTimeout(() => {
r.current && (r.current.style.backgroundColor = "#f9f9f9", r.current.style.borderColor = "#ccc");
}, 2e3)), () => {
a && clearTimeout(a);
};
}, [e.id]), /* @__PURE__ */ o(
"div",
{
className: "reply-container",
id: `reply._${e.id}`,
ref: r,
role: "article",
children: C ? /* @__PURE__ */ o(Y, { numCols: 1, numRows: 4 }) : /* @__PURE__ */ o(p, { children: s && /* @__PURE__ */ t(p, { children: [
/* @__PURE__ */ t("div", { children: [
/* @__PURE__ */ o(
$,
{
userId: e.createdBy,
withAvatar: !0,
avatarSize: "MEDIUM",
showCardOnHover: !0,
showModeratorBadge: n
}
),
/* @__PURE__ */ t("div", { className: "message-body", children: [
/* @__PURE__ */ o(
A,
{
markdown: s,
objectType: D.REPLY
}
),
/* @__PURE__ */ t("span", { children: [
"posted ",
j(v(e.createdOn), "M/D/YYYY"),
e.isEdited ? /* @__PURE__ */ o("i", { children: " (Edited)" }) : null
] }),
/* @__PURE__ */ t(
T,
{
sx: {
display: "flex",
justifyContent: "flex-end",
marginTop: { xs: "8px", sm: 0 },
float: { sm: "right" }
},
children: [
/* @__PURE__ */ o("button", { onClick: () => _(e.id), children: /* @__PURE__ */ o(m, { icon: "link", label: "Copy link to this reply" }) }),
R && /* @__PURE__ */ o("button", { onClick: () => d(!0), children: /* @__PURE__ */ o(m, { icon: "edit", label: "Edit reply" }) }),
w?.permissions.canModerate && /* @__PURE__ */ o("button", { onClick: () => l(!0), children: /* @__PURE__ */ o(m, { icon: "delete", label: "Delete reply" }) })
]
}
)
] })
] }),
/* @__PURE__ */ o(
L,
{
isReply: !0,
initialText: s,
onClose: () => d(!1),
id: e.id,
isDialog: !0,
openDialog: y
}
),
/* @__PURE__ */ o(
P,
{
open: h,
title: "Confirm Deletion",
content: "Are you sure you want to delete this reply?",
onCancel: () => {
l(!1);
},
onConfirm: () => g({
forumId: e.forumId,
threadId: e.threadId,
replyId: e.id
}),
confirmButtonColor: "error",
confirmButtonText: "Delete"
}
)
] }) })
}
);
}
export {
Ue as DiscussionReply
};
//# sourceMappingURL=DiscussionReply.js.map