Skip to content

Commit eac3c94

Browse files
committed
Fix bugs
1 parent e923f8a commit eac3c94

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface Room {
2-
roomId: string,
3-
attemptStartedAt: string,
4-
userIdOne: string,
5-
userIdTwo: string,
6-
questionId: string,
2+
roomId: string;
3+
attemptStartedAt: string;
4+
userIdOne: { _id: string };
5+
userIdTwo: { _id: string };
6+
questionId: string;
77
}

frontend/src/presentation/pages/CollaborationRoomPage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { toast } from "react-toastify";
1818

1919
const CollaborationRoomPage: React.FC = () => {
2020
const location = useLocation();
21-
const user = useAuth();
21+
const { user } = useAuth();
2222
const locationState = location.state;
2323

2424
// State Definitions
@@ -32,7 +32,6 @@ const CollaborationRoomPage: React.FC = () => {
3232

3333
// Extract details from location.state if available
3434
const { roomId, attemptStartedAt, matchUserId, questionId } = locationState || {};
35-
3635
const handleResize = useCallback(() => {
3736
if (resizeTimeoutRef.current) {
3837
clearTimeout(resizeTimeoutRef.current);
@@ -49,22 +48,21 @@ const CollaborationRoomPage: React.FC = () => {
4948
try {
5049
// Check if location.state has all required details
5150
const hasAllDetails = roomId && attemptStartedAt && matchUserId && questionId;
52-
5351
if (hasAllDetails) {
5452
// Populate room with details from location.state
5553
setRoom({
5654
roomId: roomId,
5755
attemptStartedAt: attemptStartedAt,
58-
userIdOne: user.user!._id,
59-
userIdTwo: matchUserId,
56+
userIdOne: { _id: user!._id },
57+
userIdTwo: { _id: matchUserId },
6058
questionId: questionId
6159
});
6260
} else {
6361
if (!urlRoomId) return;
6462
// Fetch room details from API
6563
const fetchedRoom = await roomUseCases.getRoomDetails(urlRoomId);
6664
// Ensure the current user is userIdOne
67-
if (fetchedRoom.userIdOne !== user.user?._id) {
65+
if (fetchedRoom.userIdOne._id !== user?._id) {
6866
const temp = fetchedRoom.userIdOne;
6967
fetchedRoom.userIdOne = fetchedRoom.userIdTwo;
7068
fetchedRoom.userIdTwo = temp;
@@ -79,10 +77,10 @@ const CollaborationRoomPage: React.FC = () => {
7977
setLoading(false);
8078
}
8179
};
82-
if (user.user) {
80+
if (user) {
8381
populateRoom();
8482
}
85-
}, [roomId, attemptStartedAt, matchUserId, questionId, user.user?._id, user.user, urlRoomId]);
83+
}, [roomId, attemptStartedAt, matchUserId, questionId, user, urlRoomId]);
8684

8785
useEffect(() => {
8886
const fetchQuestion = async () => {
@@ -169,7 +167,7 @@ const CollaborationRoomPage: React.FC = () => {
169167
questionId={room.questionId}
170168
roomId={room.roomId}
171169
attemptStartedAt={new Date(room.attemptStartedAt)}
172-
collaboratorId={room.userIdTwo}
170+
collaboratorId={room.userIdTwo?._id}
173171
/>
174172
</div>
175173

0 commit comments

Comments
 (0)