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

prevent reload when resolve conflict

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

+ 5 - 6
packages/app/src/client/services/PageContainer.js

@@ -649,17 +649,16 @@ export default class PageContainer extends Container {
 
   async resolveConflict(markdown, editrMode) {
 
-    const { pageId, revisionId, path } = this.state;
+    const { pageId, remoteRevisionId, path } = this.state;
     const editorContainer = this.appContainer.getContainer('EditorContainer');
-
     const optionsToSave = editorContainer.getCurrentOptionsToSave();
 
-    const res = this.updatePage(pageId, revisionId, markdown, optionsToSave);
-
     editorContainer.clearDraft(path);
-    editorContainer.disableUnsavedWarning();
+    const res = await this.updatePage(pageId, remoteRevisionId, markdown, optionsToSave);
+
+    this.updateStateAfterSave(res.page, res.tags, res.revision, editrMode);
+
     editorContainer.setState({ tags: res.tags });
-    this.updateStateAfterSave(res.page, res.tags, res.revision, 'edit');
 
     return res;
   }

+ 12 - 9
packages/app/src/components/PageEditor/ConflictDiffModal.tsx

@@ -14,6 +14,8 @@ import PageContainer from '../../client/services/PageContainer';
 import EditorContainer from '../../client/services/EditorContainer';
 import AppContainer from '../../client/services/AppContainer';
 
+import { EditorMode } from '~/stores/ui';
+
 import { IRevisionOnConflict } from '../../interfaces/revision';
 import { UncontrolledCodeMirror } from '../UncontrolledCodeMirror';
 
@@ -26,7 +28,7 @@ Object.keys(DMP).forEach((key) => { window[key] = DMP[key] });
 
 type ConflictDiffModalProps = {
   isOpen: boolean | null;
-  onCancel: (() => void) | null;
+  onClose: (() => void) | null;
   pageContainer: PageContainer;
   editorContainer: EditorContainer;
   appContainer: AppContainer;
@@ -85,9 +87,9 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
     }
   }, [codeMirrorRef, origin.revisionBody, request.revisionBody, latest.revisionBody]);
 
-  const onCancel = () => {
-    if (props.onCancel != null) {
-      props.onCancel();
+  const onClose = () => {
+    if (props.onClose != null) {
+      props.onClose();
     }
   };
 
@@ -98,8 +100,9 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
     const codeMirrorVal = uncontrolledRef.current?.editor.doc.getValue();
 
     try {
-      await pageContainer.resolveConflict(codeMirrorVal, 'edit');
+      await pageContainer.resolveConflict(codeMirrorVal, EditorMode);
       pageContainer.showSuccessToastr();
+      onClose();
     }
     catch (error) {
       pageContainer.showErrorToastr(error);
@@ -108,8 +111,8 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
   };
 
   return (
-    <Modal isOpen={props.isOpen || false} toggle={onCancel} className="modal-gfm-cheatsheet" size="xl">
-      <ModalHeader tag="h4" toggle={onCancel} className="bg-primary text-light">
+    <Modal isOpen={props.isOpen || false} toggle={onClose} className="modal-gfm-cheatsheet" size="xl">
+      <ModalHeader tag="h4" toggle={onClose} className="bg-primary text-light">
         <i className="icon-fw icon-exclamation" />{t('modal_resolve_conflict.resolve_conflict')}
       </ModalHeader>
       <ModalBody>
@@ -218,7 +221,7 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
         <button
           type="button"
           className="btn btn-outline-secondary"
-          onClick={onCancel}
+          onClick={onClose}
         >
           {t('Cancel')}
         </button>
@@ -237,7 +240,7 @@ export const ConflictDiffModal: FC<ConflictDiffModalProps> = (props) => {
 
 ConflictDiffModal.propTypes = {
   isOpen: PropTypes.bool,
-  onCancel: PropTypes.func,
+  onClose: PropTypes.func,
   pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
   editorContainer:  PropTypes.instanceOf(EditorContainer).isRequired,
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,

+ 1 - 1
packages/app/src/components/PageEditor/Editor.jsx

@@ -375,7 +375,7 @@ class Editor extends AbstractEditor {
         </div>
         <ConflictDiffModal
           isOpen={this.props.pageContainer.state.isConflictDiffModalOpen}
-          onCancel={() => this.props.pageContainer.setState({ isConflictDiffModalOpen: false })}
+          onClose={() => this.props.pageContainer.setState({ isConflictDiffModalOpen: false })}
           appContainer={this.props.appContainer}
           pageContainer={this.props.pageContainer}
           editorContainer={this.props.editorContainer}