|
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect } from 'react';
|
|
|
|
|
|
import type EventEmitter from 'events';
|
|
|
|
|
|
-import { Origin } from '@growi/core';
|
|
|
+import { Origin, GlobalSocketEventName } from '@growi/core';
|
|
|
import type { DrawioEditByViewerProps } from '@growi/remark-drawio';
|
|
|
|
|
|
import { extractRemoteRevisionDataFromErrorObj, updatePage as _updatePage } from '~/client/services/update-page';
|
|
|
@@ -11,6 +11,7 @@ import { useShareLinkId } from '~/stores/context';
|
|
|
import { useConflictDiffModal, useDrawioModal } from '~/stores/modal';
|
|
|
import { useSWRxCurrentPage } from '~/stores/page';
|
|
|
import { type RemoteRevisionData, useSetRemoteLatestPageData } from '~/stores/remote-latest-page';
|
|
|
+import { useDefaultSocket } from '~/stores/socket-io';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
@@ -28,6 +29,8 @@ export const useDrawioModalLauncherForView = (opts?: {
|
|
|
onSaveError?: (error: any) => void,
|
|
|
}): void => {
|
|
|
|
|
|
+ const { data: socket } = useDefaultSocket();
|
|
|
+
|
|
|
const { data: shareLinkId } = useShareLinkId();
|
|
|
|
|
|
const { data: currentPage } = useSWRxCurrentPage();
|
|
|
@@ -52,6 +55,8 @@ export const useDrawioModalLauncherForView = (opts?: {
|
|
|
origin: Origin.View,
|
|
|
});
|
|
|
|
|
|
+ socket?.emit(GlobalSocketEventName.YDocUpdate, { pageId: currentPage._id, newMarkdown });
|
|
|
+
|
|
|
closeConflictDiffModal();
|
|
|
opts?.onSaveSuccess?.();
|
|
|
}
|
|
|
@@ -64,7 +69,7 @@ export const useDrawioModalLauncherForView = (opts?: {
|
|
|
logger.error('failed to save', error);
|
|
|
opts?.onSaveError?.(error);
|
|
|
}
|
|
|
- }, [closeConflictDiffModal, currentPage, opts, shareLinkId]);
|
|
|
+ }, [closeConflictDiffModal, currentPage, opts, shareLinkId, socket]);
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
const generateResolveConflictHandler = useCallback((revisionId: string, onConflict: (conflictData: RemoteRevisionData, newMarkdown: string) => void) => {
|