Skip to content

Commit 7841f27

Browse files
committed
added comments
1 parent 929d529 commit 7841f27

File tree

8 files changed

+48
-29
lines changed

8 files changed

+48
-29
lines changed

app/src/components/left/DragDropPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const DragDropPanel = (props): JSX.Element => {
9494
})}
9595
</Grid>
9696

97+
{/* Next.js */}
9798
{state.projectType === 'Next.js' ? (
9899
<h3 style={{ color: 'C6C6C6' }}>Next.js</h3>
99100
) : null}

app/src/components/left/HTMLItem.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ const HTMLItem: React.FC<{
4141
id: number;
4242
Icon: any;
4343
handleDelete: (id: number) => void;
44-
}> = ({ name, id, handleDelete }) => {
44+
}> = ({ name, id, Icon, handleDelete }) => {
4545
const classes = useStyles();
4646
const [modal, setModal] = useState(null);
47+
4748
const [{ isDragging }, drag] = useDrag({
4849
// is dragging is never read, but if deleted adjustment in the ref are needed line 122/128 ref={drag} to {...drag}
4950
item: {
@@ -120,16 +121,21 @@ const HTMLItem: React.FC<{
120121
return (
121122
// HTML Elements
122123
<Grid item xs={5} key={`html-g${name}`}>
124+
{/* predefined elements */}
123125
{id <= 20 && (
124126
<div
125127
ref={drag}
126128
style={{ borderColor: '#C6C6C6' }}
127129
className={`${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`}
128130
id="HTMLItem"
129131
>
132+
{/* render element's name on canvas */}
133+
{Icon}
130134
<h3>{name}</h3>
131135
</div>
132136
)}
137+
138+
{/* Custom Elements */}
133139
{id > 20 && (
134140
<span id="customHTMLElement">
135141
<div

app/src/components/left/RoomsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const RoomsContainer = () => {
6464
store.dispatch(allCooperativeState(state.appState));
6565
store.dispatch(codePreviewCooperative(state.codePreviewCooperative));
6666
store.dispatch(cooperativeStyle(state.styleSlice));
67-
callback({ status: 'confirmed' });
67+
callback({ status: 'confirmed' });
6868
});
6969

7070
// update user list when there's a change: new join or leave the room

app/src/components/main/Canvas.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ function Canvas(props: {}): JSX.Element {
1919
const state = useSelector((store: RootState) => store.appState);
2020
const contextParam = useSelector((store: RootState) => store.contextSlice);
2121

22-
const dispatch = useDispatch();
23-
24-
Arrow.deleteLines();
25-
2622
// find the current component based on the canvasFocus component ID in the state
2723
const currentComponent: Component = state.components.find(
2824
(elem: Component) => elem.id === state.canvasFocus.componentId
2925
);
3026

27+
Arrow.deleteLines();
28+
29+
const dispatch = useDispatch();
3130
// changes focus of the canvas to a new component / child
3231
const changeFocusFunction = (
3332
componentId?: number,

app/src/components/main/DirectChildComponent.tsx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ import { useDispatch, useSelector } from 'react-redux';
99
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
1010
import { RootState } from '../../redux/store';
1111

12-
function DirectChildComponent({
13-
childId,
14-
type,
15-
typeId,
16-
name
17-
}: ChildElement) {
18-
const state = useSelector((store:RootState) => store.appState);
12+
function DirectChildComponent({ childId, type, typeId, name }: ChildElement) {
13+
const state = useSelector((store: RootState) => store.appState);
1914
const dispatch = useDispatch();
2015

2116
// find the top-level component corresponding to this instance of the component
@@ -38,7 +33,7 @@ function DirectChildComponent({
3833
})
3934
});
4035
const changeFocusFunction = (componentId: number, childId: number | null) => {
41-
dispatch(changeFocus({ componentId, childId}));
36+
dispatch(changeFocus({ componentId, childId }));
4237
};
4338

4439
// onClickHandler is responsible for changing the focused component and child component
@@ -63,17 +58,13 @@ function DirectChildComponent({
6358
);
6459
// Renders name and not children of subcomponents to clean up Canvas view when dragging components
6560
// into the main canvas. To render html elements on canvas, import and invoke renderChildren
66-
return (
67-
<div
68-
onClick={onClickHandler}
69-
style={combinedStyle}
70-
ref={drag}
71-
>
72-
<span>
73-
<strong style={{ color: 'white' }}>{name}</strong>
74-
<DeleteButton id={childId} name={name} />
75-
</span>
76-
61+
return (
62+
<div onClick={onClickHandler} style={combinedStyle} ref={drag}>
63+
<span>
64+
{/* render name and delete button X */}
65+
<strong style={{ color: 'white' }}>{name}</strong>
66+
<DeleteButton id={childId} name={name} />
67+
</span>
7768
</div>
7869
);
7970
}

app/src/components/right/ComponentPanelItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useDispatch, useSelector } from 'react-redux';
77
import { changeFocus } from '../../redux/reducers/slice/appStateSlice';
88
import { RootState } from '../../redux/store';
99
/*
10-
DESCRIPTION: This component is each box beneath the 'root components' and
10+
DESCRIPTION: This component is each box beneath the 'HTML Elements' and
1111
'reusable components' (in classic React mode) headings. Drag-and-drop
1212
functionality works only for reusable components.
1313
@@ -25,6 +25,7 @@ const ComponentPanelItem: React.FC<{
2525
const classes = useStyles();
2626
const state = useSelector((store: RootState) => store.appState);
2727
const dispatch = useDispatch();
28+
2829
// useDrag hook allows components in left panel to be drag source
2930
const [{ isDragging }, drag] = useDrag({
3031
item: {
@@ -44,6 +45,7 @@ const ComponentPanelItem: React.FC<{
4445
//LEGACY PD
4546
dispatch(changeFocus({ componentId: id, childId: null }));
4647
};
48+
4749
return (
4850
<Grid
4951
item
@@ -62,11 +64,13 @@ const ComponentPanelItem: React.FC<{
6264
>
6365
{isFocus && <div className={classes.focusMark}></div>}
6466
<div className="compPanelItem" onClick={handleClick}>
67+
{/* render element's name on the left panel*/}
6568
<h3>{name}</h3>
6669
</div>
6770
</Grid>
6871
);
6972
};
73+
7074
const useStyles = makeStyles({
7175
activeFocus: {
7276
backgroundColor: 'rgba(1,212,109,0.3)'

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,21 @@ const appStateSlice = createSlice({
285285
typeId,
286286
childId
287287
}: { type: string; typeId: number; childId: any } = action.payload;
288+
289+
// determine the parent component id
288290
if (action.payload.copyId) {
289291
parentComponentId = action.payload.copyId;
290292
} else {
291293
parentComponentId = state.canvasFocus.componentId;
292294
}
293295

296+
// make a copy of the components from state
294297
const components = [...state.components];
295298

299+
// find the parent component
296300
const parentComponent = findComponent(components, parentComponentId);
301+
302+
// if type is 'Component', loop through components to find componentName and componentChildren
297303
let componentName: string = '';
298304
let componentChildren: ChildElement[] = [];
299305
if (type === 'Component') {
@@ -314,6 +320,7 @@ const appStateSlice = createSlice({
314320
}
315321
}
316322

323+
// create a new name based on the type of element
317324
let newName = state.HTMLTypes.reduce((name, el) => {
318325
if (typeId === el.id) {
319326
name = type === 'Component' ? componentName : el.tag;
@@ -329,6 +336,7 @@ const appStateSlice = createSlice({
329336
}
330337
});
331338
}
339+
332340
const newChild: ChildElement = {
333341
type,
334342
typeId,
@@ -341,6 +349,7 @@ const appStateSlice = createSlice({
341349
stateProps: [], //legacy pd: added stateprops and passedinprops
342350
passedInProps: []
343351
};
352+
344353
// added missing properties
345354
const topSeparator: ChildElement = {
346355
type: 'HTML Element',
@@ -366,7 +375,7 @@ const appStateSlice = createSlice({
366375
parentComponent.children.push(newChild);
367376
}
368377
}
369-
// if there is a childId (childId here references the direct parent of the new child) find that child and a new child to its children array
378+
// if there is a childId (childId here references the direct parent of the new child) find that child and add new child to its children array
370379
else {
371380
if (parentComponent) {
372381
directParent = findChild(parentComponent, childId);
@@ -379,23 +388,28 @@ const appStateSlice = createSlice({
379388
}
380389
}
381390
}
391+
// update canvasFocus to the new child
382392
const canvasFocus = {
383393
...state.canvasFocus,
384394
componentId: state.canvasFocus.componentId,
385395
childId: newChild.childId
386396
};
397+
387398
const nextChildId = state.nextChildId + 1;
388399
let nextTopSeparatorId = state.nextTopSeparatorId + 1;
389400
let addChildArray = components[canvasFocus.componentId - 1].children;
390-
addChildArray = manageSeparators.mergeSeparator(addChildArray, 1); // merge separator needs interface and type
401+
// merge separator needs interface and type
402+
addChildArray = manageSeparators.mergeSeparator(addChildArray, 1);
391403
if (directParent && directParent.name === 'separator')
392404
nextTopSeparatorId = manageSeparators.handleSeparators(
393405
// handle separator needs interface and type
394406
addChildArray,
395407
'add'
396408
);
409+
397410
components[canvasFocus.componentId - 1].children = addChildArray;
398411

412+
// generate code
399413
if (parentComponent) {
400414
parentComponent.code = generateCode(
401415
components,
@@ -407,11 +421,14 @@ const appStateSlice = createSlice({
407421
action.payload.contextParam
408422
);
409423
}
424+
425+
// update the state with the new values
410426
state.components = components;
411427
state.nextChildId = nextChildId;
412428
state.canvasFocus = canvasFocus;
413429
state.nextTopSeparatorId = nextTopSeparatorId;
414430
},
431+
415432
changeTailwind: (state, action) => {
416433
// return { ...state, tailwind: action.payload }
417434
state.tailwind = action.payload;

server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ io.on('connection', (client) => {
119119
.to(hostID)
120120
.emitWithAck('requesting state from host'); //sending request
121121

122-
console.log('hostState:', hostState);
122+
// console.log('hostState:', hostState);
123123

124124
//share host's state with the latest user
125125
const newClientResponse = await io //send the requested host state to the new client awaiting for the host state to come back before doing other task
@@ -143,6 +143,7 @@ io.on('connection', (client) => {
143143

144144
//server monitors incoming data from users for any new state changes
145145
client.on('new state from front', (redux_store, room: string) => {
146+
// console.log('new state from front:', JSON.parse(redux_store));
146147
if (room) {
147148
//server send the state from the user to everyone in the room
148149
client.to(room).emit('new state from back', redux_store);

0 commit comments

Comments
 (0)