|
|
@@ -1,11 +1,13 @@
|
|
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
|
|
|
|
-import { IUser } from '@growi/core';
|
|
|
+import { IUser, pathUtils } from '@growi/core';
|
|
|
import { UserPicture } from '@growi/ui';
|
|
|
import { format } from 'date-fns';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import dynamic from 'next/dynamic';
|
|
|
+import Link from 'next/link';
|
|
|
import { UncontrolledTooltip } from 'reactstrap';
|
|
|
+import urljoin from 'url-join';
|
|
|
|
|
|
import { RendererOptions } from '~/services/renderer/renderer';
|
|
|
|
|
|
@@ -20,6 +22,7 @@ import { CommentEditorProps } from './CommentEditor';
|
|
|
|
|
|
import styles from './Comment.module.scss';
|
|
|
|
|
|
+
|
|
|
const CommentEditor = dynamic<CommentEditorProps>(() => import('./CommentEditor').then(mod => mod.CommentEditor), { ssr: false });
|
|
|
|
|
|
type CommentProps = {
|
|
|
@@ -29,6 +32,8 @@ type CommentProps = {
|
|
|
revisionCreatedAt: Date,
|
|
|
currentUser: IUser,
|
|
|
isReadOnly: boolean,
|
|
|
+ pageId: string,
|
|
|
+ pagePath: string,
|
|
|
deleteBtnClicked: (comment: ICommentHasId) => void,
|
|
|
onComment: () => void,
|
|
|
}
|
|
|
@@ -37,9 +42,11 @@ export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
|
|
|
const {
|
|
|
comment, rendererOptions, revisionId, revisionCreatedAt, currentUser, isReadOnly,
|
|
|
- deleteBtnClicked, onComment,
|
|
|
+ pageId, pagePath, deleteBtnClicked, onComment,
|
|
|
} = props;
|
|
|
|
|
|
+ const { returnPathForURL } = pathUtils;
|
|
|
+
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
const [markdown, setMarkdown] = useState('');
|
|
|
@@ -151,9 +158,11 @@ export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
</div>
|
|
|
<div className="page-comment-body">{commentBody}</div>
|
|
|
<div className="page-comment-meta">
|
|
|
- <a href={`#${commentId}`}>
|
|
|
- <FormattedDistanceDate id={commentId} date={comment.createdAt} />
|
|
|
- </a>
|
|
|
+ <Link href={`#${commentId}`} prefetch={false}>
|
|
|
+ <a>
|
|
|
+ <FormattedDistanceDate id={commentId} date={comment.createdAt} />
|
|
|
+ </a>
|
|
|
+ </Link>
|
|
|
{ isEdited && (
|
|
|
<>
|
|
|
<span id={editedDateId}> (edited)</span>
|
|
|
@@ -161,9 +170,11 @@ export const Comment = (props: CommentProps): JSX.Element => {
|
|
|
</>
|
|
|
) }
|
|
|
<span className="ml-2">
|
|
|
- <a id={`page-comment-revision-${commentId}`} className="page-comment-revision" href={revHref}>
|
|
|
- <HistoryIcon />
|
|
|
- </a>
|
|
|
+ <Link href={urljoin(returnPathForURL(pagePath, pageId), revHref)} prefetch={false}>
|
|
|
+ <a id={`page-comment-revision-${commentId}`} className="page-comment-revision">
|
|
|
+ <HistoryIcon />
|
|
|
+ </a>
|
|
|
+ </Link>
|
|
|
<UncontrolledTooltip placement="bottom" fade={false} target={`page-comment-revision-${commentId}`}>
|
|
|
{t('page_comment.display_the_page_when_posting_this_comment')}
|
|
|
</UncontrolledTooltip>
|