Shun Miyazawa 1 год назад
Родитель
Сommit
6afaf2e848

+ 3 - 2
apps/app/src/client/services/side-effects/yjs.ts

@@ -3,14 +3,15 @@ import { useCallback, useEffect } from 'react';
 import { useGlobalSocket } from '@growi/core/dist/swr';
 import { useGlobalSocket } from '@growi/core/dist/swr';
 
 
 import { SocketEventName } from '~/interfaces/websocket';
 import { SocketEventName } from '~/interfaces/websocket';
+import { type CurrentPageYjsDraft } from '~/interfaces/yjs';
 import { useCurrentPageYjsData } from '~/stores/yjs';
 import { useCurrentPageYjsData } from '~/stores/yjs';
 
 
 export const useYjsDraftEffect = (): void => {
 export const useYjsDraftEffect = (): void => {
   const { data: socket } = useGlobalSocket();
   const { data: socket } = useGlobalSocket();
   const { updateHasDraft } = useCurrentPageYjsData();
   const { updateHasDraft } = useCurrentPageYjsData();
 
 
-  const yjsDraftUpdateHandler = useCallback(((hasDraft: boolean) => {
-    updateHasDraft(hasDraft);
+  const yjsDraftUpdateHandler = useCallback(((currentPageYjsDraft: CurrentPageYjsDraft) => {
+    updateHasDraft(currentPageYjsDraft.hasYjsDraft);
   }), [updateHasDraft]);
   }), [updateHasDraft]);
 
 
   useEffect(() => {
   useEffect(() => {

+ 5 - 0
apps/app/src/interfaces/yjs.ts

@@ -0,0 +1,5 @@
+export type CurrentPageYjsDraft = {
+  hasYjsDraft: boolean,
+}
+
+export const CurrentPageYjsDraftData = { hasYjsDraft: true };

+ 2 - 2
apps/app/src/server/service/socket-io.js

@@ -1,8 +1,8 @@
 import { GlobalSocketEventName } from '@growi/core/dist/interfaces';
 import { GlobalSocketEventName } from '@growi/core/dist/interfaces';
 import { Server } from 'socket.io';
 import { Server } from 'socket.io';
 
 
-// import { CurrentPageYjsDraftData } from '~/interfaces/page';
 import { SocketEventName } from '~/interfaces/websocket';
 import { SocketEventName } from '~/interfaces/websocket';
+import { CurrentPageYjsDraftData } from '~/interfaces/yjs';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -175,7 +175,7 @@ class SocketIoService {
         // Emit to the client in the room of the target pageId.
         // Emit to the client in the room of the target pageId.
         this.io
         this.io
           .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
           .in(getRoomNameWithId(RoomPrefix.PAGE, pageId))
-          .emit(SocketEventName.YjsDraftUpdated, true);
+          .emit(SocketEventName.YjsDraftUpdated, CurrentPageYjsDraftData);
 
 
         yjsConnectionManager.ysocketio.on('awareness-update', async(update) => {
         yjsConnectionManager.ysocketio.on('awareness-update', async(update) => {
           const awarenessStateSize = update.awareness.states.size;
           const awarenessStateSize = update.awareness.states.size;