Comments.tsx 1.7 KB

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