SuggestionBox.tsx 3.0 KB

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