Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f62ea4c

Browse filesBrowse files
committed
refactor: Merge standalone and collaborative canvas into a unified component
1 parent 37e9c3c commit f62ea4c
Copy full SHA for f62ea4c

File tree

25 files changed

+515
-433
lines changed
Filter options

25 files changed

+515
-433
lines changed

‎.github/workflows/cd_frontend.yml

Copy file name to clipboardExpand all lines: .github/workflows/cd_frontend.yml
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ jobs:
5555
run: |
5656
echo "${{ secrets.SSH_PRIVATE_KEY }}" | head -n 15
5757
58-
- name: Deploy to VM
59-
uses: appleboy/ssh-action@v1.1.0
60-
with:
61-
host: ${{ secrets.VM_HOST }}
62-
username: ${{ secrets.VM_USERNAME }}
63-
key: ${{ secrets.SSH_PRIVATE_KEY }}
64-
script: |
65-
docker pull coderomm/collabydraw:${{ github.sha }}
66-
docker stop collabydraw-frontend || true
67-
docker rm collabydraw-frontend || true
68-
docker run -d \
69-
--name collabydraw-frontend \
70-
--restart always \
71-
-p 3000:3000 \
72-
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
73-
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \
74-
-e WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }} \
75-
coderomm/collabydraw:${{ github.sha }}
58+
# - name: Deploy to VM
59+
# uses: appleboy/ssh-action@v1.1.0
60+
# with:
61+
# host: ${{ secrets.VM_HOST }}
62+
# username: ${{ secrets.VM_USERNAME }}
63+
# key: ${{ secrets.SSH_PRIVATE_KEY }}
64+
# script: |
65+
# docker pull coderomm/collabydraw:${{ github.sha }}
66+
# docker stop collabydraw-frontend || true
67+
# docker rm collabydraw-frontend || true
68+
# docker run -d \
69+
# --name collabydraw-frontend \
70+
# --restart always \
71+
# -p 3000:3000 \
72+
# -e DATABASE_URL=${{ secrets.DATABASE_URL }} \
73+
# -e JWT_SECRET=${{ secrets.JWT_SECRET }} \
74+
# -e WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }} \
75+
# coderomm/collabydraw:${{ github.sha }}
7676

‎.github/workflows/cd_ws.yml

Copy file name to clipboardExpand all lines: .github/workflows/cd_ws.yml
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ jobs:
3838
run: |
3939
echo "${{ secrets.SSH_PRIVATE_KEY }}" | head -n 15
4040
41-
- name: Deploy to VM
42-
uses: appleboy/ssh-action@v1.1.0
43-
with:
44-
host: ${{ secrets.VM_HOST }}
45-
username: ${{ secrets.VM_USERNAME }}
46-
key: ${{ secrets.SSH_PRIVATE_KEY }}
47-
script: |
48-
docker pull coderomm/collabydraw-websocket:${{ github.sha }}
49-
docker stop collabydraw-websocket || true
50-
docker rm collabydraw-websocket || true
51-
docker run -d \
52-
--name collabydraw-websocket \
53-
--restart always \
54-
-p 8080:8080 \
55-
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
56-
coderomm/collabydraw-websocket:${{ github.sha }}
41+
# - name: Deploy to VM
42+
# uses: appleboy/ssh-action@v1.1.0
43+
# with:
44+
# host: ${{ secrets.VM_HOST }}
45+
# username: ${{ secrets.VM_USERNAME }}
46+
# key: ${{ secrets.SSH_PRIVATE_KEY }}
47+
# script: |
48+
# docker pull coderomm/collabydraw-websocket:${{ github.sha }}
49+
# docker stop collabydraw-websocket || true
50+
# docker rm collabydraw-websocket || true
51+
# docker run -d \
52+
# --name collabydraw-websocket \
53+
# --restart always \
54+
# -p 8080:8080 \
55+
# -e DATABASE_URL=${{ secrets.DATABASE_URL }} \
56+
# coderomm/collabydraw-websocket:${{ github.sha }}

‎apps/collabydraw/actions/room.ts

Copy file name to clipboardExpand all lines: apps/collabydraw/actions/room.ts
+8-19Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import { z } from "zod";
44
import client from "@repo/db/client";
5-
import { CreateRoomSchema, JoinRoomSchema } from "@repo/common/types";
65
import { getServerSession } from "next-auth";
76
import { authOptions } from "@/utils/auth";
87
import { cookies } from "next/headers";
98

