List.tsx 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 'use client';
  2. import '../style.scss';
  3. import React from 'react';
  4. import BoardResponse from '@/dtos/response/forum/board/boardResponse';
  5. import PostResponse from '@/dtos/response/forum/post/postResponse';
  6. import CommentListResponse from '@/dtos/response/forum/comment/commentListResponse';
  7. import WriteForm from './WriteForm';
  8. import Item from './Item';
  9. import Loading from '@/app/component/Loading';
  10. type Props = {
  11. board: BoardResponse,
  12. post: PostResponse,
  13. data: CommentListResponse;
  14. loading: boolean;
  15. replyTargetID: number|null;
  16. onReply: (commentID: number) => void;
  17. onDelete: () => void;
  18. onSuccess: () => void;
  19. }
  20. export default function List({ board, post, data, loading, replyTargetID, onReply, onSuccess, onDelete } : Props)
  21. {
  22. return (
  23. <>
  24. {loading && <Loading type={2} />}
  25. {data && data.total > 0 && (
  26. <article className="comment-list">
  27. <ol>
  28. {data.list.map((row, i) => {
  29. return (
  30. <React.Fragment key={i}>
  31. <Item key={i}
  32. board={board}
  33. post={post}
  34. comment={row}
  35. isReplying={replyTargetID == row.id}
  36. onReply={() => onReply(row.id)}
  37. onDelete={onDelete}
  38. onSuccess={onSuccess}
  39. />
  40. {/* row에 대한 답글 폼(토글) */}
  41. {replyTargetID === row.id && (
  42. <div className="pl-[81px] mb-2">
  43. <WriteForm
  44. board={board}
  45. post={post}
  46. comment={row}
  47. onSuccess={onSuccess}
  48. onCancel={() => onReply(row.id)}
  49. />
  50. </div>
  51. )}
  52. {Array.isArray(row.children) && row.children.length > 0 && (
  53. <ol className="pl-[81px]">
  54. {row.children.map((ch, j) => (
  55. <React.Fragment key={j}>
  56. <Item
  57. board={board}
  58. post={post}
  59. comment={ch}
  60. onReply={() => onReply(row.id)}
  61. onDelete={onDelete}
  62. onSuccess={onSuccess}
  63. />
  64. {replyTargetID != null && replyTargetID === ch.id && (
  65. <div className="pl-[81px] mb-2">
  66. <WriteForm
  67. board={board}
  68. post={post}
  69. comment={ch}
  70. onSuccess={onSuccess}
  71. onCancel={() => onReply(ch.id)}
  72. />
  73. </div>
  74. )}
  75. </React.Fragment>
  76. ))}
  77. </ol>
  78. )}
  79. </React.Fragment>
  80. )
  81. })}
  82. </ol>
  83. </article>
  84. )}
  85. </>
  86. );
  87. }