Sfoglia il codice sorgente

Merge pull request #1923 from visuddhinanda/agile

句子更新后发布更新消息,让同样的句子更新
visuddhinanda 2 anni fa
parent
commit
0db68a8910

+ 2 - 3
dashboard/src/components/template/QuoteLink.tsx

@@ -33,7 +33,7 @@ const QuoteLinkCtl = ({
   found,
 }: IWidgetQuoteLinkCtl) => {
   const [tpl, setTpl] = useState<string>();
-  let textShow = volume === 0 ? page : ` ${volume}.${page}`;
+  let textShow = volume === 0 ? ` ${page}` : ` ${volume}.${page}`;
   if (type === "c") {
     textShow = ` ${chapter}`;
   }
@@ -68,8 +68,7 @@ const QuoteLinkCtl = ({
               title
             ) : (
               <>
-                <TermCtl {...term} compact={true} />
-                {textShow}
+                <TermCtl {...term} compact={true} /> {textShow}
               </>
             )
           }

+ 1 - 0
dashboard/src/components/template/SentEdit.tsx

@@ -64,6 +64,7 @@ export const toISentence = (apiData: ISentenceData): ISentence => ({
   wordStart: apiData.word_start,
   wordEnd: apiData.word_end,
   editor: apiData.editor,
+  studio: apiData.studio,
   channel: apiData.channel,
   updateAt: apiData.updated_at,
   acceptor: apiData.acceptor,

+ 36 - 20
dashboard/src/components/template/SentEdit/SentCell.tsx

@@ -10,7 +10,7 @@ import MdView from "../MdView";
 import EditInfo, { Details } from "./EditInfo";
 import SuggestionToolbar from "./SuggestionToolbar";
 import { useAppSelector } from "../../../hooks";
-import { dirtySent, remove, sentence } from "../../../reducers/accept-pr";
+import { accept, doneSent, done, sentence } from "../../../reducers/accept-pr";
 import { IWbw } from "../Wbw/WbwWord";
 import { my_to_roman } from "../../code/my";
 import SentWbwEdit, { sentSave } from "./SentWbwEdit";
@@ -26,6 +26,7 @@ import "./style.css";
 import StudioName from "../../auth/StudioName";
 import CopyToModal from "../../channel/CopyToModal";
 import store from "../../../store";
+import { randomString } from "../../../utils";
 
 interface IWidget {
   initValue?: ISentence;
@@ -55,9 +56,10 @@ const SentCellWidget = ({
   const [isEditMode, setIsEditMode] = useState(editMode);
   const [sentData, setSentData] = useState<ISentence | undefined>(initValue);
   const [bgColor, setBgColor] = useState<string>();
+  const [uuid] = useState(randomString());
   const endings = useAppSelector(getEnding);
   const acceptPr = useAppSelector(sentence);
-  const removed = useAppSelector(dirtySent);
+  const changedSent = useAppSelector(doneSent);
 
   const [prOpen, setPrOpen] = useState(false);
   const discussionMessage = useAppSelector(message);
@@ -66,6 +68,7 @@ const SentCellWidget = ({
 
   const sentId = `${sentData?.book}-${sentData?.para}-${sentData?.wordStart}-${sentData?.wordEnd}`;
   const sid = `${sentData?.book}_${sentData?.para}_${sentData?.wordStart}_${sentData?.wordEnd}_${sentData?.channel.id}`;
+
   useEffect(() => {
     if (
       discussionMessage &&
@@ -98,24 +101,34 @@ const SentCellWidget = ({
   }, [value]);
 
   useEffect(() => {
-    if (removed?.includes(sid)) {
+    console.debug("sent cell acceptPr", acceptPr, uuid);
+    if (isPr) {
+      console.debug("sent cell is pr");
       return;
     }
-    if (typeof acceptPr !== "undefined" && !isPr && sentData) {
-      const found = acceptPr.findIndex(
-        (value) =>
-          value.book === sentData.book &&
-          value.para === sentData.para &&
-          value.wordStart === sentData.wordStart &&
-          value.wordEnd === sentData.wordEnd &&
-          value.channel.id === sentData.channel.id
-      );
-      if (found !== -1) {
-        setSentData(acceptPr[found]);
-        store.dispatch(remove(sid));
-      }
+    if (typeof acceptPr === "undefined" || acceptPr.length === 0) {
+      console.debug("sent cell acceptPr is empty");
+      return;
+    }
+    if (!sentData) {
+      console.debug("sent cell sentData is empty");
+      return;
+    }
+    if (changedSent?.includes(uuid)) {
+      console.debug("sent cell already apply", uuid);
+      return;
     }
-  }, [acceptPr, sentData, isPr, removed, sid]);
+
+    const found = acceptPr.findIndex((value) => {
+      const vId = `${value.book}_${value.para}_${value.wordStart}_${value.wordEnd}_${value.channel.id}`;
+      return vId === sid;
+    });
+    if (found !== -1) {
+      console.debug("sent cell sentence apply", uuid, found, acceptPr[found]);
+      setSentData(acceptPr[found]);
+      store.dispatch(done(uuid));
+    }
+  }, [acceptPr, sentData, isPr, uuid, changedSent, sid]);
 
   const deletePr = (id: string) => {
     delete_<IDeleteResponse>(`/v2/sentpr/${id}`)
@@ -163,8 +176,10 @@ const SentCellWidget = ({
                   sentData.content = value;
                   _sentSave(
                     sentData,
-                    (res) => {
-                      setSentData(res);
+                    (res: ISentence) => {
+                      //setSentData(res);
+                      //发布句子的改变,让同样的句子更新
+                      store.dispatch(accept([res]));
                       if (typeof onChange !== "undefined") {
                         onChange(res);
                       }
@@ -311,8 +326,9 @@ const SentCellWidget = ({
                     }}
                     onSave={(data: ISentence) => {
                       console.debug("sent cell onSave", data);
+                      //setSentData(data);
+                      store.dispatch(accept([data]));
                       setIsEditMode(false);
-                      setSentData(data);
                       if (typeof onChange !== "undefined") {
                         onChange(data);
                       }

+ 3 - 29
dashboard/src/components/template/SentEdit/SentCellEditable.tsx

@@ -10,7 +10,7 @@ import {
   ISentenceRequest,
   ISentenceResponse,
 } from "../../api/Corpus";
-import { ISentence } from "../SentEdit";
+import { ISentence, toISentence } from "../SentEdit";
 import TermTextArea from "../../general/TermTextArea";
 import { useAppSelector } from "../../../hooks";
 import { wordList } from "../../../reducers/sent-word";
@@ -39,20 +39,7 @@ export const sentSave = (
     .then((json) => {
       if (json.ok) {
         console.debug("sent save ok", json.data);
-        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,
-          studio: json.data.studio,
-          channel: json.data.channel,
-          forkAt: json.data.fork_at,
-          updateAt: json.data.updated_at,
-        };
+        const newData: ISentence = toISentence(json.data);
         ok(newData);
       } else {
         message.error(json.message);
@@ -170,20 +157,7 @@ const SentCellEditableWidget = ({
         if (json.ok) {
           message.success(intl.formatMessage({ id: "flashes.success" }));
           if (typeof onSave !== "undefined") {
-            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,
-              studio: json.data.studio,
-              channel: json.data.channel,
-              forkAt: json.data.fork_at,
-              updateAt: json.data.updated_at,
-            };
+            const newData: ISentence = toISentence(json.data);
             onSave(newData);
           }
         } else {

+ 9 - 9
dashboard/src/reducers/accept-pr.ts

@@ -8,10 +8,10 @@ import type { RootState } from "../store";
 
 interface IState {
   sentences?: ISentence[];
-  dirty: string[];
+  done: string[];
 }
 
-const initialState: IState = { dirty: [] };
+const initialState: IState = { done: [] };
 
 export const slice = createSlice({
   name: "accept-pr",
@@ -19,23 +19,23 @@ export const slice = createSlice({
   reducers: {
     accept: (state, action: PayloadAction<ISentence[]>) => {
       state.sentences = action.payload;
-      state.dirty = [];
+      state.done = [];
     },
 
-    remove: (state, action: PayloadAction<string>) => {
-      if (!state.dirty.includes(action.payload)) {
-        state.dirty.push(action.payload);
+    done: (state, action: PayloadAction<string>) => {
+      if (!state.done.includes(action.payload)) {
+        state.done.push(action.payload);
       }
     },
   },
 });
 
-export const { accept, remove } = slice.actions;
+export const { accept, done } = slice.actions;
 
 export const sentence = (state: RootState): ISentence[] | undefined =>
   state.acceptPr.sentences;
 
-export const dirtySent = (state: RootState): string[] | undefined =>
-  state.acceptPr.dirty;
+export const doneSent = (state: RootState): string[] | undefined =>
+  state.acceptPr.done;
 
 export default slice.reducer;