Procházet zdrojové kódy

:construction: create

visuddhinanda před 3 roky
rodič
revize
562f900d98

+ 85 - 0
dashboard/src/components/template/SentEdit/PrAcceptButton.tsx

@@ -0,0 +1,85 @@
+import { useState } from "react";
+import { useIntl } from "react-intl";
+import { Button, message } from "antd";
+import { CheckOutlined } from "@ant-design/icons";
+
+import { put } from "../../../request";
+import { ISentenceRequest, ISentenceResponse } from "../../api/Corpus";
+import { ISentence } from "../SentEdit";
+import store from "../../../store";
+import { accept } from "../../../reducers/accept-pr";
+
+interface IWidget {
+  data: ISentence;
+  onAccept?: Function;
+}
+const Widget = ({ data, onAccept }: IWidget) => {
+  const intl = useIntl();
+
+  const [saving, setSaving] = useState<boolean>(false);
+
+  const save = () => {
+    setSaving(true);
+    put<ISentenceRequest, ISentenceResponse>(
+      `/v2/sentence/${data.book}_${data.para}_${data.wordStart}_${data.wordEnd}_${data.channel.id}`,
+      {
+        book: data.book,
+        para: data.para,
+        wordStart: data.wordStart,
+        wordEnd: data.wordEnd,
+        channel: data.channel.id,
+        content: data.content,
+        prEditor: data.editor.id,
+        prId: data.id,
+        prEditAt: data.updateAt,
+      }
+    )
+      .then((json) => {
+        console.log(json);
+        setSaving(false);
+
+        if (json.ok) {
+          message.success(intl.formatMessage({ id: "flashes.success" }));
+
+          const newData: ISentence = {
+            id: json.data.id,
+            content: json.data.content,
+            html: json.data.html,
+            book: json.data.book,
+            para: json.data.paragraph,
+            wordStart: json.data.word_start,
+            wordEnd: json.data.word_end,
+            editor: json.data.editor,
+            channel: json.data.channel,
+            updateAt: json.data.updated_at,
+            acceptor: json.data.acceptor,
+            prEditAt: json.data.pr_edit_at,
+            suggestionCount: json.data.suggestionCount,
+          };
+          store.dispatch(accept(newData));
+          if (typeof onAccept !== "undefined") {
+            onAccept(newData);
+          }
+        } else {
+          message.error(json.message);
+        }
+      })
+      .catch((e) => {
+        setSaving(false);
+        console.error("catch", e);
+        message.error(e.message);
+      });
+  };
+
+  return (
+    <Button
+      size="small"
+      type="text"
+      icon={<CheckOutlined />}
+      loading={saving}
+      onClick={() => save()}
+    />
+  );
+};
+
+export default Widget;

+ 78 - 0
dashboard/src/components/template/SentEdit/SuggestionBox.tsx

@@ -0,0 +1,78 @@
+import { useEffect, useState } from "react";
+import { Button, Card, Drawer } from "antd";
+
+import SuggestionList from "./SuggestionList";
+import SuggestionAdd from "./SuggestionAdd";
+import { ISentence } from "../SentEdit";
+
+export interface IAnswerCount {
+  id: string;
+  count: number;
+}
+interface IWidget {
+  data: ISentence;
+  trigger?: JSX.Element;
+}
+const Widget = ({ trigger, data }: IWidget) => {
+  const [open, setOpen] = useState(false);
+  const [openNotification, setOpenNotification] = useState(false);
+
+  useEffect(() => {
+    if (localStorage.getItem("read_pr_Notification") === "ok") {
+      setOpenNotification(false);
+    } else {
+      setOpenNotification(true);
+    }
+  }, []);
+  const showDrawer = () => {
+    setOpen(true);
+  };
+
+  const onClose = () => {
+    setOpen(false);
+  };
+
+  return (
+    <>
+      <span onClick={showDrawer}>{trigger}</span>
+      <Drawer
+        title="修改建议"
+        width={520}
+        onClose={onClose}
+        open={open}
+        maskClosable={false}
+      >
+        <div>
+          <Card
+            title="温馨提示"
+            size="small"
+            style={{
+              width: "100%",
+              display: openNotification ? "block" : "none",
+            }}
+          >
+            <p>此处专为提交修改建议译文。如果有问题,请在讨论页面提交。</p>
+            <p style={{ textAlign: "center" }}>
+              <Button
+                onClick={() => {
+                  localStorage.setItem("read_pr_Notification", "ok");
+                  setOpenNotification(false);
+                }}
+              >
+                知道了
+              </Button>
+            </p>
+          </Card>
+          <div>
+            <SuggestionAdd data={data} />
+          </div>
+          <div>
+            <SuggestionList {...data} />
+          </div>
+        </div>
+      </Drawer>
+    </>
+  );
+};
+
+export default Widget;

+ 53 - 0
dashboard/src/components/template/SentEdit/SuggestionToolbar.tsx

@@ -0,0 +1,53 @@
+import { Divider, Space, Typography } from "antd";
+import { CommentOutlined, LikeOutlined } from "@ant-design/icons";
+import { ISentence } from "../SentEdit";
+import { useState } from "react";
+import CommentBox from "../../comment/CommentBox";
+import SuggestionBox from "./SuggestionBox";
+import PrAcceptButton from "./PrAcceptButton";
+import { HandOutlinedIcon } from "../../../assets/icon";
+
+const { Text } = Typography;
+
+interface IWidget {
+  data: ISentence;
+  isPr?: boolean;
+  onAccept?: Function;
+}
+const Widget = ({ data, isPr = false, onAccept }: IWidget) => {
+  const [CommentCount, setCommentCount] = useState<number | undefined>(
+    data.suggestionCount?.discussion
+  );
+  const prButton = (
+    <Space>
+      <LikeOutlined />
+      <Divider type="vertical" />
+      <PrAcceptButton
+        data={data}
+        onAccept={(value: ISentence) => {
+          if (typeof onAccept !== "undefined") {
+            onAccept(value);
+          }
+        }}
+      />
+    </Space>
+  );
+  const normalButton = (
+    <Space>
+      <SuggestionBox data={data} trigger={<HandOutlinedIcon />} />
+      {data.suggestionCount?.suggestion} <Divider type="vertical" />
+      <CommentBox
+        resId={`data.book`}
+        resType="sentence"
+        trigger={<CommentOutlined />}
+        onCommentCountChange={(count: number) => {
+          setCommentCount(count);
+        }}
+      />
+      {CommentCount}
+    </Space>
+  );
+  return <Text type="secondary">{isPr ? prButton : normalButton}</Text>;
+};
+
+export default Widget;

+ 32 - 0
dashboard/src/reducers/accept-pr.ts

@@ -0,0 +1,32 @@
+/**
+ * 查字典,添加术语命令
+ */
+import { createSlice, PayloadAction } from "@reduxjs/toolkit";
+import { IWidgetDict } from "../components/dict/DictComponent";
+import { ISentence } from "../components/template/SentEdit";
+import { IWidgetDictCreate } from "../components/term/TermCreate";
+
+import type { RootState } from "../store";
+
+interface IState {
+  sentence?: ISentence;
+}
+
+const initialState: IState = {};
+
+export const slice = createSlice({
+  name: "accept-pr",
+  initialState,
+  reducers: {
+    accept: (state, action: PayloadAction<ISentence>) => {
+      state.sentence = action.payload;
+    },
+  },
+});
+
+export const { accept } = slice.actions;
+
+export const sentence = (state: RootState): ISentence | undefined =>
+  state.acceptPr.sentence;
+
+export default slice.reducer;