Comments.tsx 2.0 KB

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