@@ -38,6 +38,7 @@ const RoomsContainer = () => {
38
38
userJoined : store . roomSlice . userJoined
39
39
} )
40
40
) ;
41
+
41
42
React . useEffect ( ( ) => {
42
43
console . log ( 'You Joined Room---:' , roomCode ) ;
43
44
} , [ roomCode ] ) ;
@@ -72,15 +73,22 @@ const RoomsContainer = () => {
72
73
if ( currentStore !== event ) {
73
74
currentStore = JSON . parse ( currentStore ) ;
74
75
event = JSON . parse ( event ) ;
75
- if ( currentStore . appState !== event . appState ) {
76
+ if (
77
+ JSON . stringify ( currentStore . appState ) !==
78
+ JSON . stringify ( event . appState )
79
+ ) {
76
80
console . log ( 'updating app state' ) ;
77
81
store . dispatch ( allCooperativeState ( event . appState ) ) ;
78
82
} else if (
79
- currentStore . codePreviewSlice !== event . codePreviewCooperative
83
+ JSON . stringify ( currentStore . codePreviewSlice ) !==
84
+ JSON . stringify ( event . codePreviewCooperative )
80
85
) {
81
86
console . log ( 'updating code preview' ) ;
82
87
store . dispatch ( codePreviewCooperative ( event . codePreviewCooperative ) ) ;
83
- } else if ( currentStore . styleSlice !== event . styleSlice ) {
88
+ } else if (
89
+ JSON . stringify ( currentStore . styleSlice ) !==
90
+ JSON . stringify ( event . styleSlice )
91
+ ) {
84
92
console . log ( 'updating style' ) ;
85
93
store . dispatch ( cooperativeStyle ( event . styleSlice ) ) ;
86
94
}
@@ -98,23 +106,23 @@ const RoomsContainer = () => {
98
106
const newState = store . getState ( ) ;
99
107
const roomCode = newState . roomSlice . roomCode ;
100
108
101
- if ( newState !== previousState ) {
109
+ if ( JSON . stringify ( newState ) !== JSON . stringify ( previousState ) ) {
102
110
// Send the current state to the server
103
111
console . log ( 'front emitting new state' ) ;
104
112
socket . emit ( 'new state from front' , JSON . stringify ( newState ) , roomCode ) ;
105
113
previousState = newState ;
106
114
}
107
- } , 10000 ) ;
115
+ } , 100 ) ;
108
116
109
117
store . subscribe ( ( ) => {
110
118
if ( socket ) {
111
- console . log ( 'handling store change' ) ;
119
+ // console.log('handling store change');
112
120
handleStoreChange ( ) ;
113
121
}
114
122
} ) ;
115
123
116
124
function joinRoom ( ) {
117
- if ( userList . length !== 0 ) setUserList ( [ ] ) ; //edge case check if userList not empty.
125
+ if ( userList . length !== 0 ) dispatch ( setUserList ( [ ] ) ) ; //edge case check if userList not empty.
118
126
handleUserEnteredRoom ( roomCode ) ; // Call handleUserEnteredRoom when joining a room
119
127
dispatch ( setRoomCode ( roomCode ) ) ;
120
128
dispatch ( setUserJoined ( true ) ) ; //setting joined room to true for rendering leave room button
@@ -131,12 +139,11 @@ const RoomsContainer = () => {
131
139
}
132
140
133
141
//checking if both text field have any input (not including spaces)
134
- function checkInputField ( ...inputs : any ) {
142
+ function checkInputField ( ...inputs ) {
135
143
let userName : string = inputs [ 0 ] . trim ( ) ;
136
144
let roomCode : string = inputs [ 1 ] . trim ( ) ;
137
145
return userName . length === 0 || roomCode . length === 0 ;
138
146
}
139
-
140
147
return (
141
148
< div >
142
149
< Stack //stack styling for container
0 commit comments