@@ -18,7 +18,7 @@ import { toast } from "react-toastify";
18
18
19
19
const CollaborationRoomPage : React . FC = ( ) => {
20
20
const location = useLocation ( ) ;
21
- const user = useAuth ( ) ;
21
+ const { user } = useAuth ( ) ;
22
22
const locationState = location . state ;
23
23
24
24
// State Definitions
@@ -32,7 +32,6 @@ const CollaborationRoomPage: React.FC = () => {
32
32
33
33
// Extract details from location.state if available
34
34
const { roomId, attemptStartedAt, matchUserId, questionId } = locationState || { } ;
35
-
36
35
const handleResize = useCallback ( ( ) => {
37
36
if ( resizeTimeoutRef . current ) {
38
37
clearTimeout ( resizeTimeoutRef . current ) ;
@@ -49,22 +48,21 @@ const CollaborationRoomPage: React.FC = () => {
49
48
try {
50
49
// Check if location.state has all required details
51
50
const hasAllDetails = roomId && attemptStartedAt && matchUserId && questionId ;
52
-
53
51
if ( hasAllDetails ) {
54
52
// Populate room with details from location.state
55
53
setRoom ( {
56
54
roomId : roomId ,
57
55
attemptStartedAt : attemptStartedAt ,
58
- userIdOne : user . user ! . _id ,
59
- userIdTwo : matchUserId ,
56
+ userIdOne : { _id : user ! . _id } ,
57
+ userIdTwo : { _id : matchUserId } ,
60
58
questionId : questionId
61
59
} ) ;
62
60
} else {
63
61
if ( ! urlRoomId ) return ;
64
62
// Fetch room details from API
65
63
const fetchedRoom = await roomUseCases . getRoomDetails ( urlRoomId ) ;
66
64
// Ensure the current user is userIdOne
67
- if ( fetchedRoom . userIdOne !== user . user ?. _id ) {
65
+ if ( fetchedRoom . userIdOne . _id !== user ?. _id ) {
68
66
const temp = fetchedRoom . userIdOne ;
69
67
fetchedRoom . userIdOne = fetchedRoom . userIdTwo ;
70
68
fetchedRoom . userIdTwo = temp ;
@@ -79,10 +77,10 @@ const CollaborationRoomPage: React.FC = () => {
79
77
setLoading ( false ) ;
80
78
}
81
79
} ;
82
- if ( user . user ) {
80
+ if ( user ) {
83
81
populateRoom ( ) ;
84
82
}
85
- } , [ roomId , attemptStartedAt , matchUserId , questionId , user . user ?. _id , user . user , urlRoomId ] ) ;
83
+ } , [ roomId , attemptStartedAt , matchUserId , questionId , user , urlRoomId ] ) ;
86
84
87
85
useEffect ( ( ) => {
88
86
const fetchQuestion = async ( ) => {
@@ -169,7 +167,7 @@ const CollaborationRoomPage: React.FC = () => {
169
167
questionId = { room . questionId }
170
168
roomId = { room . roomId }
171
169
attemptStartedAt = { new Date ( room . attemptStartedAt ) }
172
- collaboratorId = { room . userIdTwo }
170
+ collaboratorId = { room . userIdTwo ?. _id }
173
171
/>
174
172
</ div >
175
173
0 commit comments