SuggestionBox.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { useEffect, useState } from "react";
  2. import { Alert, Button, 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. import { useAppSelector } from "../../../hooks";
  8. import { message } from "../../../reducers/discussion";
  9. interface ISuggestionWidget {
  10. data: ISentence;
  11. openNotification: boolean;
  12. enable?: boolean;
  13. onNotificationChange?: Function;
  14. onPrChange?: Function;
  15. }
  16. const Suggestion = ({
  17. data,
  18. enable = true,
  19. openNotification,
  20. onNotificationChange,
  21. onPrChange,
  22. }: ISuggestionWidget) => {
  23. const [reload, setReload] = useState(false);
  24. return (
  25. <Space direction="vertical" style={{ width: "100%" }}>
  26. {openNotification ? (
  27. <Alert
  28. message="温馨提示"
  29. type="info"
  30. showIcon
  31. description={
  32. <Marked
  33. text="此处专为提交修改建议译文。您输入的应该是**译文**
  34. 而不是评论和问题。其他内容,请在讨论页面提交。"
  35. />
  36. }
  37. action={
  38. <Button
  39. type="text"
  40. onClick={() => {
  41. localStorage.setItem("read_pr_Notification", "ok");
  42. if (typeof onNotificationChange !== "undefined") {
  43. onNotificationChange(false);
  44. }
  45. }}
  46. >
  47. 知道了
  48. </Button>
  49. }
  50. closable
  51. />
  52. ) : undefined}
  53. <SuggestionAdd
  54. data={data}
  55. onCreate={() => {
  56. setReload(true);
  57. }}
  58. />
  59. <SuggestionList
  60. {...data}
  61. enable={enable}
  62. reload={reload}
  63. onReload={() => {
  64. setReload(false);
  65. }}
  66. onChange={(count: number) => {
  67. if (typeof onPrChange !== "undefined") {
  68. onPrChange(count);
  69. }
  70. }}
  71. />
  72. </Space>
  73. );
  74. };
  75. export interface IAnswerCount {
  76. id: string;
  77. count: number;
  78. }
  79. const SuggestionBoxWidget = () => {
  80. const [openNotification, setOpenNotification] = useState(false);
  81. const [sentData, setSentData] = useState<ISentence>();
  82. const discussionMessage = useAppSelector(message);
  83. useEffect(() => {
  84. if (discussionMessage?.type === "pr") {
  85. setSentData(discussionMessage.sent);
  86. }
  87. }, [discussionMessage]);
  88. useEffect(() => {
  89. if (localStorage.getItem("read_pr_Notification") === "ok") {
  90. setOpenNotification(false);
  91. } else {
  92. setOpenNotification(true);
  93. }
  94. }, []);
  95. return sentData ? (
  96. <Suggestion
  97. data={sentData}
  98. enable={true}
  99. openNotification={openNotification}
  100. onNotificationChange={(value: boolean) => setOpenNotification(value)}
  101. onPrChange={(value: number) => {}}
  102. />
  103. ) : (
  104. <></>
  105. );
  106. };
  107. export default SuggestionBoxWidget;