Toggle visibility of comment UI based on policy (#5143)

This commit is contained in:
Apoorv Mishra
2023-04-13 06:41:58 +05:30
committed by GitHub
parent 8bd797aed7
commit 511e790cb1
4 changed files with 19 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import Scrollable from "~/components/Scrollable";
import useCurrentUser from "~/hooks/useCurrentUser";
import useFocusedComment from "~/hooks/useFocusedComment";
import useKeyDown from "~/hooks/useKeyDown";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import CommentForm from "./CommentForm";
import CommentThread from "./CommentThread";
@@ -22,6 +23,7 @@ function Comments() {
const match = useRouteMatch<{ documentSlug: string }>();
const document = documents.getByUrl(match.params.documentSlug);
const focusedComment = useFocusedComment();
const can = usePolicy(document?.id);
useKeyDown("Escape", () => document && ui.collapseComments(document?.id));
@@ -65,7 +67,7 @@ function Comments() {
</Wrapper>
</Scrollable>
<AnimatePresence initial={false}>
{!focusedComment && (
{!focusedComment && can.comment && (
<NewCommentForm
documentId={document.id}
placeholder={`${t("Add a comment")}`}