Преглед изворни кода

Fixed behavior when duplicating pages from SubNavButtons

Shun Miyazawa пре 3 година
родитељ
комит
a4e7e73bcb
1 измењених фајлова са 7 додато и 4 уклоњено
  1. 7 4
      packages/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

+ 7 - 4
packages/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -19,7 +19,7 @@ import {
   useCurrentPageId, useCurrentPathname, useIsNotFound,
   useCurrentUser, useIsGuestUser, useIsSharedUser, useShareLinkId, useTemplateTagData, useIsContainerFluid, useIsIdenticalPath,
 } from '~/stores/context';
-import { usePageTagsForEditors } from '~/stores/editor';
+import { usePageTagsForEditors, useEditingMarkdown } from '~/stores/editor';
 import {
   usePageAccessoriesModal, PageAccessoriesModalContents, IPageForPageDuplicateModal,
   usePageDuplicateModal, usePageRenameModal, usePageDeleteModal, usePagePresentationModal,
@@ -228,6 +228,8 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
   const { open: openDeleteModal } = usePageDeleteModal();
   const { data: templateTagData } = useTemplateTagData();
 
+  const { mutate: mutateEditingMarkdown } = useEditingMarkdown();
+
   const updateStateAfterSave = useUpdateStateAfterSave(pageId);
 
   const path = currentPage?.path ?? currentPathname;
@@ -285,11 +287,12 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
   }, [currentPathname, router]);
 
   const duplicateItemClickedHandler = useCallback(async(page: IPageForPageDuplicateModal) => {
-    const duplicatedHandler: OnDuplicatedFunction = (fromPath, toPath) => {
-      router.push(toPath);
+    const duplicatedHandler: OnDuplicatedFunction = async(fromPath, toPath) => {
+      await router.push(toPath);
+      mutateEditingMarkdown(revision?.body);
     };
     openDuplicateModal(page, { onDuplicated: duplicatedHandler });
-  }, [openDuplicateModal, router]);
+  }, [mutateEditingMarkdown, openDuplicateModal, revision?.body, router]);
 
   const renameItemClickedHandler = useCallback(async(page: IPageToRenameWithMeta<IPageInfoForEntity>) => {
     const renamedHandler: OnRenamedFunction = () => {