CommentItem.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Avatar } from "antd";
  2. import { useState } from "react";
  3. import { IUser } from "../auth/User";
  4. import CommentShow from "./CommentShow";
  5. import CommentEdit from "./CommentEdit";
  6. export interface IComment {
  7. id?: string; //id未提供为新建
  8. resId?: string;
  9. resType?: string;
  10. user: IUser;
  11. parent?: string;
  12. title?: string;
  13. content?: string;
  14. children?: IComment[];
  15. childrenCount?: number;
  16. createdAt?: string;
  17. updatedAt?: string;
  18. }
  19. interface IWidget {
  20. data: IComment;
  21. onSelect?: Function;
  22. onCreated?: Function;
  23. }
  24. const Widget = ({ data, onSelect, onCreated }: IWidget) => {
  25. const [edit, setEdit] = useState(false);
  26. console.log(data);
  27. return (
  28. <div style={{ display: "flex" }}>
  29. <div style={{ width: "2em" }}>
  30. <Avatar size="small">{data.user?.nickName?.slice(0, 1)}</Avatar>
  31. </div>
  32. <div style={{ width: "100%" }}>
  33. {edit ? (
  34. <CommentEdit
  35. data={data}
  36. onCreated={(e: IComment) => {
  37. if (typeof onCreated !== "undefined") {
  38. onCreated(e);
  39. }
  40. }}
  41. />
  42. ) : (
  43. <CommentShow
  44. data={data}
  45. onEdit={() => {
  46. setEdit(true);
  47. }}
  48. />
  49. )}
  50. </div>
  51. </div>
  52. );
  53. };
  54. export default Widget;