Просмотр исходного кода

wip: resolve conflict method in page container

yuto-oweseek 4 лет назад
Родитель
Сommit
c1bc3e0be7

+ 8 - 19
packages/app/src/client/services/PageContainer.js

@@ -647,32 +647,21 @@ export default class PageContainer extends Container {
   retrieveMyBookmarkList() {
   }
 
-  async resolveConflict(pageId, revisionId, markdown, optionsToSave) {
+  async resolveConflict(markdown, editrMode) {
 
-    if (optionsToSave == null) {
-      const msg = '\'saveAndReload\' requires the \'optionsToSave\' param';
-      throw new Error(msg);
-    }
-
-    const { path } = this.state;
+    const { pageId, revisionId, path } = this.state;
+    const editorContainer = this.appContainer.getContainer('EditorContainer');
 
-    const params = Object.assign(optionsToSave, {
-      page_id: pageId,
-      revision_id: revisionId,
-      body: markdown,
-    });
+    const optionsToSave = editorContainer.getCurrentOptionsToSave();
 
-    const res = await apiPost('/pages.update', params);
+    const res = this.updatePage(pageId, revisionId, markdown, optionsToSave);
 
-    const editorContainer = this.appContainer.getContainer('EditorContainer');
     editorContainer.clearDraft(path);
+    editorContainer.disableUnsavedWarning();
+    editorContainer.setState({ tags: res.tags });
+    this.updateStateAfterSave(res.page, res.tags, res.revision, 'edit');
 
     return res;
   }
 
-  async resolveConflictAndReload(pageId, revisionId, markdown, optionsToSave) {
-    await this.resolveConflict(pageId, revisionId, markdown, optionsToSave);
-    window.location.href = this.state.path;
-  }
-
 }

+ 5 - 7
packages/app/src/components/PageEditor/ConflictDiffModal.tsx

@@ -94,19 +94,17 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
   const onResolveConflict = async() : Promise<void> => {
     // disable button after clicked
     setIsRevisionSelected(false);
+
     const codeMirrorVal = uncontrolledRef.current?.editor.doc.getValue();
-    editorContainer.disableUnsavedWarning();
+
     try {
-      await pageContainer.resolveConflictAndReload(
-        pageContainer.state.pageId,
-        latest.revisionId,
-        codeMirrorVal,
-        editorContainer.getCurrentOptionsToSave(),
-      );
+      await pageContainer.resolveConflict(codeMirrorVal, 'edit');
+      pageContainer.showSuccessToastr();
     }
     catch (error) {
       pageContainer.showErrorToastr(error);
     }
+
   };
 
   return (