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

@@ -16,6 +16,7 @@ import Typing from "~/components/Typing";
import { WebsocketContext } from "~/components/WebsocketProvider";
import useCurrentUser from "~/hooks/useCurrentUser";
import useOnClickOutside from "~/hooks/useOnClickOutside";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import { sidebarAppearDuration } from "~/styles/animations";
import CommentForm from "./CommentForm";
@@ -68,6 +69,7 @@ function CommentThread({
document,
comment: thread,
});
const can = usePolicy(document.id);
const commentsInThread = comments
.inThread(thread.id)
@@ -155,7 +157,8 @@ function CommentThread({
comment={comment}
key={comment.id}
firstOfThread={index === 0}
lastOfThread={index === commentsInThread.length - 1 && !focused}
lastOfThread={index === commentsInThread.length - 1}
canReply={focused && can.comment}
firstOfAuthor={firstOfAuthor}
lastOfAuthor={lastOfAuthor}
previousCommentCreatedAt={commentsInThread[index - 1]?.createdAt}
@@ -174,7 +177,7 @@ function CommentThread({
))}
<ResizingHeightContainer hideOverflow={false}>
{(focused || commentsInThread.length === 0) && (
{(focused || commentsInThread.length === 0) && can.comment && (
<Fade timing={100}>
<CommentForm
documentId={document.id}
@@ -187,7 +190,7 @@ function CommentThread({
</Fade>
)}
</ResizingHeightContainer>
{!focused && !recessed && (
{!focused && !recessed && can.comment && (
<Reply onClick={() => setAutoFocus(true)}>{t("Reply")}</Reply>
)}
</Thread>