Skip to content

Commit 380d08b

Browse files
Merge pull request #339 from boostcampwm-2024/bug-fe-#338
소켓 룸 이름 통일
2 parents 0f880fd + 08dd43e commit 380d08b

File tree

4 files changed

+15
-116
lines changed

4 files changed

+15
-116
lines changed

apps/frontend/src/features/canvas/model/useCanvas.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const useCanvas = () => {
3838
const { cursors, handleMouseMove, handleNodeDrag, handleMouseLeave } =
3939
useCollaborativeCursors({
4040
ydoc,
41-
roomName: `flow-room-${workspace}`,
4241
});
4342

4443
const provider = useRef<SocketIOProvider>();
@@ -81,7 +80,7 @@ export const useCanvas = () => {
8180
const existingNode = nodesMap.get(pageId) as YNode;
8281

8382
const newNode: YNode = {
84-
id: pageId,
83+
id: existingNode.id,
8584
type: "note",
8685
data: { title: value, id: pageId, emoji: existingNode.data.emoji },
8786
position: existingNode.position,
@@ -116,7 +115,7 @@ export const useCanvas = () => {
116115
useEffect(() => {
117116
if (!ydoc) return;
118117

119-
const wsProvider = createSocketIOProvider("flow-room", ydoc);
118+
const wsProvider = createSocketIOProvider(`flow-room-${workspace}`, ydoc);
120119

121120
provider.current = wsProvider;
122121

apps/frontend/src/features/canvas/model/useCollaborativeCursors.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useReactFlow, type XYPosition } from "@xyflow/react";
55

66
import { createSocketIOProvider } from "@/shared/api/socketProvider";
77
import { useUserStore } from "@/entities/user/model/userStore";
8+
import { useWorkspace } from "@/shared/lib/useWorkspace";
89

910
export interface AwarenessState {
1011
cursor: XYPosition | null;
@@ -14,13 +15,9 @@ export interface AwarenessState {
1415

1516
interface CollaborativeCursorsProps {
1617
ydoc: Y.Doc;
17-
roomName?: string;
1818
}
1919

20-
export function useCollaborativeCursors({
21-
ydoc,
22-
roomName = "cursor-room",
23-
}: CollaborativeCursorsProps) {
20+
export function useCollaborativeCursors({ ydoc }: CollaborativeCursorsProps) {
2421
const flowInstance = useReactFlow();
2522
const provider = useRef<SocketIOProvider>();
2623
const [cursors, setCursors] = useState<Map<number, AwarenessState>>(
@@ -29,8 +26,10 @@ export function useCollaborativeCursors({
2926
const { currentUser } = useUserStore();
3027
const { color, clientId } = currentUser;
3128

29+
const workspace = useWorkspace();
30+
3231
useEffect(() => {
33-
const wsProvider = createSocketIOProvider("flow-room", ydoc);
32+
const wsProvider = createSocketIOProvider(`flow-room-${workspace}`, ydoc);
3433
provider.current = wsProvider;
3534

3635
wsProvider.awareness.setLocalState({
@@ -53,7 +52,7 @@ export function useCollaborativeCursors({
5352
return () => {
5453
wsProvider.destroy();
5554
};
56-
}, [ydoc, roomName, color, clientId]);
55+
}, [ydoc, color, clientId, workspace]);
5756

5857
const updateCursorPosition = useCallback(
5958
(x: number | null, y: number | null) => {

apps/frontend/src/features/workspace/ui/ShareTool/SharePanel.tsx

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,27 @@
11
import { Switch } from "@/shared/ui/Switch";
22
import { Globe2, Lock, Copy, CheckCheck } from "lucide-react";
3-
import { useState, useEffect } from "react";
4-
import {
5-
useWorkspaceStatus,
6-
useToggleWorkspaceStatus,
7-
} from "@/features/workspace/model/useWorkspaceStatus";
8-
import { useCreateWorkspaceInviteLink } from "@/features/workspace/model/useWorkspaceInvite";
9-
import { useWorkspace } from "@/shared/lib/useWorkspace";
10-
import { useInviteLinkStore } from "@/features/workspace/model/useInviteLinkStore";
11-
12-
const createFrontendUrl = (apiUrl: string, currentWorkspaceId: string) => {
13-
const searchParams = new URLSearchParams();
14-
15-
searchParams.set("workspaceId", currentWorkspaceId);
16-
searchParams.set("token", new URL(apiUrl).searchParams.get("token") || "");
17-
return `${window.location.origin}/join?${searchParams.toString()}`;
18-
};
3+
import { useState } from "react";
194

205
export function SharePanel() {
216
const [copied, setCopied] = useState(false);
22-
const currentWorkspaceId = useWorkspace();
23-
const workspaceStatus = useWorkspaceStatus();
24-
25-
const { inviteLink, setInviteLink } = useInviteLinkStore();
26-
27-
const { mutate: toggleStatus, isPending: isTogglingStatus } =
28-
useToggleWorkspaceStatus(workspaceStatus);
29-
const { mutate: createLink, isPending: isCreatingLink } =
30-
useCreateWorkspaceInviteLink();
31-
32-
const isPublic = workspaceStatus === "public";
33-
const isLoading = isTogglingStatus || isCreatingLink;
7+
const [isPublic, setIsPublic] = useState(false);
348

35-
useEffect(() => {
36-
if (isPublic) {
37-
setInviteLink(window.location.href);
38-
} else if (!inviteLink && currentWorkspaceId) {
39-
createLink(currentWorkspaceId, {
40-
onSuccess: (inviteUrl) => {
41-
const frontendUrl = createFrontendUrl(inviteUrl, currentWorkspaceId);
42-
setInviteLink(frontendUrl);
43-
},
44-
});
45-
}
46-
}, [isPublic, currentWorkspaceId]);
9+
const url = "https://octodocs.com";
4710

4811
const handleCopy = async () => {
49-
const linkToCopy = isPublic ? window.location.href : inviteLink;
50-
if (!linkToCopy) return;
51-
52-
await navigator.clipboard.writeText(linkToCopy);
12+
await navigator.clipboard.writeText(url);
5313
setCopied(true);
5414
setTimeout(() => setCopied(false), 2000);
5515
};
5616

57-
const handleSwitchChange = () => {
58-
toggleStatus();
59-
};
60-
61-
const displayedLink = isPublic ? window.location.href : inviteLink;
62-
6317
return (
6418
<div className="w-full">
6519
<div className="flex w-full items-center gap-2 p-1">
6620
<div className="flex-row text-sm text-slate-400">공개 범위</div>
6721
<div className="flex items-center space-x-2">
6822
<Switch
6923
checked={isPublic}
70-
onChange={handleSwitchChange}
24+
onChange={setIsPublic}
7125
CheckedIcon={Globe2}
7226
UncheckedIcon={Lock}
7327
/>
@@ -79,13 +33,13 @@ export function SharePanel() {
7933
}`}
8034
>
8135
<div className="w-48 flex-1 truncate rounded-md bg-gray-100 px-3 py-2 text-sm text-gray-600">
82-
{isLoading ? "링크 생성 중..." : displayedLink}
36+
{isPublic ? url : "비공개 모드입니다."}
8337
</div>
8438
<button
8539
onClick={handleCopy}
8640
className="inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-gray-100 disabled:cursor-not-allowed disabled:hover:bg-transparent"
8741
aria-label="Copy URL"
88-
disabled={isLoading || !displayedLink}
42+
disabled={!isPublic}
8943
>
9044
{copied ? (
9145
<CheckCheck className="h-4 w-4 text-green-500" />

apps/frontend/src/routes/join/index.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)