Преглед на файлове

Merge branch 'master' into fix/slack-channels-are-not-automatically-filled-after-setting-user-trigger-notification

kaori преди 3 години
родител
ревизия
ff414cc852
променени са 2 файла, в които са добавени 24 реда и са изтрити 19 реда
  1. 5 7
      packages/app/src/components/Page/TrashPageAlert.jsx
  2. 19 12
      packages/app/src/components/PageEditor.tsx

+ 5 - 7
packages/app/src/components/Page/TrashPageAlert.jsx

@@ -1,18 +1,17 @@
 import React, { useState } from 'react';
-import PropTypes from 'prop-types';
 
-import { withTranslation } from 'react-i18next';
 
 import { UserPicture } from '@growi/ui';
-import { withUnstatedContainers } from '../UnstatedUtils';
-import AppContainer from '~/client/services/AppContainer';
-import PageContainer from '~/client/services/PageContainer';
+import PropTypes from 'prop-types';
+import { withTranslation } from 'react-i18next';
 
+import PageContainer from '~/client/services/PageContainer';
 import { useCurrentUpdatedAt, useShareLinkId } from '~/stores/context';
 import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
 import { useSWRxPageInfo } from '~/stores/page';
 
 import EmptyTrashModal from '../EmptyTrashModal';
+import { withUnstatedContainers } from '../UnstatedUtils';
 
 const onDeletedHandler = (pathOrPathsToDelete, isRecursively, isCompletely) => {
   if (typeof pathOrPathsToDelete !== 'string') {
@@ -145,12 +144,11 @@ const TrashPageAlert = (props) => {
 /**
  * Wrapper component for using unstated
  */
-const TrashPageAlertWrapper = withUnstatedContainers(TrashPageAlert, [AppContainer, PageContainer]);
+const TrashPageAlertWrapper = withUnstatedContainers(TrashPageAlert, [PageContainer]);
 
 
 TrashPageAlert.propTypes = {
   t: PropTypes.func.isRequired, // i18next
-  appContainer: PropTypes.instanceOf(AppContainer).isRequired,
   pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
 };
 

+ 19 - 12
packages/app/src/components/PageEditor.tsx

@@ -129,7 +129,7 @@ const PageEditor = (props: Props): JSX.Element => {
       editorContainer.disableUnsavedWarning();
 
       // eslint-disable-next-line no-unused-vars
-      const { page, tags } = await pageContainer.save(markdown, editorMode, optionsToSave);
+      const { tags } = await pageContainer.save(markdown, editorMode, optionsToSave);
       logger.debug('success to save');
 
       pageContainer.showSuccessToastr();
@@ -305,18 +305,11 @@ const PageEditor = (props: Props): JSX.Element => {
     appContainer.registerComponentInstance('PageEditor', pageEditorInstance);
   }, [appContainer, markdown]);
 
-  // set handler to update editor value
+  // initial caret line
   useEffect(() => {
-    const handler = (markdown) => {
-      if (editorRef.current != null) {
-        editorRef.current.setValue(markdown);
-      }
-    };
-    window.globalEmitter.on('updateEditorValue', handler);
-
-    return function cleanup() {
-      window.globalEmitter.removeListener('updateEditorValue', handler);
-    };
+    if (editorRef.current != null) {
+      editorRef.current.setCaretLine(0);
+    }
   }, []);
 
   // set handler to set caret line
@@ -343,6 +336,20 @@ const PageEditor = (props: Props): JSX.Element => {
     }
   }, [editorMode]);
 
+  // set handler to update editor value
+  useEffect(() => {
+    const handler = (markdown) => {
+      if (editorRef.current != null) {
+        editorRef.current.setValue(markdown);
+      }
+    };
+    window.globalEmitter.on('updateEditorValue', handler);
+
+    return function cleanup() {
+      window.globalEmitter.removeListener('updateEditorValue', handler);
+    };
+  }, []);
+
   // Displays an alert if there is a difference with pageContainer's markdown
   useEffect(() => {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion