@@ -23,16 +23,16 @@ const { API_BASE_URL } = config;
23
23
const RoomsContainer = ( ) => {
24
24
const [ roomCode , setRoomCode ] = useState ( '' ) ;
25
25
const [ userName , setUserName ] = useState ( '' ) ;
26
- const [ userList , setUserList ] = useState ( new Map ( ) ) ;
27
- // const [confirmRoom, setConfirmRoom] = useState('');
28
26
const [ userJoined , setUserJoined ] = useState ( false ) ; //setting up state for joinning a room
29
- const [ emptyInput , setEmptyInput ] = useState ( false ) ;
30
27
31
28
const dispatch = useDispatch ( ) ;
32
- const { state, joinedRoom } = useSelector ( ( store : RootState ) => ( {
33
- state : store . appState ,
34
- joinedRoom : store . roomCodeSlice . roomCode
35
- } ) ) ;
29
+ const { state, joinedRoom } = useSelector (
30
+ ( store : RootState ) => ( {
31
+ state : store . appState ,
32
+ joinedRoom : store . roomCodeSlice . roomCode ,
33
+ } )
34
+ ) ;
35
+
36
36
React . useEffect ( ( ) => {
37
37
console . log ( 'You Joined Room: ' , joinedRoom ) ;
38
38
} , [ joinedRoom ] ) ;
@@ -52,24 +52,19 @@ const RoomsContainer = () => {
52
52
socket . emit ( 'join-room' , roomCode ) ; // Join the room when connected
53
53
//passing current client nickname to server
54
54
console . log ( `Your Nickname Is: ${ userName } ` ) ;
55
- socket . emit ( 'user ' , userName ) ;
55
+ socket . emit ( 'userJoined ' , userName ) ;
56
56
} ) ;
57
-
58
- // // Receiving the room state from the backend
59
- // socket.on('room-state-update', (stateFromServer) => {
60
- // const newState = JSON.parse(stateFromServer);
61
- // // Dispatch actions to update your Redux store with the received state
62
- // store.dispatch(allCooperativeState(newState.appState));
63
- // store.dispatch(codePreviewCooperative(newState.codePreviewCooperative));
64
- // store.dispatch(cooperativeStyle(newState.styleSlice));
65
- // });
57
+
66
58
67
59
// receiving the message from the back end
68
60
socket . on ( 'receive message' , ( event ) => {
69
61
let currentStore : any = JSON . stringify ( store . getState ( ) ) ;
62
+ console . log ( 'event ' , event ) ;
70
63
if ( currentStore !== event ) {
71
64
currentStore = JSON . parse ( currentStore ) ;
72
65
event = JSON . parse ( event ) ;
66
+ console . log ( 'current store' , currentStore ) ;
67
+ console . log ( 'event ' , event ) ;
73
68
if ( currentStore . appState !== event . appState ) {
74
69
store . dispatch ( allCooperativeState ( event . appState ) ) ;
75
70
} else if (
@@ -110,6 +105,7 @@ const RoomsContainer = () => {
110
105
) ;
111
106
previousState = newState ;
112
107
}
108
+
113
109
} , 100 ) ;
114
110
115
111
store . subscribe ( ( ) => {
0 commit comments