SuggestionBox.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { useEffect, useState } from "react";
  2. import { Button, Card, Drawer, Space } from "antd";
  3. import SuggestionList from "./SuggestionList";
  4. import SuggestionAdd from "./SuggestionAdd";
  5. import { ISentence } from "../SentEdit";
  6. import Marked from "../../general/Marked";
  7. export interface IAnswerCount {
  8. id: string;
  9. count: number;
  10. }
  11. interface IWidget {
  12. data: ISentence;
  13. trigger?: JSX.Element;
  14. }
  15. const SuggestionBoxWidget = ({ trigger, data }: IWidget) => {
  16. const [open, setOpen] = useState(false);
  17. const [reload, setReload] = useState(false);
  18. const [openNotification, setOpenNotification] = useState(false);
  19. const [prNumber, setPrNumber] = useState(data.suggestionCount?.suggestion);
  20. useEffect(() => {
  21. if (localStorage.getItem("read_pr_Notification") === "ok") {
  22. setOpenNotification(false);
  23. } else {
  24. setOpenNotification(true);
  25. }
  26. }, []);
  27. const showDrawer = () => {
  28. setOpen(true);
  29. };
  30. const onClose = () => {
  31. setOpen(false);
  32. };
  33. return (
  34. <>
  35. <Space onClick={showDrawer}>
  36. {trigger}
  37. {prNumber}
  38. </Space>
  39. <Drawer
  40. title="修改建议"
  41. width={520}
  42. onClose={onClose}
  43. open={open}
  44. maskClosable={false}
  45. >
  46. <Space direction="vertical" style={{ width: "100%" }}>
  47. <Card
  48. title="温馨提示"
  49. size="small"
  50. style={{
  51. width: "100%",
  52. display: openNotification ? "block" : "none",
  53. }}
  54. >
  55. <Marked
  56. text="此处专为提交修改建议译文。您输入的应该是**译文**
  57. 而不是评论和问题。其他内容,请在讨论页面提交。"
  58. />
  59. <p style={{ textAlign: "center" }}>
  60. <Button
  61. onClick={() => {
  62. localStorage.setItem("read_pr_Notification", "ok");
  63. setOpenNotification(false);
  64. }}
  65. >
  66. 知道了
  67. </Button>
  68. </p>
  69. </Card>
  70. <SuggestionAdd
  71. data={data}
  72. onCreate={() => {
  73. setReload(true);
  74. }}
  75. />
  76. <SuggestionList
  77. {...data}
  78. reload={reload}
  79. onReload={() => setReload(false)}
  80. onChange={(count: number) => setPrNumber(count)}
  81. />
  82. </Space>
  83. </Drawer>
  84. </>
  85. );
  86. };
  87. export default SuggestionBoxWidget;