CommentBox.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { useState } from "react";
  2. import { Drawer } from "antd";
  3. import CommentTopic from "./CommentTopic";
  4. import CommentListCard from "./CommentListCard";
  5. import { IComment } from "./CommentItem";
  6. interface IWidget {
  7. trigger?: JSX.Element;
  8. resId?: string;
  9. resType?: string;
  10. onCommentCountChange?: Function;
  11. }
  12. const Widget = ({ trigger, resId, resType, onCommentCountChange }: IWidget) => {
  13. const [open, setOpen] = useState(false);
  14. const [childrenDrawer, setChildrenDrawer] = useState(false);
  15. const [topicComment, setTopicComment] = useState<IComment>();
  16. console.log(resId, resType);
  17. const showDrawer = () => {
  18. setOpen(true);
  19. };
  20. const onClose = () => {
  21. setOpen(false);
  22. };
  23. const showChildrenDrawer = (
  24. e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
  25. comment: IComment
  26. ) => {
  27. setChildrenDrawer(true);
  28. setTopicComment(comment);
  29. };
  30. const onChildrenDrawerClose = () => {
  31. setChildrenDrawer(false);
  32. };
  33. return (
  34. <>
  35. <span onClick={showDrawer}>{trigger}</span>
  36. <Drawer
  37. title="Discussion"
  38. width={520}
  39. closable={false}
  40. onClose={onClose}
  41. open={open}
  42. >
  43. <CommentListCard
  44. resId={resId}
  45. resType={resType}
  46. onSelect={showChildrenDrawer}
  47. onItemCountChange={(count: number) => {
  48. if (typeof onCommentCountChange !== "undefined") {
  49. onCommentCountChange(count);
  50. }
  51. }}
  52. />
  53. <Drawer
  54. title="回答"
  55. width={480}
  56. closable={false}
  57. onClose={onChildrenDrawerClose}
  58. open={childrenDrawer}
  59. >
  60. {resId && resType ? (
  61. <CommentTopic
  62. comment={topicComment}
  63. resId={resId}
  64. resType={resType}
  65. />
  66. ) : (
  67. <></>
  68. )}
  69. </Drawer>
  70. </Drawer>
  71. </>
  72. );
  73. };
  74. export default Widget;