Skip to content

Commit 126f805

Browse files
committed
add websocket emitters for functionality in bottom panel: State Manager & ComponentPanelItem
1 parent c6a1d3b commit 126f805

File tree

7 files changed

+134
-2
lines changed

7 files changed

+134
-2
lines changed

app/src/components/StateManagement/CreateTab/components/StatePropsPanel.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import TableStateProps from './TableStateProps';
1616
import TableParentProps from './TableParentProps';
1717
import TablePassedInProps from './TablePassedInProps';
1818
import { RootState } from '../../../../redux/store';
19+
import { emitEvent } from '../../../../helperFunctions/socket';
1920

2021
const StatePropsPanel = ({ isThemeLight, data }): JSX.Element => {
2122
const state = useSelector((store: RootState) => store.appState);
2223
const contextParam = useSelector((store: RootState) => store.contextSlice);
24+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
2325

2426
const dispatch = useDispatch();
2527
const classes = useStyles();
@@ -159,6 +161,15 @@ const StatePropsPanel = ({ isThemeLight, data }): JSX.Element => {
159161
contextParam: contextParam
160162
})
161163
);
164+
165+
if (roomCode) {
166+
emitEvent('addStateAction', roomCode, {
167+
newState: newState,
168+
setNewState: setNewState,
169+
contextParam: contextParam
170+
});
171+
}
172+
162173
setRows1([...rows1, newState]);
163174
setErrorStatus(false);
164175
clearForm();

app/src/components/StateManagement/CreateTab/components/TableParentProps.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import makeStyles from '@mui/styles/makeStyles';
66
import AddIcon from '@mui/icons-material/Add';
77
import { addPassedInProps } from '../../../../redux/reducers/slice/appStateSlice';
88
import { RootState } from '../../../../redux/store';
9+
import { emitEvent } from '../../../../helperFunctions/socket';
910

1011
const TableParentProps = (props) => {
1112
const state = useSelector((store: RootState) => store.appState);
1213
const contextParam = useSelector((store: RootState) => store.contextSlice);
14+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
1315

1416
const dispatch = useDispatch();
1517
const classes = useStyles();
@@ -76,6 +78,15 @@ const TableParentProps = (props) => {
7678
contextParam: contextParam
7779
})
7880
);
81+
82+
if (roomCode) {
83+
emitEvent('addPassedInPropsAction', roomCode, {
84+
passedInProps: parentComponentProps,
85+
rowId: rowId,
86+
parentComponent: parentComponent,
87+
contextParam: contextParam
88+
});
89+
}
7990
};
8091

