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

Push router.push when file is uploaded

Shun Miyazawa 3 лет назад
Родитель
Сommit
1d4af54996

+ 11 - 8
packages/app/src/components/PageEditor.tsx

@@ -318,6 +318,16 @@ const PageEditor = React.memo((): JSX.Element => {
       const attachment = res.attachment;
       const fileName = attachment.originalName;
 
+      // when if created newly
+      if (res.pageCreated) {
+        logger.info('Page is created', res.page._id);
+        globalEmitter.emit('resetInitializedHackMdStatus');
+        mutateGrant(res.page.grant);
+        
+        mutateIsEnabledUnsavedWarning(false);
+        await router.push(`/${res.page._id}#edit`);
+      }
+
       let insertText = `[${fileName}](${attachment.filePathProxied})`;
       // when image
       if (attachment.fileFormat.startsWith('image/')) {
@@ -325,13 +335,6 @@ const PageEditor = React.memo((): JSX.Element => {
         insertText = `!${insertText}`;
       }
       editorRef.current.insertText(insertText);
-
-      // when if created newly
-      if (res.pageCreated) {
-        logger.info('Page is created', res.page._id);
-        globalEmitter.emit('resetInitializedHackMdStatus');
-        mutateGrant(res.page.grant);
-      }
     }
     catch (e) {
       logger.error('failed to upload', e);
@@ -340,7 +343,7 @@ const PageEditor = React.memo((): JSX.Element => {
     finally {
       editorRef.current.terminateUploadingState();
     }
-  }, [currentPagePath, mutateGrant, pageId]);
+  }, [currentPagePath, mutateGrant, pageId, router]);
 
 
   const scrollPreviewByEditorLine = useCallback((line: number) => {

+ 1 - 5
packages/app/src/server/routes/attachment.js

@@ -1,5 +1,3 @@
-import { pathUtils } from '@growi/core';
-
 import { SupportedAction } from '~/interfaces/activity';
 import { AttachmentType } from '~/server/interfaces/attachment';
 import loggerFactory from '~/utils/logger';
@@ -470,12 +468,10 @@ module.exports = function(crowi, app) {
     if (pageId == null) {
       logger.debug('Create page before file upload');
 
-      const fixedPageBody = pageBody ?? pathUtils.attachTitleHeader(pagePath);
-
       const isAclEnabled = crowi.aclService.isAclEnabled();
       const grant = isAclEnabled ? Page.GRANT_OWNER : Page.GRANT_PUBLIC;
 
-      page = await crowi.pageService.create(pagePath, fixedPageBody, req.user, { grant });
+      page = await crowi.pageService.create(pagePath, pageBody ?? '', req.user, { grant });
       pageCreated = true;
       pageId = page._id;
     }