| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { useEffect, useState } from "react";
- import { Alert, Button, Space } from "antd";
- import SuggestionList from "./SuggestionList";
- import SuggestionAdd from "./SuggestionAdd";
- import type { ISentence } from "../SentEdit";
- import Marked from "../../general/Marked";
- import { useAppSelector } from "../../../hooks";
- import { message } from "../../../reducers/discussion";
- import { useIntl } from "react-intl";
- interface ISuggestionWidget {
- data: ISentence;
- openNotification: boolean;
- enable?: boolean;
- onNotificationChange?: Function;
- onPrChange?: Function;
- }
- const Suggestion = ({
- data,
- enable = true,
- openNotification,
- onNotificationChange,
- onPrChange,
- }: ISuggestionWidget) => {
- const [reload, setReload] = useState(false);
- const intl = useIntl();
- return (
- <Space orientation="vertical" style={{ width: "100%" }}>
- {openNotification ? (
- <Alert
- message="温馨提示"
- type="info"
- showIcon
- description={
- <Marked
- text="此处专为提交修改建议译文。您输入的应该是**译文**
- 而不是评论和问题。其他内容,请在讨论页面提交。"
- />
- }
- action={
- <Button
- type="text"
- onClick={() => {
- localStorage.setItem("read_pr_Notification", "ok");
- if (typeof onNotificationChange !== "undefined") {
- onNotificationChange(false);
- }
- }}
- >
- {intl.formatMessage({
- id: "buttons.got.it",
- })}
- </Button>
- }
- closable
- />
- ) : undefined}
- <SuggestionAdd
- data={data}
- onCreate={() => {
- setReload(true);
- }}
- />
- <SuggestionList
- {...data}
- enable={enable}
- reload={reload}
- onReload={() => {
- setReload(false);
- }}
- onChange={(count: number) => {
- if (typeof onPrChange !== "undefined") {
- onPrChange(count);
- }
- }}
- />
- </Space>
- );
- };
- export interface IAnswerCount {
- id: string;
- count: number;
- }
- const SuggestionBoxWidget = () => {
- const [openNotification, setOpenNotification] = useState(false);
- const [sentData, setSentData] = useState<ISentence>();
- const discussionMessage = useAppSelector(message);
- useEffect(() => {
- if (discussionMessage?.type === "pr") {
- setSentData(discussionMessage.sent);
- }
- }, [discussionMessage]);
- useEffect(() => {
- if (localStorage.getItem("read_pr_Notification") === "ok") {
- setOpenNotification(false);
- } else {
- setOpenNotification(true);
- }
- }, []);
- return sentData ? (
- <Suggestion
- data={sentData}
- enable={true}
- openNotification={openNotification}
- onNotificationChange={(value: boolean) => setOpenNotification(value)}
- onPrChange={(_value: number) => {}}
- />
- ) : (
- <></>
- );
- };
- export default SuggestionBoxWidget;
|