Yuki Takei 3 лет назад
Родитель
Сommit
47701a1183
2 измененных файлов с 17 добавлено и 11 удалено
  1. 7 5
      packages/app/src/components/Page.tsx
  2. 10 6
      packages/app/src/stores/modal.tsx

+ 7 - 5
packages/app/src/components/Page.tsx

@@ -63,6 +63,13 @@ export const Page = (props) => {
 
   const saveOrUpdate = useSaveOrUpdate();
 
+
+  useEffect(() => {
+    mutateCurrentPageTocNode(tocRef.current);
+  // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [mutateCurrentPageTocNode, tocRef.current]); // include tocRef.current to call mutateCurrentPageTocNode when tocRef.current changes
+
+
   const saveByDrawioModal = useCallback(async(drawioMxFile: string, bol: number, eol: number) => {
     if (currentPage == null || tagsInfo == null) {
       return;
@@ -99,11 +106,6 @@ export const Page = (props) => {
     }
   }, [currentPage, mutateCurrentPage, saveOrUpdate, t, tagsInfo]);
 
-  useEffect(() => {
-    mutateCurrentPageTocNode(tocRef.current);
-  // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [mutateCurrentPageTocNode, tocRef.current]); // include tocRef.current to call mutateCurrentPageTocNode when tocRef.current changes
-
   // set handler to open DrawioModal
   useEffect(() => {
     const handler = (data: DrawioEditByViewerProps) => {

+ 10 - 6
packages/app/src/stores/modal.tsx

@@ -1,3 +1,5 @@
+import { useCallback } from 'react';
+
 import { SWRResponse } from 'swr';
 
 import MarkdownTable from '~/client/models/MarkdownTable';
@@ -467,13 +469,15 @@ export const useDrawioModal = (status?: DrawioModalStatus): SWRResponse<DrawioMo
   };
   const swrResponse = useStaticSWR<DrawioModalStatus, Error>('drawioModalStatus', status, { fallbackData: initialData });
 
-  const open = (drawioMxFile: string, onSave?: DrawioModalSaveHandler): void => {
-    swrResponse.mutate({ isOpened: true, drawioMxFile, onSave });
-  };
+  const { mutate } = swrResponse;
 
-  const close = (): void => {
-    swrResponse.mutate({ isOpened: false, drawioMxFile: '', onSave: undefined });
-  };
+  const open = useCallback((drawioMxFile: string, onSave?: DrawioModalSaveHandler): void => {
+    mutate({ isOpened: true, drawioMxFile, onSave });
+  }, [mutate]);
+
+  const close = useCallback((): void => {
+    mutate({ isOpened: false, drawioMxFile: '', onSave: undefined });
+  }, [mutate]);
 
   return {
     ...swrResponse,