@@ -35,88 +35,88 @@ import withStyles from '@mui/styles/withStyles';
35
35
const { API_BASE_URL } = config ;
36
36
37
37
// Part - join room and room code functionality
38
- let socket ;
39
-
40
- function initSocketConnection ( roomCode ) {
41
- if ( socket ) {
42
- socket . disconnect ( ) ;
43
- }
44
-
45
- socket = io ( API_BASE_URL , {
46
- transports : [ 'websocket' ]
47
- } ) ;
48
-
49
- socket . on ( 'connect' , ( ) => {
50
- console . log ( `You connected with id: ${ socket . id } ` ) ;
51
- socket . emit ( 'join-room' , roomCode ) ; // Join the room when connected
52
- } ) ;
53
-
54
- // Receiving the room state from the backend
55
- socket . on ( 'room-state-update' , ( stateFromServer ) => {
56
- const newState = JSON . parse ( stateFromServer ) ;
57
- // Dispatch actions to update your Redux store with the received state
58
- store . dispatch ( allCooperativeState ( newState . appState ) ) ;
59
- store . dispatch ( codePreviewCooperative ( newState . codePreviewCooperative ) ) ;
60
- store . dispatch ( cooperativeStyle ( newState . styleSlice ) ) ;
61
- } ) ;
62
-
63
- // receiving the message from the back end
64
- socket . on ( 'receive message' , ( event ) => {
65
- // console.log('message from server: ', event);
66
- let currentStore : any = JSON . stringify ( store . getState ( ) ) ;
67
- if ( currentStore !== event ) {
68
- currentStore = JSON . parse ( currentStore ) ;
69
- event = JSON . parse ( event ) ;
70
- if ( currentStore . darkMode . isDarkMode !== event . darkMode . isDarkMode ) {
71
- store . dispatch ( toggleDarkMode ( ) ) ;
72
- } else if ( currentStore . appState !== event . appState ) {
73
- store . dispatch ( allCooperativeState ( event . appState ) ) ;
74
- } else if (
75
- currentStore . codePreviewSlice !== event . codePreviewCooperative
76
- ) {
77
- store . dispatch ( codePreviewCooperative ( event . codePreviewCooperative ) ) ;
78
- } else if ( currentStore . styleSlice !== event . styleSlice ) {
79
- store . dispatch ( cooperativeStyle ( event . styleSlice ) ) ;
80
- }
81
- }
82
- console . log ( 'updated user Store from another user: ' , store . getState ( ) ) ;
83
- } ) ;
84
- }
85
-
86
- function handleUserEnteredRoom ( roomCode ) {
87
- initSocketConnection ( roomCode ) ;
88
- }
38
+ // let socket;
39
+
40
+ // function initSocketConnection(roomCode) {
41
+ // if (socket) {
42
+ // socket.disconnect();
43
+ // }
44
+
45
+ // socket = io(API_BASE_URL, {
46
+ // transports: ['websocket']
47
+ // });
48
+
49
+ // socket.on('connect', () => {
50
+ // console.log(`You connected with id: ${socket.id}`);
51
+ // socket.emit('join-room', roomCode); // Join the room when connected
52
+ // });
53
+
54
+ // // Receiving the room state from the backend
55
+ // socket.on('room-state-update', (stateFromServer) => {
56
+ // const newState = JSON.parse(stateFromServer);
57
+ // // Dispatch actions to update your Redux store with the received state
58
+ // store.dispatch(allCooperativeState(newState.appState));
59
+ // store.dispatch(codePreviewCooperative(newState.codePreviewCooperative));
60
+ // store.dispatch(cooperativeStyle(newState.styleSlice));
61
+ // });
62
+
63
+ // // receiving the message from the back end
64
+ // socket.on('receive message', (event) => {
65
+ // // console.log('message from server: ', event);
66
+ // let currentStore: any = JSON.stringify(store.getState());
67
+ // if (currentStore !== event) {
68
+ // currentStore = JSON.parse(currentStore);
69
+ // event = JSON.parse(event);
70
+ // if (currentStore.darkMode.isDarkMode !== event.darkMode.isDarkMode) {
71
+ // store.dispatch(toggleDarkMode());
72
+ // } else if (currentStore.appState !== event.appState) {
73
+ // store.dispatch(allCooperativeState(event.appState));
74
+ // } else if (
75
+ // currentStore.codePreviewSlice !== event.codePreviewCooperative
76
+ // ) {
77
+ // store.dispatch(codePreviewCooperative(event.codePreviewCooperative));
78
+ // } else if (currentStore.styleSlice !== event.styleSlice) {
79
+ // store.dispatch(cooperativeStyle(event.styleSlice));
80
+ // }
81
+ // }
82
+ // console.log('updated user Store from another user: ', store.getState());
83
+ // });
84
+ // }
85
+
86
+ // function handleUserEnteredRoom(roomCode) {
87
+ // initSocketConnection(roomCode);
88
+ // }
89
89
90
90
// console.log(store.getState());
91
- let previousState = store . getState ( ) ;
92
-
93
- // sending info to backend whenever the redux store changes
94
- const handleStoreChange = debounce ( ( ) => {
95
- const newState = store . getState ( ) ;
96
- const roomCode = newState . roomCodeSlice . roomCode ;
97
-
98
- if ( roomCode !== '' ) {
99
- // Emit the current room code
100
- socket . emit ( 'room-code' , roomCode ) ;
101
- }
102
-
103
- if ( newState !== previousState ) {
104
- // Send the current state to the server
105
- socket . emit (
106
- 'custom-event' ,
107
- 'sent from front-end' ,
108
- JSON . stringify ( newState ) ,
109
- roomCode
110
- ) ;
111
- previousState = newState ;
112
- }
113
- } , 100 ) ;
114
-
115
- store . subscribe ( ( ) => {
116
- if ( socket ) {
117
- handleStoreChange ( ) ;
118
- }
119
- } ) ;
91
+ // let previousState = store.getState();
92
+
93
+ // // sending info to backend whenever the redux store changes
94
+ // const handleStoreChange = debounce(() => {
95
+ // const newState = store.getState();
96
+ // const roomCode = newState.roomCodeSlice.roomCode;
97
+
98
+ // if (roomCode !== '') {
99
+ // // Emit the current room code
100
+ // socket.emit('room-code', roomCode);
101
+ // }
102
+
103
+ // if (newState !== previousState) {
104
+ // // Send the current state to the server
105
+ // socket.emit(
106
+ // 'custom-event',
107
+ // 'sent from front-end',
108
+ // JSON.stringify(newState),
109
+ // roomCode
110
+ // );
111
+ // previousState = newState;
112
+ // }
113
+ // }, 100);
114
+
115
+ // store.subscribe(() => {
116
+ // if (socket) {
117
+ // handleStoreChange();
118
+ // }
119
+ // });
120
120
121
121
const useStyles = makeStyles ( ( theme ) =>
122
122
createStyles ( {
@@ -254,17 +254,17 @@ function navbarDropDown(props) {
254
254
props . setDropMenu ( false ) ;
255
255
} ;
256
256
257
- React . useEffect ( ( ) => {
258
- console . log ( 'joinedRoom: ' , joinedRoom ) ;
259
- } , [ joinedRoom ] ) ;
257
+ // React.useEffect(() => {
258
+ // console.log('joinedRoom: ', joinedRoom);
259
+ // }, [joinedRoom]);
260
260
261
- function joinRoom ( ) {
262
- dispatch ( changeRoom ( roomCode ) ) ;
263
- setConfirmRoom ( ( confirmRoom ) => roomCode ) ;
261
+ // function joinRoom() {
262
+ // dispatch(changeRoom(roomCode));
263
+ // setConfirmRoom((confirmRoom) => roomCode);
264
264
265
- // Call handleUserEnteredRoom when joining a room
266
- handleUserEnteredRoom ( roomCode ) ;
267
- }
265
+ // // Call handleUserEnteredRoom when joining a room
266
+ // handleUserEnteredRoom(roomCode);
267
+ // }
268
268
// Part - Dark Mode
269
269
const switchDark = isDarkMode ? (
270
270
< svg
@@ -298,16 +298,19 @@ function navbarDropDown(props) {
298
298
299
299
useEffect ( ( ) => {
300
300
const handleClick = ( event ) => {
301
- if ( event . type === "click" &&
302
- ( dropdownRef . current &&
303
- ! dropdownRef . current . contains ( event . target ) && ! props . menuButtonRef . current . contains ( event . target ) ) || event . type === "message" && event . data === 'iframeClicked'
301
+ if (
302
+ ( event . type === 'click' &&
303
+ dropdownRef . current &&
304
+ ! dropdownRef . current . contains ( event . target ) &&
305
+ ! props . menuButtonRef . current . contains ( event . target ) ) ||
306
+ ( event . type === 'message' && event . data === 'iframeClicked' )
304
307
) {
305
308
//menuButtonRef is to ensure that handleClose does not get invoked when the user clicks on the menu dropdown button
306
309
handleClose ( ) ;
307
310
}
308
311
} ;
309
312
window . addEventListener ( 'click' , handleClick , true ) ;
310
- window . addEventListener ( 'message' , handleClick ) ; //to capture clicks in the iframe
313
+ window . addEventListener ( 'message' , handleClick ) ; //to capture clicks in the iframe
311
314
312
315
return ( ) => {
313
316
window . removeEventListener ( 'click' , handleClick , true ) ;
@@ -360,7 +363,7 @@ function navbarDropDown(props) {
360
363
</ svg >
361
364
</ button >
362
365
{ /* {<ExportButton />} */ }
363
- { /*
366
+ { /*
364
367
<button onClick={handleDarkModeToggle}>
365
368
{isDarkMode ? 'Light' : 'Dark'} Mode {switchDark}
366
369
</button> */ }
@@ -390,8 +393,11 @@ function navbarDropDown(props) {
390
393
className = "bi bi-bag-check"
391
394
viewBox = "0 0 16 16"
392
395
>
393
- < path fillRule = "evenodd" d = "M10.854 8.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 0 1 .708-.708L7.5 10.793l2.646-2.647a.5.5 0 0 1 .708 0z" />
394
- < path d = "M8 1a2.5 2.5 0 0 1 2.5 2.5V4h-5v-.5A2.5 2.5 0 0 1 8 1zm3.5 3v-.5a3.5 3.5 0 1 0-7 0V4H1v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-3.5zM2 5h12v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5z" />
396
+ < path
397
+ fillRule = "evenodd"
398
+ d = "M10.854 8.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 0 1 .708-.708L7.5 10.793l2.646-2.647a.5.5 0 0 1 .708 0z"
399
+ />
400
+ < path d = "M8 1a2.5 2.5 0 0 1 2.5 2.5V4h-5v-.5A2.5 2.5 0 0 1 8 1zm3.5 3v-.5a3.5 3.5 0 1 0-7 0V4H1v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-3.5zM2 5h12v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5z" />
395
401
</ svg >
396
402
</ button >
397
403
</ Link >
@@ -411,7 +417,7 @@ function navbarDropDown(props) {
411
417
< SaveProjectButton />
412
418
</ StyledMenuItem >
413
419
< StyledMenuItem className = { classes . manageProject } onClick = { handleClose } >
414
- < ProjectsFolder openAlert = { props . openAlert } />
420
+ < ProjectsFolder openAlert = { props . openAlert } />
415
421
</ StyledMenuItem >
416
422
< StyledMenuItem className = { classes . manageProject } onClick = { handleClose } >
417
423
< DeleteProjects deleteAlert = { props . deleteAlert } />
0 commit comments