Browse Source

Merge pull request #1189 from visuddhinanda/agile

添加 "译文添加按钮"
visuddhinanda 2 years ago
parent
commit
317c0ef831

+ 2 - 2
dashboard/src/components/channel/ChannelPicker.tsx

@@ -18,7 +18,7 @@ const ChannelPickerWidget = ({
   trigger,
   type,
   articleId,
-  multiSelect,
+  multiSelect = true,
   open = false,
   onClose,
   onSelect,
@@ -60,7 +60,7 @@ const ChannelPickerWidget = ({
         <ChannelPickerTable
           type={type}
           articleId={articleId}
-          multiSelect={true}
+          multiSelect={multiSelect}
           onSelect={(channels: IChannel[]) => {
             console.log(channels);
             handleCancel();

+ 71 - 0
dashboard/src/components/template/SentEdit/SentAdd.tsx

@@ -0,0 +1,71 @@
+import { Button } from "antd";
+import { useState } from "react";
+import { PlusOutlined } from "@ant-design/icons";
+import { useAppSelector } from "../../../hooks";
+import { currentUser as _currentUser } from "../../../reducers/current-user";
+import ChannelPicker from "../../channel/ChannelPicker";
+import { IChannel } from "../../channel/Channel";
+import SentCell from "./SentCell";
+import { ISentence } from "../SentEdit";
+interface IWidget {
+  book: number;
+  para: number;
+  wordStart: number;
+  wordEnd: number;
+}
+const Widget = ({ book, para, wordStart, wordEnd }: IWidget) => {
+  const [channel, setChannel] = useState<IChannel>();
+  const [channelPickerOpen, setChannelPickerOpen] = useState(false);
+  const [initSent, setInitSent] = useState<ISentence>();
+  const user = useAppSelector(_currentUser);
+  return channel ? (
+    initSent ? (
+      <SentCell data={initSent} isPr={false} />
+    ) : (
+      <></>
+    )
+  ) : (
+    <>
+      <Button
+        type="dashed"
+        style={{ width: 300 }}
+        icon={<PlusOutlined />}
+        onClick={() => {
+          setChannelPickerOpen(true);
+        }}
+      >
+        Add
+      </Button>
+      <ChannelPicker
+        open={channelPickerOpen}
+        onClose={() => setChannelPickerOpen(false)}
+        onSelect={(channels: IChannel[]) => {
+          setChannel(channels[0]);
+          setChannelPickerOpen(false);
+          if (typeof user === "undefined") {
+            return;
+          }
+          const sentData: ISentence = {
+            content: "",
+            contentType: "markdown",
+            html: "<spen></spen>",
+            book: book,
+            para: para,
+            wordStart: wordStart,
+            wordEnd: wordEnd,
+            editor: {
+              id: user.id,
+              nickName: user.nickName,
+              userName: user.realName,
+            },
+            channel: channels[0],
+            updateAt: "",
+          };
+          setInitSent(sentData);
+        }}
+      />
+    </>
+  );
+};
+
+export default Widget;

+ 10 - 2
dashboard/src/components/template/SentEdit/SentCanRead.tsx

@@ -8,6 +8,7 @@ import { ISentenceListResponse } from "../../api/Corpus";
 
 import { ISentence } from "../SentEdit";
 import SentCell from "./SentCell";
+import SentAdd from "./SentAdd";
 interface IWidget {
   book: number;
   para: number;
@@ -34,7 +35,7 @@ const SentCanReadWidget = ({
     )
       .then((json) => {
         if (json.ok) {
-          console.log("pr load", json.data.rows);
+          console.log("sent load", json.data.rows);
           const newData: ISentence[] = json.data.rows.map((item) => {
             return {
               id: item.id,
@@ -47,6 +48,7 @@ const SentCanReadWidget = ({
               editor: item.editor,
               studio: item.studio,
               channel: item.channel,
+              suggestionCount: item.suggestionCount,
               updateAt: item.updated_at,
             };
           });
@@ -80,8 +82,14 @@ const SentCanReadWidget = ({
           onClick={() => load()}
         />
       </div>
+      <SentAdd
+        book={book}
+        para={para}
+        wordStart={wordStart}
+        wordEnd={wordEnd}
+      />
       {sentData.map((item, id) => {
-        return <SentCell data={item} key={id} isPr={true} />;
+        return <SentCell data={item} key={id} isPr={false} />;
       })}
     </>
   );

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

@@ -56,6 +56,8 @@ const SuggestionToolbarWidget = ({ data, isPr = false, onAccept }: IWidget) => {
         }}
       />
       {CommentCount}
+      <Divider type="vertical" />
+      <Text copyable={{ text: data.content }}></Text>
     </Space>
   );
   return <Text type="secondary">{isPr ? prButton : normalButton}</Text>;