@wordpress/block-library
Version:
Block library for the WordPress editor.
34 lines (33 loc) • 1.44 kB
JavaScript
import { useBlockProps } from "@wordpress/block-editor";
import { useSelect } from "@wordpress/data";
import { __, _n, sprintf } from "@wordpress/i18n";
import { store } from "@wordpress/core-data";
import { usePostCommentsCount } from "../utils/hooks.mjs";
import { jsx } from "react/jsx-runtime";
// packages/block-library/src/post-comments-link/edit.jsx
function PostCommentsLinkEdit({ context }) {
const { postType, postId } = context;
const { totalItems: commentsCount } = usePostCommentsCount(postId);
const blockProps = useBlockProps();
const post = useSelect((select) => select(store).getEditedEntityRecord("postType", postType, postId), [postType, postId]);
let commentsText;
if (commentsCount !== null) {
const commentsNumber = parseInt(commentsCount);
if (commentsNumber === 0) commentsText = __("No comments");
else commentsText = sprintf(_n("%s comment", "%s comments", commentsNumber), commentsNumber.toLocaleString());
}
return /* @__PURE__ */ jsx("div", {
...blockProps,
children: post?.link && commentsText !== void 0 ? /* @__PURE__ */ jsx("a", {
href: post?.link + "#comments",
onClick: (event) => event.preventDefault(),
children: commentsText
}) : /* @__PURE__ */ jsx("a", {
href: "#post-comments-link-pseudo-link",
onClick: (event) => event.preventDefault(),
children: __("No comments")
})
});
}
export { PostCommentsLinkEdit as default };
//# sourceMappingURL=edit.mjs.map