Procházet zdrojové kódy

Relocate to stores/alert.tsx

Shun Miyazawa před 2 roky
rodič
revize
a07939fd84

+ 0 - 27
apps/app/src/client/services/update-page/conflict.ts

@@ -1,6 +1,4 @@
 import type { ErrorV3 } from '@growi/core/dist/models';
 import type { ErrorV3 } from '@growi/core/dist/models';
-import { useSWRStatic } from '@growi/core/dist/swr';
-import type { SWRResponse } from 'swr';
 
 
 import { PageUpdateErrorCode } from '~/interfaces/apiv3';
 import { PageUpdateErrorCode } from '~/interfaces/apiv3';
 import { type RemoteRevisionData } from '~/stores/remote-latest-page';
 import { type RemoteRevisionData } from '~/stores/remote-latest-page';
@@ -22,28 +20,3 @@ export const extractRemoteRevisionDataFromErrorObj = (errors: Array<ErrorV3>): R
     }
     }
   }
   }
 };
 };
-
-/*
-* PageStatusAlert
-*/
-type PageStatusAlertStatus = {
-  onConflict?: () => void,
-}
-
-type PageStatusAlertUtils = {
-  storeMethods: (conflictHandler: () => void) => void,
-  clearMethods: () => void,
-}
-export const usePageStatusAlert = (): SWRResponse<PageStatusAlertStatus, Error> & PageStatusAlertUtils => {
-  const swrResponse = useSWRStatic<PageStatusAlertStatus, Error>('pageStatusAlert', undefined);
-
-  return {
-    ...swrResponse,
-    storeMethods(onConflict) {
-      swrResponse.mutate({ onConflict });
-    },
-    clearMethods() {
-      swrResponse.mutate({});
-    },
-  };
-};

+ 2 - 1
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -20,10 +20,11 @@ import { throttle, debounce } from 'throttle-debounce';
 
 
 import { useShouldExpandContent } from '~/client/services/layout';
 import { useShouldExpandContent } from '~/client/services/layout';
 import { useUpdateStateAfterSave } from '~/client/services/page-operation';
 import { useUpdateStateAfterSave } from '~/client/services/page-operation';
-import { updatePage, extractRemoteRevisionDataFromErrorObj, usePageStatusAlert } from '~/client/services/update-page';
+import { updatePage, extractRemoteRevisionDataFromErrorObj } from '~/client/services/update-page';
 import { apiv3Get, apiv3PostForm } from '~/client/util/apiv3-client';
 import { apiv3Get, apiv3PostForm } from '~/client/util/apiv3-client';
 import { toastError, toastSuccess, toastWarning } from '~/client/util/toastr';
 import { toastError, toastSuccess, toastWarning } from '~/client/util/toastr';
 import { SocketEventName } from '~/interfaces/websocket';
 import { SocketEventName } from '~/interfaces/websocket';
+import { usePageStatusAlert } from '~/stores/alert';
 import {
 import {
   useDefaultIndentSize, useCurrentUser,
   useDefaultIndentSize, useCurrentUser,
   useCurrentPathname, useIsEnabledAttachTitleHeader,
   useCurrentPathname, useIsEnabledAttachTitleHeader,

+ 1 - 1
apps/app/src/components/PageStatusAlert.tsx

@@ -3,7 +3,7 @@ import React, { useCallback, useMemo } from 'react';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import * as ReactDOMServer from 'react-dom/server';
 import * as ReactDOMServer from 'react-dom/server';
 
 
-import { usePageStatusAlert } from '~/client/services/update-page/conflict';
+import { usePageStatusAlert } from '~/stores/alert';
 import { useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
 import { useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
 import { useEditingMarkdown } from '~/stores/editor';
 import { useEditingMarkdown } from '~/stores/editor';
 import { useSWRMUTxCurrentPage, useSWRxCurrentPage } from '~/stores/page';
 import { useSWRMUTxCurrentPage, useSWRxCurrentPage } from '~/stores/page';

+ 27 - 0
apps/app/src/stores/alert.tsx

@@ -0,0 +1,27 @@
+import { useSWRStatic } from '@growi/core/dist/swr';
+import type { SWRResponse } from 'swr';
+
+/*
+* PageStatusAlert
+*/
+type PageStatusAlertStatus = {
+  onConflict?: () => void,
+}
+
+type PageStatusAlertUtils = {
+  storeMethods: (conflictHandler: () => void) => void,
+  clearMethods: () => void,
+}
+export const usePageStatusAlert = (): SWRResponse<PageStatusAlertStatus, Error> & PageStatusAlertUtils => {
+  const swrResponse = useSWRStatic<PageStatusAlertStatus, Error>('pageStatusAlert', undefined);
+
+  return {
+    ...swrResponse,
+    storeMethods(onConflict) {
+      swrResponse.mutate({ onConflict });
+    },
+    clearMethods() {
+      swrResponse.mutate({});
+    },
+  };
+};