Skip to content

Commit 549be86

Browse files
committed
fix: FE 미반영 커밋 반영
1 parent 3b1f63d commit 549be86

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/frontend/src/api/load-balancer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ type getRoomNumberBody = {
66
urlId: string;
77
};
88

9-
export async function getRoomNumber(type: string, spaceUrlPath: string) {
9+
export async function getRoomNumber(
10+
type: "note" | "space",
11+
spaceUrlPath: string | undefined,
12+
) {
1013
const response = await http.get<getRoomNumberBody>(
1114
`/lb/${type}/${spaceUrlPath}`,
1215
);

packages/frontend/src/components/note/Editor.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useState } from "react";
12
import { useParams } from "react-router-dom";
23

34
import { Milkdown, MilkdownProvider } from "@milkdown/react";
@@ -6,6 +7,7 @@ import { ProsemirrorAdapterProvider } from "@prosemirror-adapter/react";
67

78
import { WS_URL } from "@/api/constants";
89
import useMilkdownCollab from "@/hooks/useMilkdownCollab";
10+
import { getRoomNumber } from "@/api/load-balancer";
911
import useMilkdownEditor from "@/hooks/useMilkdownEditor";
1012

1113
import { BlockView } from "./Block";
@@ -14,13 +16,28 @@ import "./Editor.css";
1416
function MilkdownEditor() {
1517
const { noteId } = useParams<Record<"noteId", string>>();
1618

19+
const [roomNumber, setRoomNumber] = useState<string>();
20+
21+
useEffect(() => {
22+
const requestRoomNumber = async () => {
23+
const response = await getRoomNumber("note", noteId);
24+
return response.server;
25+
};
26+
27+
const initRoomNumber = async () => {
28+
const roomNumber = await requestRoomNumber();
29+
setRoomNumber(roomNumber);
30+
};
31+
32+
initRoomNumber();
33+
}, [noteId]);
1734
const { loading, get } = useMilkdownEditor({
1835
BlockView,
1936
});
2037

2138
useMilkdownCollab({
2239
editor: loading ? null : get() || null,
23-
websocketUrl: `${WS_URL}/note`,
40+
websocketUrl: roomNumber ? `${WS_URL}/${roomNumber}/note` : null,
2441
roomName: noteId || "",
2542
});
2643
return <Milkdown />;

packages/frontend/src/hooks/useMilkdownCollab.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as Y from "yjs";
88

99
type useMilkdownCollabProps = {
1010
editor: Editor | null;
11-
websocketUrl: string;
11+
websocketUrl: string | null;
1212
roomName: string;
1313
};
1414

@@ -21,6 +21,7 @@ export default function useMilkdownCollab({
2121
}: useMilkdownCollabProps) {
2222
useEffect(() => {
2323
if (!editor) return undefined;
24+
if (!websocketUrl) return undefined;
2425

2526
const doc = new Y.Doc();
2627

0 commit comments

Comments
 (0)