Skip to content

Commit 4ec06ce

Browse files
authored
Merge pull request #20 from oslabs-beta/laura
Laura
2 parents 3714b08 + 347ee63 commit 4ec06ce

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

app/src/components/left/HTMLItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ const HTMLItem: React.FC<{
129129
className={`${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`}
130130
id="HTMLItem"
131131
>
132-
{/* <Icon fontSize="small" align-items="center" /> */}
133132
{typeof IconComponent !== 'undefined' && (
134133
<IconComponent fontSize="small" align-items="center" />
135134
)}
@@ -146,7 +145,7 @@ const HTMLItem: React.FC<{
146145
className={`${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`}
147146
id="HTMLItem"
148147
>
149-
<h3>{name}</h3>
148+
<div>{name}</div>
150149
</div>
151150
<button
152151
id="newElement"

app/src/components/left/RoomsContainer.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import Button from '@mui/material/Button';
88
import React, { useState } from 'react';
99
import { RootState } from '../../redux/store';
1010
import TextField from '@mui/material/TextField';
11+
import { BottomPanelObj } from '../../interfaces/Interfaces';
1112
import {
1213
allCooperativeState,
1314
addChild,
1415
changeFocus,
1516
deleteChild,
1617
changePosition,
17-
resetState
18+
resetState,
19+
updateStateUsed,
20+
updateUseContext,
21+
updateCss,
22+
updateAttributes,
23+
updateEvents
1824
} from '../../redux/reducers/slice/appStateSlice';
1925
import {
2026
setRoomCode,
@@ -115,6 +121,16 @@ const RoomsContainer = () => {
115121
store.dispatch(deleteChild(deleteData));
116122
});
117123

124+
//write out emitters for reach function inside of CusomizationPanel HandleSave//no need to pull the function into RoomsContainer
125+
socket.on('update data from server', (updateData: BottomPanelObj) => {
126+
console.log('update data received from server', updateData);
127+
store.dispatch(updateStateUsed({stateUsedObj: updateData.stateUsedObj, contextParam: updateData.contextParam}));
128+
store.dispatch(updateUseContext({useContextObj: updateData.useContextObj, contextParam: updateData.contextParam}));
129+
store.dispatch(updateCss({style: updateData.style, contextParam: updateData.contextParam}));
130+
store.dispatch(updateAttributes({attributes: updateData.attributes, contextParam: updateData.contextParam}));
131+
store.dispatch(updateEvents({events: updateData.events, contextParam: updateData.contextParam}));
132+
});
133+
118134
socket.on(
119135
'item position data from server',
120136
(itemPositionData: object) => {

app/src/containers/CustomizationPanel.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import createModal from '../components/right/createModal';
3838
import makeStyles from '@mui/styles/makeStyles';
3939
import { ColumnTab } from '../interfaces/Interfaces';
4040
import { RootState } from '../redux/store';
41+
import { emitEvent } from '../helperFunctions/socket';
42+
import { Number } from 'mongoose';
4143

4244
// Previously named rightContainer, Renamed to Customizationpanel this now hangs on BottomTabs
4345
// need to pass in props to use the useHistory feature of react router
@@ -46,6 +48,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
4648
const dispatch = useDispatch();
4749
const state = useSelector((store: RootState) => store.appState);
4850
const contextParam = useSelector((store: RootState) => store.contextSlice);
51+
const roomCode = useSelector((store: RootState) => store.roomSlice.roomCode);
4952
const style = useSelector((store: RootState) => store.styleSlice);
5053

5154
const [displayMode, setDisplayMode] = useState('');
@@ -370,25 +373,42 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
370373
if (compText !== '') attributesObj.compText = compText;
371374
if (compLink !== '') attributesObj.compLink = compLink;
372375
if (cssClasses !== '') attributesObj.cssClasses = cssClasses;
373-
374376
dispatch(
375377
updateAttributes({
376378
attributes: attributesObj,
377379
contextParam: contextParam
378380
})
379381
);
380-
382+
381383
const eventsObj: any = {};
382384
if (eventAll[0] !== '') eventsObj[eventAll[0]] = eventAll[1];
383385
dispatch(updateEvents({ events: eventsObj, contextParam: contextParam }));
384386

387+
if (roomCode) {
388+
emitEvent('updateChildAction', roomCode, {
389+
stateUsedObj: stateUsedObj,
390+
contextParam: contextParam,
391+
useContextObj: useContextObj,
392+
attributes: attributesObj,
393+
style: styleObj,
394+
events: eventsObj
395+
});
396+
console.log('emit updateChildAction event is triggered in CustomizationPanel.tsx');
397+
}
398+
385399
return styleObj;
400+
386401
};
387402
const handleTailwind = (): void => {
388403
dispatch(changeTailwind(true));
389404
handleSave();
390405
};
391406

407+
// const clickToUpdate = () => {
408+
// handleSave();
409+
// saveEmitter();
410+
// }
411+
392412
// UNDO/REDO functionality--onClick these functions will be invoked.
393413
const handleUndo = () => {
394414
dispatch(undo({ contextParam }));
@@ -399,7 +419,15 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
399419
// placeholder for handling deleting instance
400420
const handleDelete = () => {
401421
dispatch(deleteChild({ id: {}, contextParam: contextParam }));
422+
if (roomCode) {
423+
emitEvent('deleteChildAction', roomCode, {
424+
id: {},
425+
contextParam: contextParam
426+
});
427+
console.log('emit deleteChildAction event is triggered in CustomizationPanel.tsx');
428+
}
402429
};
430+
403431
const handlePageDelete = (id) => () => {
404432
// TODO: return modal
405433
if (isLinkedTo()) return setDeleteLinkedPageError(true);

app/src/interfaces/Interfaces.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,12 @@ export interface MouseState {
191191
clientX: number;
192192
clientY: number;
193193
}
194+
195+
export interface BottomPanelObj {
196+
stateUsedObj: object;
197+
contextParam: object;
198+
useContextObj: object;
199+
attributes: object;
200+
style: object;
201+
events: object;
202+
}

server/server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ io.on('connection', (client) => {
205205
client.to(roomCode).emit('delete data from server', deleteData);
206206
});
207207

208+
client.on('updateChildAction', (roomCode: string, updateData: object) => {
209+
client.to(roomCode).emit('update data from server', updateData);
210+
console.log('client received update from server!')
211+
});
212+
208213
client.on(
209214
'changePositionAction',
210215
(roomCode: string, itemPositionData: object) => {

0 commit comments

Comments
 (0)