Yuken Tezuka 3 лет назад
Родитель
Сommit
9746197110
2 измененных файлов с 9 добавлено и 3 удалено
  1. 5 1
      packages/app/src/pages/[[...path]].page.tsx
  2. 4 2
      packages/app/src/stores/editor.tsx

+ 5 - 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,10 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
     }
   }, [props.currentPathname, router]);
 
+  useEffect(() => {
+    mutateEditingMarkdown(pageWithMeta?.data.revision?.body);
+  }, [mutateEditingMarkdown, pageWithMeta?.data.revision?.body]);
+
   const isTopPagePath = isTopPage(pageWithMeta?.data.path ?? '');
 
   const title = generateCustomTitleForPage(props, pagePath ?? '');

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

@@ -10,15 +10,17 @@ 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();
+  const { data: currentPagePath } = useCurrentPathname();
+
   return useStaticSWR(['editingMarkdown', currentPagePath], initialData);
 };