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

Merge pull request #7301 from weseek/fix/refactor-useEditingMarkdown

fix: Delete updated contents when save with shortcut
Yuki Takei пре 3 година
родитељ
комит
a7786bef0e
2 измењених фајлова са 12 додато и 3 уклоњено
  1. 6 1
      packages/app/src/pages/[[...path]].page.tsx
  2. 6 2
      packages/app/src/stores/editor.tsx

+ 6 - 1
packages/app/src/pages/[[...path]].page.tsx

@@ -285,7 +285,7 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
 
   useSWRxCurrentPage(pageWithMeta?.data ?? null); // store initial data
 
-  useEditingMarkdown(pageWithMeta?.data.revision?.body);
+  const { mutate: mutateEditingMarkdown } = useEditingMarkdown();
 
   const { data: grantData } = useSWRxIsGrantNormalized(pageId);
   const { mutate: mutateSelectedGrant } = useSelectedGrant();
@@ -314,6 +314,11 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
     }
   }, [props.currentPathname, router]);
 
+  // initialize mutateEditingMarkdown only once per page
+  useEffect(() => {
+    mutateEditingMarkdown(pageWithMeta?.data.revision?.body);
+  }, [mutateEditingMarkdown, pageWithMeta?.data.revision?.body]);
+
   const isTopPagePath = isTopPage(pageWithMeta?.data.path ?? '');
 
   const title = generateCustomTitleForPage(props, pagePath ?? '');

+ 6 - 2
packages/app/src/stores/editor.tsx

@@ -10,15 +10,19 @@ import { IEditorSettings } from '~/interfaces/editor-settings';
 import { SlackChannels } from '~/interfaces/user-trigger-notification';
 
 import {
+  useCurrentPathname,
   useCurrentUser, useDefaultIndentSize, useIsGuestUser,
 } from './context';
 // import { localStorageMiddleware } from './middlewares/sync-to-storage';
-import { useCurrentPagePath, useSWRxTagsInfo } from './page';
+import { useSWRxTagsInfo } from './page';
 import { useStaticSWR } from './use-static-swr';
 
 
 export const useEditingMarkdown = (initialData?: string): SWRResponse<string, Error> => {
-  const { data: currentPagePath } = useCurrentPagePath();
+  // need to include useCurrentPathname not useCurrentPagePath
+  // https://github.com/weseek/growi/pull/7301
+  const { data: currentPagePath } = useCurrentPathname();
+
   return useStaticSWR(['editingMarkdown', currentPagePath], initialData);
 };