@@ -23,16 +23,16 @@ const { API_BASE_URL } = config;
2323const RoomsContainer = ( ) => {
2424 const [ roomCode , setRoomCode ] = useState ( '' ) ;
2525 const [ userName , setUserName ] = useState ( '' ) ;
26- const [ userList , setUserList ] = useState ( new Map ( ) ) ;
27- // const [confirmRoom, setConfirmRoom] = useState('');
2826 const [ userJoined , setUserJoined ] = useState ( false ) ; //setting up state for joinning a room
29- const [ emptyInput , setEmptyInput ] = useState ( false ) ;
3027
3128 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+
3636 React . useEffect ( ( ) => {
3737 console . log ( 'You Joined Room: ' , joinedRoom ) ;
3838 } , [ joinedRoom ] ) ;
@@ -52,24 +52,19 @@ const RoomsContainer = () => {
5252 socket . emit ( 'join-room' , roomCode ) ; // Join the room when connected
5353 //passing current client nickname to server
5454 console . log ( `Your Nickname Is: ${ userName } ` ) ;
55- socket . emit ( 'user ' , userName ) ;
55+ socket . emit ( 'userJoined ' , userName ) ;
5656 } ) ;
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+
6658
6759 // receiving the message from the back end
6860 socket . on ( 'receive message' , ( event ) => {
6961 let currentStore : any = JSON . stringify ( store . getState ( ) ) ;
62+ console . log ( 'event ' , event ) ;
7063 if ( currentStore !== event ) {
7164 currentStore = JSON . parse ( currentStore ) ;
7265 event = JSON . parse ( event ) ;
66+ console . log ( 'current store' , currentStore ) ;
67+ console . log ( 'event ' , event ) ;
7368 if ( currentStore . appState !== event . appState ) {
7469 store . dispatch ( allCooperativeState ( event . appState ) ) ;
7570 } else if (
@@ -110,6 +105,7 @@ const RoomsContainer = () => {
110105 ) ;
111106 previousState = newState ;
112107 }
108+
113109 } , 100 ) ;
114110
115111 store . subscribe ( ( ) => {
0 commit comments