DiscussionDrawer.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { useEffect, useState } from "react";
  2. import { Button, _Divider, Drawer, Space } from "antd";
  3. import { FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons";
  4. import _DiscussionTopic from "./DiscussionTopic";
  5. import _DiscussionListCard, { type TResType } from "./DiscussionListCard";
  6. import type { _IComment } from "./DiscussionItem"
  7. import _DiscussionAnchor from "./DiscussionAnchor";
  8. import { Link } from "react-router";
  9. import { useIntl } from "react-intl";
  10. import Discussion from "./Discussion";
  11. export interface IAnswerCount {
  12. id: string;
  13. count: number;
  14. }
  15. interface IWidget {
  16. trigger?: JSX.Element;
  17. open?: boolean;
  18. onClose?: () => void;
  19. resId?: string;
  20. resType?: TResType;
  21. }
  22. const DiscussionDrawerWidget = ({
  23. trigger,
  24. open,
  25. onClose,
  26. resId,
  27. resType,
  28. }: IWidget) => {
  29. const intl = useIntl();
  30. const [openDrawer, setOpenDrawer] = useState(open);
  31. useEffect(() => {
  32. setOpenDrawer(open);
  33. }, [open]);
  34. const drawerMinWidth = 600;
  35. const drawerMaxWidth = 1100;
  36. const [drawerWidth, setDrawerWidth] = useState(drawerMinWidth);
  37. return (
  38. <>
  39. <span
  40. onClick={() => {
  41. setOpenDrawer(true);
  42. }}
  43. >
  44. {trigger}
  45. </span>
  46. <Drawer
  47. title="Discussion"
  48. destroyOnClose
  49. extra={
  50. <Space>
  51. <Link to={`/discussion/show/${resType}/${resId}`} target="_blank">
  52. {intl.formatMessage(
  53. {
  54. id: "buttons.open.in.new.tab",
  55. },
  56. { item: "" }
  57. )}
  58. </Link>
  59. {drawerWidth === drawerMinWidth ? (
  60. <Button
  61. type="link"
  62. icon={<FullscreenOutlined />}
  63. onClick={() => setDrawerWidth(drawerMaxWidth)}
  64. />
  65. ) : (
  66. <Button
  67. type="link"
  68. icon={<FullscreenExitOutlined />}
  69. onClick={() => setDrawerWidth(drawerMinWidth)}
  70. />
  71. )}
  72. </Space>
  73. }
  74. width={drawerWidth}
  75. onClose={() => {
  76. if (onClose) {
  77. onClose();
  78. } else {
  79. setOpenDrawer(false);
  80. }
  81. if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
  82. document.getElementsByTagName("body")[0].removeAttribute("style");
  83. }
  84. }}
  85. open={openDrawer}
  86. maskClosable={false}
  87. >
  88. <Discussion resId={resId} resType={resType} showStudent={false} />
  89. </Drawer>
  90. </>
  91. );
  92. };
  93. export default DiscussionDrawerWidget;