|
|
@@ -40,13 +40,14 @@ export type PageCommentProps = {
|
|
|
isReadOnly: boolean,
|
|
|
titleAlign?: 'center' | 'left' | 'right',
|
|
|
hideIfEmpty?: boolean,
|
|
|
+ onCommentCountUpdated?: () => void,
|
|
|
}
|
|
|
|
|
|
-export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps): JSX.Element => {
|
|
|
+export const PageComment: FC<PageCommentProps> = memo((props: PageCommentProps): JSX.Element => {
|
|
|
|
|
|
const {
|
|
|
rendererOptions: rendererOptionsByProps,
|
|
|
- pageId, pagePath, revision, currentUser, isReadOnly, titleAlign, hideIfEmpty,
|
|
|
+ pageId, pagePath, revision, currentUser, isReadOnly, titleAlign, hideIfEmpty, onCommentCountUpdated,
|
|
|
} = props;
|
|
|
|
|
|
const { data: comments, mutate } = useSWRxPageComment(pageId);
|
|
|
@@ -84,15 +85,18 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
|
|
|
const onDeleteCommentAfterOperation = useCallback(() => {
|
|
|
onCancelDeleteComment();
|
|
|
mutate();
|
|
|
- }, [mutate, onCancelDeleteComment]);
|
|
|
+ if (onCommentCountUpdated != null) {
|
|
|
+ onCommentCountUpdated();
|
|
|
+ }
|
|
|
+ }, [mutate, onCancelDeleteComment, onCommentCountUpdated]);
|
|
|
|
|
|
- const onDeleteComment = useCallback(async() => {
|
|
|
+ const onDeleteComment = useCallback(async () => {
|
|
|
if (commentToBeDeleted == null) return;
|
|
|
try {
|
|
|
await apiPost('/comments.remove', { comment_id: commentToBeDeleted._id });
|
|
|
onDeleteCommentAfterOperation();
|
|
|
}
|
|
|
- catch (error:unknown) {
|
|
|
+ catch (error: unknown) {
|
|
|
setErrorMessageOnDelete(error as string);
|
|
|
toastError(`error: ${error}`);
|
|
|
}
|
|
|
@@ -107,10 +111,18 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
|
|
|
});
|
|
|
}, []);
|
|
|
|
|
|
- const handleReplyButtonClick = useCallback((commentId: string) => {
|
|
|
+ const onReplyButtonClickHandler = useCallback((commentId: string) => {
|
|
|
setShowEditorIds((previousState) => new Set(previousState.add(commentId)));
|
|
|
}, []);
|
|
|
|
|
|
+ const onCommentButtonClickHandler = useCallback((commentId: string) => {
|
|
|
+ removeShowEditorId(commentId);
|
|
|
+ mutate();
|
|
|
+ if (onCommentCountUpdated != null) {
|
|
|
+ onCommentCountUpdated();
|
|
|
+ }
|
|
|
+ }, [removeShowEditorId, mutate, onCommentCountUpdated])
|
|
|
+
|
|
|
if (hideIfEmpty && comments?.length === 0) {
|
|
|
return <PageCommentRoot />;
|
|
|
}
|
|
|
@@ -168,7 +180,7 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
|
|
|
<div className="page-comments">
|
|
|
<h2 className={commentTitleClasses}><i className="icon-fw icon-bubbles"></i>Comments</h2>
|
|
|
<div className="page-comments-list" id="page-comments-list">
|
|
|
- { commentsExceptReply.map((comment) => {
|
|
|
+ {commentsExceptReply.map((comment) => {
|
|
|
|
|
|
const defaultCommentThreadClasses = 'page-comment-thread pb-5';
|
|
|
const hasReply: boolean = Object.keys(allReplies).includes(comment._id);
|
|
|
@@ -189,7 +201,7 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
|
|
|
color="secondary"
|
|
|
size="sm"
|
|
|
className="btn-comment-reply"
|
|
|
- onClick={() => handleReplyButtonClick(comment._id)}
|
|
|
+ onClick={() => onReplyButtonClickHandler(comment._id)}
|
|
|
>
|
|
|
<i className="icon-fw icon-action-undo"></i> Reply
|
|
|
</Button>
|
|
|
@@ -204,10 +216,7 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
|
|
|
onCancelButtonClicked={() => {
|
|
|
removeShowEditorId(comment._id);
|
|
|
}}
|
|
|
- onCommentButtonClicked={() => {
|
|
|
- removeShowEditorId(comment._id);
|
|
|
- mutate();
|
|
|
- }}
|
|
|
+ onCommentButtonClicked={() => onCommentButtonClickHandler(comment._id)}
|
|
|
revisionId={revisionId}
|
|
|
/>
|
|
|
)}
|