Skip to content

Commit 7f942fb

Browse files
committed
Added cursor position streaming and better ux all over
1 parent 2a6940e commit 7f942fb

File tree

20 files changed

+133
-932
lines changed

20 files changed

+133
-932
lines changed

apps/http-server/dist/controllers/roomControllers.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1212
exports.createRoomController = createRoomController;
1313
exports.joinRoomController = joinRoomController;
1414
exports.fetchAllRoomsController = fetchAllRoomsController;
15+
exports.fetchRoomByIdController = fetchRoomByIdController;
1516
const client_1 = require("@workspace/db/client");
1617
const utils_1 = require("../utils");
1718
const common_1 = require("@workspace/common");
@@ -178,3 +179,33 @@ function fetchAllRoomsController(req, res) {
178179
}
179180
});
180181
}
182+
function fetchRoomByIdController(req, res) {
183+
return __awaiter(this, void 0, void 0, function* () {
184+
const userId = req.userId;
185+
const roomId = req.params.roomId;
186+
if (!userId) {
187+
res.status(401).json({ message: "User Id not found" });
188+
return;
189+
}
190+
if (!roomId) {
191+
res.status(400).json({ message: "Room Id required" });
192+
return;
193+
}
194+
try {
195+
const existingRooms = yield client_1.db.select().from(client_1.roomsTable).where((0, drizzle_orm_1.eq)(client_1.roomsTable.id, roomId));
196+
const room = existingRooms[0];
197+
if (!room) {
198+
res.status(404).json({ message: "Room not found" });
199+
return;
200+
}
201+
res.json({
202+
message: "Room fetched successfully",
203+
room,
204+
});
205+
}
206+
catch (e) {
207+
console.log(e);
208+
res.status(500).json({ message: "Error fetching room" });
209+
}
210+
});
211+
}

apps/http-server/dist/routes/roomRouter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ const router = (0, express_1.Router)();
77
router.route("/create").post(authenticateUser_1.authenticateUser, roomControllers_1.createRoomController);
88
router.route("/join").post(authenticateUser_1.authenticateUser, roomControllers_1.joinRoomController);
99
router.route("/all").get(authenticateUser_1.authenticateUser, roomControllers_1.fetchAllRoomsController);
10+
router.route("/:roomId").get(authenticateUser_1.authenticateUser, roomControllers_1.fetchRoomByIdController);
1011
exports.default = router;

