-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#168 블록 드래그앤드랍 서버 반영 #169
The head ref may contain hidden characters: "Feature/#168_\uBE14\uB85D_\uB4DC\uB798\uADF8\uC564\uB4DC\uB78D_\uC11C\uBC84_\uBC18\uC601"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
// hooks/useBlockDragAndDrop.ts | ||
import { DragEndEvent, PointerSensor, useSensor, useSensors } from "@dnd-kit/core"; | ||
import { EditorCRDT } from "@noctaCrdt/Crdt"; | ||
import { useSocketStore } from "@src/stores/useSocketStore.ts"; | ||
import { EditorStateProps } from "../Editor"; | ||
|
||
interface UseBlockDragAndDropProps { | ||
editorCRDT: EditorCRDT; | ||
editorState: EditorStateProps; | ||
setEditorState: React.Dispatch<React.SetStateAction<EditorStateProps>>; | ||
pageId: string; | ||
} | ||
|
||
export const useBlockDragAndDrop = ({ | ||
editorCRDT, | ||
editorState, | ||
setEditorState, | ||
pageId, | ||
}: UseBlockDragAndDropProps) => { | ||
const sensors = useSensors( | ||
useSensor(PointerSensor, { | ||
|
@@ -22,6 +25,8 @@ export const useBlockDragAndDrop = ({ | |
}), | ||
); | ||
|
||
const { sendBlockReorderOperation } = useSocketStore(); | ||
|
||
const handleDragEnd = (event: DragEndEvent) => { | ||
const { active, over } = event; | ||
|
||
|
@@ -73,12 +78,15 @@ export const useBlockDragAndDrop = ({ | |
} | ||
|
||
// EditorCRDT의 현재 상태로 작업 | ||
editorCRDT.localReorder({ | ||
const operation = editorCRDT.localReorder({ | ||
targetId: targetNode.id, | ||
beforeId: beforeNode?.id || null, | ||
afterId: afterNode?.id || null, | ||
pageId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희가 논의했던 방식으로 구현하셨네요. |
||
}); | ||
|
||
sendBlockReorderOperation(operation); | ||
|
||
// EditorState 업데이트 | ||
setEditorState({ | ||
clock: editorCRDT.clock, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
RemoteCharInsertOperation, | ||
RemoteBlockUpdateOperation, | ||
RemotePageCreateOperation, | ||
RemoteBlockReorderOperation, | ||
CursorPosition, | ||
} from "@noctaCrdt/Interfaces"; | ||
import { Logger } from "@nestjs/common"; | ||
|
@@ -362,6 +363,43 @@ export class CrdtGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa | |
} | ||
} | ||
|
||
@SubscribeMessage("reorder/block") | ||
async handleBlockReorder( | ||
@MessageBody() data: RemoteBlockReorderOperation, | ||
@ConnectedSocket() client: Socket, | ||
): Promise<void> { | ||
const clientInfo = this.clientMap.get(client.id); | ||
try { | ||
this.logger.debug( | ||
`블록 Reorder 연산 수신 - Client ID: ${clientInfo?.clientId}, Data:`, | ||
JSON.stringify(data), | ||
); | ||
// 1. 워크스페이스 가져오기 | ||
const workspace = this.workSpaceService.getWorkspace(); | ||
|
||
const currentPage = workspace.pageList.find((p) => p.id === data.pageId); | ||
if (!currentPage) { | ||
throw new Error(`Page with id ${data.pageId} not found`); | ||
} | ||
currentPage.crdt.remoteReorder(data); | ||
|
||
// 5. 다른 클라이언트들에게 업데이트된 블록 정보 브로드캐스트 | ||
const operation = { | ||
targetId: data.targetId, | ||
beforeId: data.beforeId, | ||
afterId: data.afterId, | ||
pageId: data.pageId, | ||
} as RemoteBlockReorderOperation; | ||
client.broadcast.emit("reorder/block", operation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
} catch (error) { | ||
this.logger.error( | ||
`블록 Reorder 연산 처리 중 오류 발생 - Client ID: ${clientInfo?.clientId}`, | ||
error.stack, | ||
); | ||
throw new WsException(`Update 연산 실패: ${error.message}`); | ||
} | ||
} | ||
|
||
/** | ||
* 커서 위치 업데이트 처리 | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
합니다이.. 할때마다 웃고 갑니다....