Comments.tsx 1.7 KB

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