10-
export async function joinRoom(data: { roomName: string }) {
9+
export async function joinRoom(data: { id: string }) {
1110
try {
12-
const validatedRoomName = JoinRoomSchema.parse(data);
13-
1411
const room = await client.room.findUnique({
15-
where: { slug: validatedRoomName.roomName },
12+
where: { id: data.id },
1613
});
1714

1815
if (!room) {
@@ -37,7 +34,7 @@ export async function joinRoom(data: { roomName: string }) {
3734

3835
return {
3936
success: true,
40-
roomName: room.slug,
37+
room: room,
4138
};
4239
} catch (error) {
4340
if (error instanceof z.ZodError) {
@@ -48,7 +45,7 @@ export async function joinRoom(data: { roomName: string }) {
4845
}
4946
}
5047

51-
export async function createRoom(data: { roomName: string }) {
48+
export async function createRoom() {
5249
try {
5350
const session = await getServerSession(authOptions);
5451
const user = session?.user;
@@ -57,11 +54,8 @@ export async function createRoom(data: { roomName: string }) {
5754
return { success: false, error: "User not found" };
5855
}
5956

60-
const validatedRoomName = CreateRoomSchema.parse(data);
61-
6257
const room = await client.room.create({
6358
data: {
64-
slug: validatedRoomName.roomName,
6559
adminId: user.id,
6660
},
6761
});
@@ -83,12 +77,10 @@ export async function createRoom(data: { roomName: string }) {
8377
}
8478
}
8579

86-
export async function getRoom(data: { roomName: string }) {
80+
export async function getRoom(data: { id: string }) {
8781
try {
88-
const validatedRoomName = JoinRoomSchema.parse(data);
89-
9082
const room = await client.room.findUnique({
91-
where: { slug: validatedRoomName.roomName },
83+
where: { id: data.id },
9284
include: { Shape: true },
9385
});
9486

@@ -125,18 +117,16 @@ export async function getRoom(data: { roomName: string }) {
125117
}
126118
}
127119

128-
export async function deleteRoom(data: { roomName: string }) {
120+
export async function deleteRoom(data: { id: string }) {
129121
try {
130122
const session = await getServerSession(authOptions);
131123

132124
if (!session || !session.user || !session.user.id) {
133125
return { success: false, error: "Authentication required" };
134126
}
135127

136-
const validatedRoomName = JoinRoomSchema.parse(data);
137-
138128
const room = await client.room.findUnique({
139-
where: { slug: validatedRoomName.roomName },
129+
where: { id: data.id },
140130
include: { admin: true },
141131
});
142132

@@ -182,7 +172,6 @@ export async function getUserRooms() {
182172
where: { adminId: user.id },
183173
select: {
184174
id: true,
185-
slug: true,
186175
createdAt: true,
187176
updatedAt: true,
188177
},

‎apps/collabydraw/actions/shape.ts

Copy file name to clipboard
+84-84Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
1-
"use server";
2-
3-
import { z } from "zod";
4-
import client from "@repo/db/client";
5-
import { JoinRoomSchema } from "@repo/common/types";
6-
import { getServerSession } from "next-auth";
7-
import { authOptions } from "@/utils/auth";
8-
import { Shape } from "@/types/canvas";
9-
10-
export async function getShapes(data: { roomName: string }) {
11-
try {
12-
const validatedRoomName = JoinRoomSchema.parse(data);
13-
14-
const room = await client.room.findUnique({
15-
where: { slug: validatedRoomName.roomName },
16-
});
17-
18-
if (!room || !room.id) {
19-
return { success: false, error: "Room not found" };
20-
}
21-
22-
const shapesResponse = await client.shape.findMany({
23-
where: { roomId: room.id },
24-
});
25-
26-
if (!shapesResponse.length) {
27-
return { success: true, shapes: [] };
28-
}
29-
30-
const shapes: Shape[] = shapesResponse.map((x) => JSON.parse(x.message));
31-
32-
return { success: true, shapes };
33-
} catch (error) {
34-
if (error instanceof z.ZodError) {
35-
return { success: false, error: "Invalid room code format" };
36-
}
37-
console.error("Failed to get shapes:", error);
38-
return { success: false, error: "Failed to get shapes" };
39-
}
40-
}
41-
42-
export async function clearAllShapes(data: { roomName: string }) {
43-
try {
44-
const session = await getServerSession(authOptions);
45-
46-
if (!session || !session.user || !session.user.email) {
47-
return { success: false, error: "Authentication required" };
48-
}
49-
50-
const userEmail = session.user.email;
51-
const validatedRoomName = JoinRoomSchema.parse(data);
52-
53-
const room = await client.room.findUnique({
54-
where: { slug: validatedRoomName.roomName },
55-
include: { admin: true },
56-
});
57-
58-
if (!room || !room.id) {
59-
return { success: false, error: "Room not found" };
60-
}
61-
62-
if (room.admin.email !== userEmail) {
63-
return {
64-
success: false,
65-
error: "Unauthorized: Only the room creator can clear chats",
66-
};
67-
}
68-
69-
const result = await client.shape.deleteMany({
70-
where: { roomId: room.id },
71-
});
72-
73-
return {
74-
success: true,
75-
count: result.count,
76-
};
77-
} catch (error) {
78-
if (error instanceof z.ZodError) {
79-
return { success: false, error: "Invalid room code format" };
80-
}
81-
console.error("Failed to clear shapes:", error);
82-
return { success: false, error: "Failed to clear shapes" };
83-
}
84-
}
1+
// "use server";
2+
3+
// import { z } from "zod";
4+
// import client from "@repo/db/client";
5+
// import { JoinRoomSchema } from "@repo/common/types";
6+
// import { getServerSession } from "next-auth";
7+
// import { authOptions } from "@/utils/auth";
8+
// import { Shape } from "@/types/canvas";
9+
10+
// export async function getShapes(data: { roomName: string }) {
11+
// try {
12+
// const validatedRoomName = JoinRoomSchema.parse(data);
13+
14+
// const room = await client.room.findUnique({
15+
// where: { slug: validatedRoomName.roomName },
16+
// });
17+
18+
// if (!room || !room.id) {
19+
// return { success: false, error: "Room not found" };
20+
// }
21+
22+
// const shapesResponse = await client.shape.findMany({
23+
// where: { roomId: room.id },
24+
// });
25+
26+
// if (!shapesResponse.length) {
27+
// return { success: true, shapes: [] };
28+
// }
29+
30+
// const shapes: Shape[] = shapesResponse.map((x) => JSON.parse(x.message));
31+
32+
// return { success: true, shapes };
33+
// } catch (error) {
34+
// if (error instanceof z.ZodError) {
35+
// return { success: false, error: "Invalid room code format" };
36+
// }
37+
// console.error("Failed to get shapes:", error);
38+
// return { success: false, error: "Failed to get shapes" };
39+
// }
40+
// }
41+
42+
// export async function clearAllShapes(data: { roomName: string }) {
43+
// try {
44+
// const session = await getServerSession(authOptions);
45+
46+
// if (!session || !session.user || !session.user.email) {
47+
// return { success: false, error: "Authentication required" };
48+
// }
49+
50+
// const userEmail = session.user.email;
51+
// const validatedRoomName = JoinRoomSchema.parse(data);
52+
53+
// const room = await client.room.findUnique({
54+
// where: { slug: validatedRoomName.roomName },
55+
// include: { admin: true },
56+
// });
57+
58+
// if (!room || !room.id) {
59+
// return { success: false, error: "Room not found" };
60+
// }
61+
62+
// if (room.admin.email !== userEmail) {
63+
// return {
64+
// success: false,
65+
// error: "Unauthorized: Only the room creator can clear chats",
66+
// };
67+
// }
68+
69+
// const result = await client.shape.deleteMany({
70+
// where: { roomId: room.id },
71+
// });
72+
73+
// return {
74+
// success: true,
75+
// count: result.count,
76+
// };
77+
// } catch (error) {
78+
// if (error instanceof z.ZodError) {
79+
// return { success: false, error: "Invalid room code format" };
80+
// }
81+
// console.error("Failed to clear shapes:", error);
82+
// return { success: false, error: "Failed to clear shapes" };
83+
// }
84+
// }

‎apps/collabydraw/app/(canvas)/room/[roomName]/page.tsx

Copy file name to clipboardExpand all lines: apps/collabydraw/app/(canvas)/room/[roomName]/page.tsx
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function CanvasPage({ params }: { params: Promise<{ roomNam
1010
const decodedParam = decodeURIComponent(paramsRoomName)
1111

1212
const room = await client.room.findFirst({
13-
where: { slug: decodedParam },
13+
where: { id: decodedParam },
1414
});
1515
if (!room) {
1616
notFound();
@@ -26,7 +26,7 @@ export default async function CanvasPage({ params }: { params: Promise<{ roomNam
2626
return (
2727
<CanvasSheet
2828
roomId={room.id.toString()}
29-
roomName={room.slug}
29+
roomName={room.id}
3030
userId={user.id}
3131
userName={user.name || 'User-' + user.id}
3232
token={session.accessToken}
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CanvasRoot from "@/components/canvas/CanvasRoot";
2+
3+
export default async function Room() {
4+
return (
5+
<CanvasRoot />
6+
)
7+
}

‎apps/collabydraw/app/(main)/page.tsx

Copy file name to clipboard
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { StandaloneCanvas } from "@/components/canvas/StandaloneCanvas";
1+
import CanvasRoot from "@/components/canvas/CanvasRoot";
22

33
export default async function Home() {
44
return (
5-
<StandaloneCanvas />
5+
<CanvasRoot />
66
)
77
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.