|
@@ -6,30 +6,17 @@ import { SocketEventName } from '~/interfaces/websocket';
|
|
|
import { type CurrentPageYjsDraft } from '~/interfaces/yjs';
|
|
import { type CurrentPageYjsDraft } from '~/interfaces/yjs';
|
|
|
import { useCurrentPageYjsData } from '~/stores/yjs';
|
|
import { useCurrentPageYjsData } from '~/stores/yjs';
|
|
|
|
|
|
|
|
-export const useYjsDraftEffect = (): void => {
|
|
|
|
|
|
|
+export const useCurrentPageYjsDataEffect = (): void => {
|
|
|
const { data: socket } = useGlobalSocket();
|
|
const { data: socket } = useGlobalSocket();
|
|
|
- const { updateHasDraft } = useCurrentPageYjsData();
|
|
|
|
|
|
|
+ const { updateHasDraft, updateHasRevisionBodyDiff, updateAwarenessStateSize } = useCurrentPageYjsData();
|
|
|
|
|
|
|
|
const yjsDraftUpdateHandler = useCallback(((currentPageYjsDraft: CurrentPageYjsDraft) => {
|
|
const yjsDraftUpdateHandler = useCallback(((currentPageYjsDraft: CurrentPageYjsDraft) => {
|
|
|
updateHasDraft(currentPageYjsDraft.hasYjsDraft);
|
|
updateHasDraft(currentPageYjsDraft.hasYjsDraft);
|
|
|
}), [updateHasDraft]);
|
|
}), [updateHasDraft]);
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
-
|
|
|
|
|
- if (socket == null) { return }
|
|
|
|
|
-
|
|
|
|
|
- socket.on(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
|
|
|
|
|
-
|
|
|
|
|
- return () => {
|
|
|
|
|
- socket.off(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- }, [socket, yjsDraftUpdateHandler]);
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-export const useYjsAwarenessStateEffect = (): void => {
|
|
|
|
|
- const { data: socket } = useGlobalSocket();
|
|
|
|
|
- const { updateAwarenessStateSize } = useCurrentPageYjsData();
|
|
|
|
|
|
|
+ const yjsHasRevisionBodyDiffUpdateHandler = useCallback((hasRevisionBodyDiff: boolean) => {
|
|
|
|
|
+ updateHasRevisionBodyDiff(hasRevisionBodyDiff);
|
|
|
|
|
+ }, [updateHasRevisionBodyDiff]);
|
|
|
|
|
|
|
|
const yjsAwarenessStateUpdateHandler = useCallback(((awarenessStateSize: number) => {
|
|
const yjsAwarenessStateUpdateHandler = useCallback(((awarenessStateSize: number) => {
|
|
|
updateAwarenessStateSize(awarenessStateSize);
|
|
updateAwarenessStateSize(awarenessStateSize);
|
|
@@ -39,12 +26,15 @@ export const useYjsAwarenessStateEffect = (): void => {
|
|
|
|
|
|
|
|
if (socket == null) { return }
|
|
if (socket == null) { return }
|
|
|
|
|
|
|
|
|
|
+ socket.on(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
|
|
|
|
|
+ socket.on(SocketEventName.YjsHasRevisionBodyDiffUpdated, yjsHasRevisionBodyDiffUpdateHandler);
|
|
|
socket.on(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
|
|
socket.on(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
|
|
|
|
|
|
|
|
return () => {
|
|
return () => {
|
|
|
|
|
+ socket.off(SocketEventName.YjsDraftUpdated, yjsDraftUpdateHandler);
|
|
|
|
|
+ socket.off(SocketEventName.YjsHasRevisionBodyDiffUpdated, yjsHasRevisionBodyDiffUpdateHandler);
|
|
|
socket.off(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
|
|
socket.off(SocketEventName.YjsAwarenessStateUpdated, yjsAwarenessStateUpdateHandler);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- }, [socket, yjsAwarenessStateUpdateHandler]);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }, [socket, yjsAwarenessStateUpdateHandler, yjsDraftUpdateHandler, yjsHasRevisionBodyDiffUpdateHandler]);
|
|
|
};
|
|
};
|