Просмотр исходного кода

declear and use SocketEventName

kaori 3 лет назад
Родитель
Сommit
cd2330caa5

+ 8 - 6
packages/app/src/components/Admin/ElasticsearchManagement/ElasticsearchManagement.tsx

@@ -5,9 +5,11 @@ import { useTranslation } from 'next-i18next';
 
 import { toastSuccess, toastError } from '~/client/util/apiNotification';
 import { apiv3Get, apiv3Post, apiv3Put } from '~/client/util/apiv3-client';
+import { SocketEventName } from '~/interfaces/websocket';
 import { useIsSearchServiceReachable } from '~/stores/context';
 import { useAdminSocket } from '~/stores/socket-io';
 
+
 import NormalizeIndicesControls from './NormalizeIndicesControls';
 import RebuildIndexControls from './RebuildIndexControls';
 import ReconnectControls from './ReconnectControls';
@@ -65,24 +67,24 @@ const ElasticsearchManagement = () => {
     if (socket == null) {
       return;
     }
-    socket.on('addPageProgress', (data) => {
+    socket.on(SocketEventName.AddPageProgress, (data) => {
       setIsRebuildingProcessing(true);
     });
 
-    socket.on('finishAddPage', async(data) => {
+    socket.on(SocketEventName.FinishAddPage, async(data) => {
       await retrieveIndicesStatus();
       setIsRebuildingProcessing(false);
       setIsRebuildingCompleted(true);
     });
 
-    socket.on('rebuildingFailed', (data) => {
+    socket.on(SocketEventName.RebuildingFailed, (data) => {
       toastError(new Error(data.error), 'Rebuilding Index has failed.');
     });
 
     return () => {
-      socket.off('addPageProgress');
-      socket.off('finishAddPage');
-      socket.off('rebuildingFailed');
+      socket.off(SocketEventName.AddPageProgress);
+      socket.off(SocketEventName.FinishAddPage);
+      socket.off(SocketEventName.RebuildingFailed);
     };
   }, [socket]);
 

+ 6 - 0
packages/app/src/interfaces/websocket.ts

@@ -11,6 +11,12 @@ export const SocketEventName = {
   // Page migration
   PageMigrationSuccess: 'PageMigrationSuccess',
   PageMigrationError: 'PageMigrationError',
+
+  // Elasticsearch
+  AddPageProgress: 'addPageProgress',
+  FinishAddPage: 'finishAddPage',
+  RebuildingFailed: 'rebuildingFailed',
+
 } as const;
 export type SocketEventName = typeof SocketEventName[keyof typeof SocketEventName];