apps/web/components/auth/SigninForm.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import { signinAction } from "@/actions/authActions";
1616
import { useFormStatus } from "react-dom";
1717
import { useActionState, useEffect } from "react";
1818
import { BiInfoCircle } from "react-icons/bi";
19-
import { redirect } from "next/navigation";
20-
import { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";
19+
import { useRouter } from "next/navigation";
20+
21+
interface RequestCookie {
22+
name: string;
23+
value: string;
24+
}
2125
import { setUser } from "@/lib/features/meetdraw/appSlice";
2226
import { useAppDispatch, useAppSelector } from "@/lib/hooks/redux";
2327
import { toast } from "@workspace/ui/components/sonner";
@@ -47,13 +51,14 @@ export default function SigninForm({
4751
const [state, formAction] = useActionState(signinAction, initialState);
4852
const userState = useAppSelector((state) => state.app.user);
4953
const dispatch = useAppDispatch();
54+
const router = useRouter();
5055

5156
useEffect(() => {
5257
const sessionUser = sessionStorage.getItem("user");
5358

5459
if (sessionUser && jwtCookie && jwtCookie.value) {
5560
dispatch(setUser(JSON.parse(sessionUser)));
56-
redirect("/home");
61+
router.replace("/home");
5762
} else if (state.user) {
5863
const user = {
5964
id: state.user.id,
@@ -67,7 +72,7 @@ export default function SigninForm({
6772

6873
useEffect(() => {
6974
if (jwtCookie && jwtCookie.value && userState !== null) {
70-
redirect("/home");
75+
router.replace("/home");
7176
}
7277
}, [userState]);
7378

apps/web/components/auth/SignupForm.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import Link from "next/link";
1616
import { signupAction } from "@/actions/authActions";
1717
import { useFormStatus } from "react-dom";
1818
import { useActionState, useEffect } from "react";
19-
import { redirect } from "next/navigation";
20-
import { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";
19+
import { useRouter } from "next/navigation";
20+
21+
interface RequestCookie {
22+
name: string;
23+
value: string;
24+
}
2125
import { setUser } from "@/lib/features/meetdraw/appSlice";
2226
import { useAppDispatch, useAppSelector } from "@/lib/hooks/redux";
2327
import { toast } from "@workspace/ui/components/sonner";
@@ -47,13 +51,14 @@ export default function SignupForm({
4751
const [state, formAction] = useActionState(signupAction, initialState);
4852
const dispatch = useAppDispatch();
4953
const userState = useAppSelector((state) => state.app.user);
54+
const router = useRouter();
5055

5156
useEffect(() => {
5257
const sessionUser = sessionStorage.getItem("user");
5358

5459
if (sessionUser && jwtCookie && jwtCookie.value) {
5560
dispatch(setUser(JSON.parse(sessionUser)));
56-
redirect("/home");
61+
router.replace("/home");
5762
} else if (state.user) {
5863
const user = {
5964
id: state.user.id,
@@ -67,7 +72,7 @@ export default function SignupForm({
6772

6873
useEffect(() => {
6974
if (jwtCookie && jwtCookie.value && userState) {
70-
redirect("/home");
75+
router.replace("/home");
7176
}
7277
}, [userState]);
7378

apps/web/components/canvas/Canvas.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { TbZoom } from "react-icons/tb";
5252
import { GrRedo, GrUndo } from "react-icons/gr";
5353
import { AiOutlineHome } from "react-icons/ai";
5454
import { BiCopy } from "react-icons/bi";
55-
import { redirect } from "next/navigation";
55+
import { useRouter } from "next/navigation";
5656
import { useAppDispatch, useAppSelector } from "@/lib/hooks/redux";
5757
import { setUser, setActiveRoom } from "@/lib/features/meetdraw/appSlice";
5858
import { useWebSocket } from "@/lib/hooks/websocket";
@@ -84,6 +84,7 @@ const Canvas = ({ roomId, token }: { roomId: string; token: string }) => {
8484
const [showChatBar, setShowChatBar] = useState(false);
8585
const canvasRef = useRef<HTMLCanvasElement>(null);
8686
const [isClient, setIsClient] = useState(false);
87+
const router = useRouter();
8788
const { socket, isLoading, isError } = useWebSocket(
8889
`${process.env.NEXT_PUBLIC_WS_URL}?token=${token}`
8990
);
@@ -178,7 +179,7 @@ const Canvas = ({ roomId, token }: { roomId: string; token: string }) => {
178179

179180
useEffect(() => {
180181
if (!token) {
181-
redirect("/signin");
182+
router.replace("/signin");
182183
}
183184

184185
if (!user) {
@@ -1580,7 +1581,7 @@ const Canvas = ({ roomId, token }: { roomId: string; token: string }) => {
15801581
className={`bg-transparent relative p-2 hover:bg-green-600/20 cursor-pointer`}
15811582
onClick={() => {
15821583
closeSocket();
1583-
redirect("/home");
1584+
router.replace("/home");
15841585
}}
15851586
>
15861587
<AiOutlineHome className="text-white" size="18" />

apps/web/components/home/ChatRoom.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { useAppDispatch, useAppSelector } from "@/lib/hooks/redux";
33
import { toast } from "@workspace/ui/components/sonner";
44
import { setHomeView } from "@/lib/features/meetdraw/appSlice";
55
import { useWebSocket } from "@/lib/hooks/websocket";
6-
import { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";
76
import { useEffect, useRef, useState } from "react";
8-
import { redirect } from "next/navigation";
7+
import { useRouter } from "next/navigation";
8+
9+
interface RequestCookie {
10+
name: string;
11+
value: string;
12+
}
913
import { Button } from "@workspace/ui/components/button";
1014
import { IoSend } from "react-icons/io5";
1115
import { WebSocketMessage } from "@workspace/common";
@@ -31,6 +35,7 @@ const ChatRoom = ({ jwtCookie }: { jwtCookie: RequestCookie }) => {
3135
const userState = useAppSelector((state) => state.app.user);
3236
const [serverReady, setServerReady] = useState(false);
3337
const dispatch = useAppDispatch();
38+
const router = useRouter();
3439
const inputRef = useRef<HTMLTextAreaElement>(null);
3540
const [messages, setMessages] = useState<Message[]>();
3641
const chatDivRef = useRef<HTMLDivElement>(null);
@@ -129,7 +134,8 @@ const ChatRoom = ({ jwtCookie }: { jwtCookie: RequestCookie }) => {
129134
toast.error("Please sign in to chat", {
130135
description: "You must be signed in to chat",
131136
});
132-
redirect("/signin");
137+
router.replace("/signin");
138+
return null;
133139
}
134140

135141
if (!activeRoom) {

apps/web/components/home/CreateRoomView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import SubmitButton from "../common/SubmitButton";
66
import { RxCross1 } from "react-icons/rx";
77
import { createRoomAction } from "@/actions/roomActions";
88
import { useEffect } from "react";
9-
import { redirect } from "next/navigation";
9+
import { useRouter } from "next/navigation";
1010
import { useAppDispatch } from "@/lib/hooks/redux";
1111
import { setHomeView } from "@/lib/features/meetdraw/appSlice";
1212

1313
const CreateRoomView = () => {
1414
const dispatch = useAppDispatch();
15+
const router = useRouter();
1516
const [state, formAction, isPending] = useActionState(createRoomAction, {
1617
message: "",
1718
room: undefined,
1819
});
1920

2021
useEffect(() => {
2122
if (state.room) {
22-
redirect(`/canvas/${state.room.id}`);
23+
router.push(`/canvas/${state.room.id}`);
2324
}
2425
}, [state.room]);
2526

apps/web/components/home/JoinRoomView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ import FormInput from "../common/FormInput";
55
import SubmitButton from "../common/SubmitButton";
66
import { RxCross1 } from "react-icons/rx";
77
import { joinRoomAction } from "@/actions/roomActions";
8-
import { redirect } from "next/navigation";
8+
import { useRouter } from "next/navigation";
99
import { setHomeView } from "@/lib/features/meetdraw/appSlice";
1010
import { useAppDispatch } from "@/lib/hooks/redux";
1111

1212
const JoinRoomView = () => {
1313
const dispatch = useAppDispatch();
14+
const router = useRouter();
1415
const [state, formAction, isPending] = useActionState(joinRoomAction, {
1516
message: "",
1617
room: undefined,
1718
});
1819

1920
useEffect(() => {
2021
if (state.room) {
21-
redirect(`/canvas/${state.room.id}`);
22+
router.push(`/canvas/${state.room.id}`);
2223
}
2324
}, [state.room]);
2425

apps/web/components/home/LinkButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import { Button } from "@workspace/ui/components/button";
3-
import { redirect, RedirectType } from "next/navigation";
3+
import { useRouter } from "next/navigation";
44
import { ReactNode } from "react";
55

66
export interface LinkButtonprops {
@@ -16,9 +16,10 @@ const LinkButton = ({
1616
variant,
1717
className,
1818
}: LinkButtonprops) => {
19+
const router = useRouter();
1920
return (
2021
<Button
21-
onClick={() => redirect(href)}
22+
onClick={() => router.push(href)}
2223
className={`overflow-clip relative p-0 cursor-pointer transition-all duration-500 hover:bg-black hover:text-white border border-black hover:border-green-600/30 ${className}`}
2324
>
2425
{variant === "ghost" ? (

apps/web/components/home/MainPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { useEffect, useRef, useState } from "react";
88
import StateButton from "./StateButton";
99
import CreateRoomView from "./CreateRoomView";
1010
import JoinRoomView from "./JoinRoomView";
11-
import { RequestCookie } from "next/dist/compiled/@edge-runtime/cookies";
1211
import { useAppDispatch, useAppSelector } from "@/lib/hooks/redux";
13-
import { redirect } from "next/navigation";
12+
import { useRouter } from "next/navigation";
13+
14+
interface RequestCookie {
15+
name: string;
16+
value: string;
17+
}
1418
import {
1519
setHomeView,
1620
setRooms,
@@ -32,10 +36,11 @@ const MainPage = ({
3236
}) => {
3337
const userState = useAppSelector((state) => state.app.user);
3438
const dispatch = useAppDispatch();
39+
const router = useRouter();
3540

3641
useEffect(() => {
3742
if (!jwtCookie || !jwtCookie.value) {
38-
redirect("/signin");
43+
router.replace("/signin");
3944
}
4045
if (!userState) {
4146
const user = JSON.parse(sessionStorage.getItem("user")!);

0 commit comments

Comments
 (0)