Taichi Masuyama 3 anni fa
parent
commit
2b50fb814b

+ 6 - 4
packages/app/src/components/PageEditor.tsx

@@ -69,7 +69,7 @@ const PageEditor = React.memo((): JSX.Element => {
   const { data: isTextlintEnabled } = useIsTextlintEnabled();
   const { data: isTextlintEnabled } = useIsTextlintEnabled();
   const { data: isIndentSizeForced } = useIsIndentSizeForced();
   const { data: isIndentSizeForced } = useIsIndentSizeForced();
   const { data: indentSize, mutate: mutateCurrentIndentSize } = useCurrentIndentSize();
   const { data: indentSize, mutate: mutateCurrentIndentSize } = useCurrentIndentSize();
-  const { mutate: mutateIsEnabledUnsavedWarning, optimisticMutate: optimisticMutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
+  const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
   const { data: isUploadableFile } = useIsUploadableFile();
   const { data: isUploadableFile } = useIsUploadableFile();
   const { data: isUploadableImage } = useIsUploadableImage();
   const { data: isUploadableImage } = useIsUploadableImage();
 
 
@@ -153,7 +153,7 @@ const PageEditor = React.memo((): JSX.Element => {
     }
     }
 
 
   // eslint-disable-next-line max-len
   // eslint-disable-next-line max-len
-  }, [grantData, isSlackEnabled, currentPathname, slackChannels, pageTags, pageId, currentPagePath, currentRevisionId, mutateCurrentPage, mutateIsEnabledUnsavedWarning]);
+  }, [grantData, isSlackEnabled, currentPathname, slackChannels, pageTags, pageId, currentPagePath, currentRevisionId]);
 
 
   const saveAndReturnToViewHandler = useCallback(async(opts?: {overwriteScopesOfDescendants: boolean}) => {
   const saveAndReturnToViewHandler = useCallback(async(opts?: {overwriteScopesOfDescendants: boolean}) => {
     if (editorMode !== EditorMode.Editor) {
     if (editorMode !== EditorMode.Editor) {
@@ -164,11 +164,13 @@ const PageEditor = React.memo((): JSX.Element => {
     if (page == null) {
     if (page == null) {
       return;
       return;
     }
     }
-    await optimisticMutateIsEnabledUnsavedWarning(false);
+    // The updateFn should be a promise or asynchronous function to handle the remote mutation
+    // it should return updated data. see: https://swr.vercel.app/docs/mutation#optimistic-updates
+    await mutateIsEnabledUnsavedWarning(async() => false, { optimisticData: false });
     // TODO: fix TAICHI
     // TODO: fix TAICHI
     await router.push(`/${page._id}`);
     await router.push(`/${page._id}`);
     mutateEditorMode(EditorMode.View);
     mutateEditorMode(EditorMode.View);
-  }, [editorMode, save, mutateEditorMode]);
+  }, [editorMode, save, mutateIsEnabledUnsavedWarning, router, mutateEditorMode]);
 
 
   const saveWithShortcut = useCallback(async() => {
   const saveWithShortcut = useCallback(async() => {
     if (editorMode !== EditorMode.Editor) {
     if (editorMode !== EditorMode.Editor) {

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

@@ -114,18 +114,6 @@ export const usePageTagsForEditors = (pageId: Nullable<string>): SWRResponse<str
   };
   };
 };
 };
 
 
-type IUtilsIsEnabledUnsavedWarning = {
-  optimisticMutate(data: boolean, options?: MutatorOptions): Promise<boolean | undefined>,
-};
-
-export const useIsEnabledUnsavedWarning = (): SWRResponseWithUtils<IUtilsIsEnabledUnsavedWarning, boolean, Error> => {
-  const swrResponse = useStaticSWR<boolean, Error>('isEnabledUnsavedWarning');
-
-  // The updateFn should be a promise or asynchronous function to handle the remote mutation
-  // it should return updated data. see: https://swr.vercel.app/docs/mutation#optimistic-updates
-  return withUtils(swrResponse, {
-    optimisticMutate: async(data: boolean, options: MutatorOptions = {}) => {
-      return swrResponse.mutate(async() => data, { ...options, optimisticData: data });
-    },
-  });
+export const useIsEnabledUnsavedWarning = (): SWRResponse<boolean, Error> => {
+  return useStaticSWR<boolean, Error>('isEnabledUnsavedWarning');
 };
 };