File tree Expand file tree Collapse file tree 4 files changed +24
-9
lines changed Expand file tree Collapse file tree 4 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import {
28
28
addPassedInProps ,
29
29
deletePassedInProps ,
30
30
deleteElement ,
31
+ resetAllState ,
31
32
updateStylesheet
32
33
} from '../../redux/reducers/slice/appStateSlice' ;
33
34
import {
@@ -132,6 +133,11 @@ const RoomsContainer = () => {
132
133
}
133
134
) ;
134
135
136
+ // dispatch clear canvas action to local state when the host of the room has clear canvas
137
+ socket . on ( 'clear canvas from server' , ( ) => {
138
+ store . dispatch ( resetAllState ( ) ) ;
139
+ } ) ;
140
+
135
141
// dispatch all updates to local state when another user has saved from Bottom Panel
136
142
socket . on ( 'update data from server' , ( updateData : BottomPanelObj ) => {
137
143
// console.log('update data received from server', updateData);
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { resetAllState } from '../../redux/reducers/slice/appStateSlice';
21
21
import { setStyle } from '../../redux/reducers/slice/styleSlice' ;
22
22
import store from '../../redux/store' ;
23
23
import withStyles from '@mui/styles/withStyles' ;
24
+ import { emitEvent } from '../../helperFunctions/socket' ;
24
25
25
26
const { API_BASE_URL } = config ;
26
27
@@ -97,6 +98,8 @@ function navbarDropDown(props) {
97
98
// state: store.appState
98
99
// }));
99
100
const state = useSelector ( ( store : RootState ) => store . appState ) ;
101
+ const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
102
+ const userName = useSelector ( ( store : RootState ) => store . roomSlice . userName ) ;
100
103
101
104
const closeModal = ( ) => setModal ( '' ) ;
102
105
const handleClick = ( event ) => {
@@ -106,7 +109,8 @@ function navbarDropDown(props) {
106
109
const clearWorkspace = ( ) => {
107
110
// Reset state for project to initial state
108
111
const resetState = ( ) => {
109
- dispatch ( resetAllState ( ) ) ;
112
+ if ( roomCode ) emitEvent ( 'clearCanvasAction' , roomCode , userName ) ;
113
+ else dispatch ( resetAllState ( ) ) ;
110
114
} ;
111
115
// Set modal options
112
116
const children = (
@@ -129,6 +133,7 @@ function navbarDropDown(props) {
129
133
</ ListItem >
130
134
</ List >
131
135
) ;
136
+
132
137
// Create modal
133
138
setModal (
134
139
createModal ( {
Original file line number Diff line number Diff line change @@ -3,14 +3,6 @@ import { configureStore } from '@reduxjs/toolkit';
3
3
// Import of combined reducers in rootReducer
4
4
import rootReducer from './reducers/rootReducer' ;
5
5
6
- /*
7
- // Define the root state type based on the rootReducer
8
- export type RootState = ReturnType<typeof rootReducer>;
9
-
10
- // Define the type of the Redux store
11
- export type AppStore = Store<RootState>;
12
- */
13
-
14
6
const store = configureStore ( {
15
7
reducer : rootReducer ,
16
8
middleware : ( getDefaultMiddleware ) => {
Original file line number Diff line number Diff line change @@ -191,6 +191,18 @@ io.on('connection', (client) => {
191
191
}
192
192
} ) ;
193
193
194
+ client . on ( 'clearCanvasAction' , async ( roomCode : string , userName : string ) => {
195
+ if ( roomCode ) {
196
+ // server send clear canvas to everyone in the room if action is from the host
197
+ if ( userName === Object . values ( roomLists [ roomCode ] ) [ 0 ] ) {
198
+ io . to ( roomCode ) . emit (
199
+ 'clear canvas from server' ,
200
+ Object . values ( roomLists [ roomCode ] )
201
+ ) ;
202
+ }
203
+ }
204
+ } ) ;
205
+
194
206
client . on (
195
207
'deleteElementAction' ,
196
208
( roomCode : string , deleteElementData : object ) => {
You can’t perform that action at this time.
0 commit comments