Comments.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import { IRevisionHasId } from '@growi/core';
  3. import dynamic from 'next/dynamic';
  4. import { PageCommentProps } from '~/components/PageComment';
  5. import { useSWRxPageComment } from '~/stores/comment';
  6. import { useIsTrashPage } from '~/stores/page';
  7. import { useCurrentUser } from '../stores/context';
  8. import { CommentEditorProps } from './PageComment/CommentEditor';
  9. const PageComment = dynamic<PageCommentProps>(() => import('~/components/PageComment').then(mod => mod.PageComment), { ssr: false });
  10. const CommentEditor = dynamic<CommentEditorProps>(() => import('./PageComment/CommentEditor').then(mod => mod.CommentEditor), { ssr: false });
  11. type CommentsProps = {
  12. pageId: string,
  13. pagePath: string,
  14. revision: IRevisionHasId,
  15. }
  16. export const Comments = (props: CommentsProps): JSX.Element => {
  17. const { pageId, pagePath, revision } = props;
  18. const { mutate } = useSWRxPageComment(pageId);
  19. const { data: isDeleted } = useIsTrashPage();
  20. const { data: currentUser } = useCurrentUser();
  21. if (pageId == null) {
  22. return <></>;
  23. }
  24. return (
  25. <div className="page-comments-row mt-5 py-4 d-edit-none d-print-none">
  26. <div className="container-lg">
  27. <div className="page-comments">
  28. <div id="page-comments-list" className="page-comments-list">
  29. <PageComment
  30. pageId={pageId}
  31. pagePath={pagePath}
  32. revision={revision}
  33. currentUser={currentUser}
  34. isReadOnly={false}
  35. titleAlign="left"
  36. hideIfEmpty={false}
  37. />
  38. </div>
  39. { !isDeleted && (
  40. <div id="page-comment-write">
  41. <CommentEditor
  42. pageId={pageId}
  43. isForNewComment
  44. onCommentButtonClicked={mutate}
  45. revisionId={revision._id}
  46. />
  47. </div>
  48. )}
  49. </div>
  50. </div>
  51. </div>
  52. );
  53. };