Skip to content

Commit

Permalink
feat: 클라이언트 remote checkbox 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pipisebastian committed Dec 2, 2024
1 parent 4ef910e commit a618f79
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/src/stores/useSocketStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RemoteCharDeleteOperation,
RemoteBlockUpdateOperation,
RemoteBlockReorderOperation,
RemoteBlockCheckboxOperation,
RemoteCharUpdateOperation,
RemotePageDeleteOperation,
RemotePageUpdateOperation,
Expand Down Expand Up @@ -77,6 +78,7 @@ interface SocketStore {
subscribeToPageOperations: (handlers: PageOperationsHandlers) => (() => void) | undefined;
setWorkspace: (workspace: WorkSpaceSerializedProps) => void;
sendOperation: (operation: any) => void;
sendBlockCheckboxOperation: (operation: RemoteBlockCheckboxOperation) => void;
}

interface RemoteOperationHandlers {
Expand All @@ -89,6 +91,7 @@ interface RemoteOperationHandlers {
onRemoteCharUpdate: (operation: RemoteCharUpdateOperation) => void;
onRemoteCursor: (position: CursorPosition) => void;
onBatchOperations: (batch: any[]) => void;
onRemoteBlockCheckbox: (operation: RemoteBlockCheckboxOperation) => void;
}

interface PageOperationsHandlers {
Expand Down Expand Up @@ -274,6 +277,11 @@ export const useSocketStore = create<SocketStore>((set, get) => ({
// sendOperation(operation);
},

sendBlockCheckboxOperation: (operation: RemoteBlockCheckboxOperation) => {
const { socket } = get();
socket?.emit("checkbox/block", operation);
},

subscribeToRemoteOperations: (handlers: RemoteOperationHandlers) => {
const { socket } = get();
if (!socket) return;
Expand All @@ -287,6 +295,7 @@ export const useSocketStore = create<SocketStore>((set, get) => ({
socket.on("update/char", handlers.onRemoteCharUpdate);
socket.on("cursor", handlers.onRemoteCursor);
socket.on("batch/operations", handlers.onBatchOperations);
socket.on("checkbox/block", handlers.onRemoteBlockCheckbox);

return () => {
socket.off("update/block", handlers.onRemoteBlockUpdate);
Expand All @@ -298,6 +307,7 @@ export const useSocketStore = create<SocketStore>((set, get) => ({
socket.off("update/char", handlers.onRemoteCharUpdate);
socket.off("cursor", handlers.onRemoteCursor);
socket.off("batch/operations", handlers.onBatchOperations);
socket.off("checkbox/block", handlers.onRemoteBlockCheckbox);
};
},

Expand Down

0 comments on commit a618f79

Please sign in to comment.