8192
useEffect(() => {

app/src/components/StateManagement/CreateTab/components/TablePassedInProps.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { useDispatch, useSelector } from 'react-redux';
77
import { deletePassedInProps } from '../../../../redux/reducers/slice/appStateSlice';
88
import { RootState } from '../../../../redux/store';
99
import { ColumnTab } from '../../../../interfaces/Interfaces';
10+
import { emitEvent } from '../../../../helperFunctions/socket';
1011

1112
const TablePassedInProps = (props) => {
1213
const state = useSelector((store: RootState) => store.appState);
1314
const contextParam = useSelector((store: RootState) => store.contextSlice);
15+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
1416

1517
const dispatch = useDispatch();
1618
const classes = useStyles();
@@ -75,6 +77,13 @@ const TablePassedInProps = (props) => {
7577
// remove the state that the button is clicked
7678
// send a dispatch to rerender the table
7779
dispatch(deletePassedInProps({ rowId: rowId, contextParam: contextParam }));
80+
81+
if (roomCode) {
82+
emitEvent('deletePassedInPropsAction', roomCode, {
83+
rowId: rowId,
84+
contextParam: contextParam
85+
});
86+
}
7887
};
7988

8089
useEffect(() => {

app/src/components/StateManagement/CreateTab/components/TableStateProps.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import { useDispatch, useSelector } from 'react-redux';
88
import { deleteState } from '../../../../redux/reducers/slice/appStateSlice';
99
import { RootState } from '../../../../redux/store';
1010
import { ColumnTab } from '../../../../interfaces/Interfaces';
11+
import { emitEvent } from '../../../../helperFunctions/socket';
12+
1113
// updates state mgmt boxes and data grid
1214
const TableStateProps = (props) => {
1315
const state = useSelector((store: RootState) => store.appState);
1416
const contextParam = useSelector((store: RootState) => store.contextSlice);
17+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
1518

1619
const dispatch = useDispatch();
1720
const classes = useStyles();
@@ -84,6 +87,14 @@ const TableStateProps = (props) => {
8487
contextParam: contextParam
8588
})
8689
);
90+
91+
if (roomCode) {
92+
emitEvent('deleteStateAction', roomCode, {
93+
stateProps: filtered,
94+
rowId: selectedId,
95+
contextParam: contextParam
96+
});
97+
}
8798
};
8899

89100
useEffect(() => {

app/src/components/left/RoomsContainer.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import {
2222
updateAttributes,
2323
updateEvents,
2424
addComponent,
25-
addElement
25+
addElement,
26+
addState,
27+
deleteState,
28+
addPassedInProps,
29+
deletePassedInProps
2630
} from '../../redux/reducers/slice/appStateSlice';
2731
import {
2832
setRoomCode,
@@ -176,6 +180,36 @@ const RoomsContainer = () => {
176180
socket.on('new element data from server', (newElement: object) => {
177181
store.dispatch(addElement(newElement));
178182
});
183+
184+
socket.on(
185+
'new component state data from server',
186+
(componentState: object) => {
187+
store.dispatch(addState(componentState));
188+
}
189+
);
190+
191+
socket.on(
192+
'delete component state data from server',
193+
(componentStateDelete: object) => {
194+
store.dispatch(deleteState(componentStateDelete));
195+
}
196+
);
197+
198+
socket.on(
199+
'new PassedInProps data from server',
200+
(passedInProps: object) => {
201+
store.dispatch(addPassedInProps(passedInProps));
202+
}
203+
);
204+
205+
socket.on(
206+
'new PassedInProps delete data from server',
207+
(passedInProps: object) => {
208+
store.dispatch(deletePassedInProps(passedInProps));
209+
}
210+
);
211+
212+
//
179213
}
180214
}
181215

app/src/components/right/ComponentPanelItem.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ItemTypes } from '../../constants/ItemTypes';
66
import { useDispatch, useSelector } from 'react-redux';
77
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
88
import { RootState } from '../../redux/store';
9+
import { emitEvent } from '../../helperFunctions/socket';
910
/*
1011
DESCRIPTION: This component is each box beneath the 'HTML Elements' and
1112
'reusable components' (in classic React mode) headings. Drag-and-drop
@@ -24,6 +25,7 @@ const ComponentPanelItem: React.FC<{
2425
}> = ({ name, id, root, isFocus, isThemeLight }) => {
2526
const classes = useStyles();
2627
const state = useSelector((store: RootState) => store.appState);
28+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
2729
const dispatch = useDispatch();
2830

2931
// useDrag hook allows components in left panel to be drag source
@@ -44,6 +46,13 @@ const ComponentPanelItem: React.FC<{
4446
const handleClick = () => {
4547
//LEGACY PD
4648
dispatch(changeFocus({ componentId: id, childId: null }));
49+
50+
if (roomCode) {
51+
emitEvent('changeFocusAction', roomCode, {
52+
componentId: id,
53+
childId: null
54+
});
55+
}
4756
};
4857

4958
return (
@@ -73,7 +82,7 @@ const ComponentPanelItem: React.FC<{
7382

7483
const useStyles = makeStyles({
7584
activeFocus: {
76-
backgroundColor: 'rgba (0, 0, 0, 0.54)', //this doesnt do anything....
85+
backgroundColor: 'rgba (0, 0, 0, 0.54)' //this doesnt do anything....
7786
},
7887
focusMark: {
7988
backgroundColor: '#29A38A',

server/server.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,53 @@ io.on('connection', (client) => {
223223
}
224224
});
225225

226+
client.on('addStateAction', (roomCode: string, componentState: object) => {
227+
if (roomCode) {
228+
client
229+
.to(roomCode)
230+
.emit('new component state data from server', componentState);
231+
}
232+
});
233+
234+
client.on(
235+
'deleteStateAction',
236+
(roomCode: string, componentStateDelete: object) => {
237+
if (roomCode) {
238+
client
239+
.to(roomCode)
240+
.emit(
241+
'delete component state data from server',
242+
componentStateDelete
243+
);
244+
}
245+
}
246+
);
247+
248+
client.on(
249+
'addPassedInPropsAction',
250+
(roomCode: string, passedInProps: object) => {
251+
if (roomCode) {
252+
client
253+
.to(roomCode)
254+
.emit('new PassedInProps data from server', passedInProps);
255+
}
256+
}
257+
);
258+
259+
client.on(
260+
'deletePassedInPropsAction',
261+
(roomCode: string, passedInPropsDelete: object) => {
262+
if (roomCode) {
263+
client
264+
.to(roomCode)
265+
.emit(
266+
'new PassedInProps delete data from server',
267+
passedInPropsDelete
268+
);
269+
}
270+
}
271+
);
272+
226273
//remote cursor
227274
client.on('cursorData', (roomCode: string, remoteData: object) => {
228275
client.to(roomCode).emit('remote cursor data from server', remoteData);

0 commit comments

Comments
 (0)