|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
|
+import React, { useEffect, useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
import { UserPicture } from '@growi/ui';
|
|
import { UserPicture } from '@growi/ui';
|
|
|
import { format } from 'date-fns';
|
|
import { format } from 'date-fns';
|
|
@@ -6,8 +6,8 @@ import { useTranslation } from 'next-i18next';
|
|
|
import dynamic from 'next/dynamic';
|
|
import dynamic from 'next/dynamic';
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
|
|
|
|
|
|
|
-import { RendererOptions } from '~/services/renderer/renderer';
|
|
|
|
|
import { useCurrentUser } from '~/stores/context';
|
|
import { useCurrentUser } from '~/stores/context';
|
|
|
|
|
+import { useCommentPreviewOptions } from '~/stores/renderer';
|
|
|
|
|
|
|
|
import { ICommentHasId } from '../../interfaces/comment';
|
|
import { ICommentHasId } from '../../interfaces/comment';
|
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
@@ -28,7 +28,6 @@ type CommentProps = {
|
|
|
isReadOnly: boolean,
|
|
isReadOnly: boolean,
|
|
|
deleteBtnClicked: (comment: ICommentHasId) => void,
|
|
deleteBtnClicked: (comment: ICommentHasId) => void,
|
|
|
onComment: () => void,
|
|
onComment: () => void,
|
|
|
- rendererOptions: RendererOptions,
|
|
|
|
|
currentPagePath: string,
|
|
currentPagePath: string,
|
|
|
currentRevisionId: string,
|
|
currentRevisionId: string,
|
|
|
currentRevisionCreatedAt: Date,
|
|
currentRevisionCreatedAt: Date,
|
|
@@ -37,12 +36,13 @@ type CommentProps = {
|
|
|
export const Comment = (props: CommentProps): JSX.Element => {
|
|
export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
- comment, isReadOnly, deleteBtnClicked, onComment, rendererOptions,
|
|
|
|
|
|
|
+ comment, isReadOnly, deleteBtnClicked, onComment,
|
|
|
currentPagePath, currentRevisionId, currentRevisionCreatedAt,
|
|
currentPagePath, currentRevisionId, currentRevisionCreatedAt,
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const { data: currentUser } = useCurrentUser();
|
|
const { data: currentUser } = useCurrentUser();
|
|
|
|
|
+ const { data: rendererOptions } = useCommentPreviewOptions();
|
|
|
|
|
|
|
|
const [markdown, setMarkdown] = useState('');
|
|
const [markdown, setMarkdown] = useState('');
|
|
|
const [isReEdit, setIsReEdit] = useState(false);
|
|
const [isReEdit, setIsReEdit] = useState(false);
|
|
@@ -101,19 +101,24 @@ export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
return <span style={{ whiteSpace: 'pre-wrap' }}>{comment}</span>;
|
|
return <span style={{ whiteSpace: 'pre-wrap' }}>{comment}</span>;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const renderRevisionBody = () => {
|
|
|
|
|
- return (
|
|
|
|
|
- <RevisionRenderer
|
|
|
|
|
- rendererOptions={rendererOptions}
|
|
|
|
|
- markdown={markdown}
|
|
|
|
|
- additionalClassName="comment"
|
|
|
|
|
- pagePath={currentPagePath}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const commentBody = useMemo(() => {
|
|
|
|
|
+ if (rendererOptions == null) {
|
|
|
|
|
+ return <></>;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return isMarkdown
|
|
|
|
|
+ ? (
|
|
|
|
|
+ <RevisionRenderer
|
|
|
|
|
+ rendererOptions={rendererOptions}
|
|
|
|
|
+ markdown={markdown}
|
|
|
|
|
+ additionalClassName="comment"
|
|
|
|
|
+ pagePath={currentPagePath}
|
|
|
|
|
+ />
|
|
|
|
|
+ )
|
|
|
|
|
+ : renderText(comment.comment);
|
|
|
|
|
+ }, [comment, currentPagePath, isMarkdown, markdown, rendererOptions]);
|
|
|
|
|
|
|
|
const rootClassName = getRootClassName(comment);
|
|
const rootClassName = getRootClassName(comment);
|
|
|
- const commentBody = isMarkdown ? renderRevisionBody() : renderText(comment.comment);
|
|
|
|
|
const revHref = `?revision=${comment.revision}`;
|
|
const revHref = `?revision=${comment.revision}`;
|
|
|
|
|
|
|
|
const editedDateId = `editedDate-${comment._id}`;
|
|
const editedDateId = `editedDate-${comment._id}`;
|
|
@@ -125,7 +130,7 @@ export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
<div className={`${styles['comment-styles']}`}>
|
|
<div className={`${styles['comment-styles']}`}>
|
|
|
{(isReEdit && !isReadOnly) ? (
|
|
{(isReEdit && !isReadOnly) ? (
|
|
|
<CommentEditor
|
|
<CommentEditor
|
|
|
- rendererOptions={rendererOptions}
|
|
|
|
|
|
|
+ pageId={comment._id}
|
|
|
replyTo={undefined}
|
|
replyTo={undefined}
|
|
|
currentCommentId={commentId}
|
|
currentCommentId={commentId}
|
|
|
commentBody={comment.comment}
|
|
commentBody={comment.comment}
|