@@ -5,12 +5,14 @@ import cloneDeep from './cloneDeep';
5
5
import {
6
6
ComponentInt ,
7
7
ApplicationStateInt ,
8
- ChildrenInt ,
8
+ // ChildrenInt, //unused import//
9
9
ChildInt ,
10
10
ComponentsInt ,
11
11
PropInt
12
12
} from './Interfaces' ;
13
13
14
+ //this is the default values for any component added to the app.
15
+
14
16
const initialComponentState : ComponentInt = {
15
17
id : 0 ,
16
18
stateful : false ,
@@ -58,9 +60,12 @@ export const addComponent = (
58
60
} ;
59
61
}
60
62
63
+ //chooses a color for the component from the random color generator
61
64
const componentColor = getColor ( ) ;
65
+ //assigns the componentID to whatever issupposed to be next
62
66
const componentId = state . nextId ;
63
67
68
+ //creates a newcomponent and prepares it to be added to an array of components in the store
64
69
const newComponent : ComponentInt = {
65
70
...initialComponentState ,
66
71
title : strippedTitle ,
@@ -71,16 +76,21 @@ export const addComponent = (
71
76
72
77
const components = [ ...state . components , newComponent ] ;
73
78
79
+ //increments both total components and the nextID
74
80
const totalComponents = state . totalComponents + 1 ;
75
81
const nextId = state . nextId + 1 ;
76
82
83
+
84
+ //creates an array of component IDs that can be added as children to this newly created component.
85
+ //the newly created component and the App component are never selectable.
77
86
const selectableChildren = state . components
78
87
. map ( ( comp : ComponentInt ) => comp . id )
79
88
. filter ( ( id : number ) => id !== newComponent . id ) ;
80
89
81
90
const ancestors : Array < number > = [ ] ;
82
91
83
- // reset focused child
92
+ // reset focused child to null values so when focused component is assigned to the newly created component,
93
+ //child from previously focused component doesn;t show up
84
94
const newFocusChild = cloneDeep ( state . initialApplicationFocusChild ) ;
85
95
return {
86
96
...state ,
@@ -94,6 +104,7 @@ export const addComponent = (
94
104
} ;
95
105
} ;
96
106
107
+ //reducer function to add component or HTML child to currently focused component
97
108
export const addChild = (
98
109
state : ApplicationStateInt ,
99
110
{
@@ -104,10 +115,12 @@ export const addChild = (
104
115
) => {
105
116
const strippedTitle = title ;
106
117
118
+ //is this warning even possible to trigger witht he current flow?
107
119
if ( ! childType ) {
108
120
window . alert ( 'addChild Error! no type specified' ) ;
109
121
}
110
122
123
+ //weird use of a ternary operator, could've wrapped it in one if statement
111
124
const htmlElement = childType !== 'COMP' ? childType : null ;
112
125
if ( childType !== 'COMP' ) {
113
126
childType = 'HTML' ;
@@ -138,14 +151,17 @@ export const addChild = (
138
151
if ( childType === 'HTML' ) {
139
152
htmlElemPosition = getSize ( htmlElement ) ;
140
153
// if above function doesnt reutn anything, it means html element is not in our database
154
+ //looks like the group that originally worked on this app planend to have a back end that accessed a DB with element types.
155
+ //I don't think this error does anything anymore either.
141
156
if ( ! htmlElemPosition . width ) {
142
157
console . log (
143
158
`Did not add html child: ${ htmlElement } the GetSize function indicated that it isnt in our DB`
144
159
) ;
145
160
return ;
146
161
}
147
162
}
148
-
163
+ //intersting how they decided to offset the next child to be placed on the stage by multiplying
164
+ //the next child ID by 16. I mean I guess it makes sense.
149
165
const newPosition =
150
166
childType === 'COMP'
151
167
? {
@@ -160,7 +176,7 @@ export const addChild = (
160
176
width : htmlElemPosition . width ,
161
177
height : htmlElemPosition . height
162
178
} ;
163
-
179
+
164
180
const newChild : ChildInt = {
165
181
childId : view . nextChildId ,
166
182
childSort : view . nextChildId ,
@@ -174,7 +190,9 @@ export const addChild = (
174
190
} ;
175
191
176
192
const compsChildrenArr = [ ...view . childrenArray , newChild ] ;
193
+
177
194
195
+ //values to put into the focus component so it is updated along with the components array
178
196
const component = {
179
197
...view ,
180
198
childrenArray : compsChildrenArr ,
@@ -261,13 +279,18 @@ export const deleteChild = (
261
279
} ;
262
280
} ;
263
281
282
+ //Simple function that changes the imageSource in the global state.
283
+ //Should be refactored to also store image data not just source,
284
+ //since currently HTML image lives in a local state of AppContainer ( a big no-no)
285
+ //and if a user clicks on 'clear workspace', the button doesn't reset
264
286
export const deleteImage = ( state : ApplicationStateInt ) => {
265
287
return {
266
288
...state ,
267
289
imageSource : ''
268
290
} ;
269
291
} ;
270
292
293
+ //the function that handles the transformation of all children in the stage
271
294
export const handleTransform = (
272
295
state : ApplicationStateInt ,
273
296
{
@@ -291,6 +314,8 @@ export const handleTransform = (
291
314
const component = state . components . find (
292
315
( comp : ComponentInt ) => comp . id === componentId
293
316
) ;
317
+
318
+ //first check if changed, if falsy then assign the original values
294
319
const transformedComponent = {
295
320
...component ,
296
321
position : {
@@ -301,6 +326,7 @@ export const handleTransform = (
301
326
}
302
327
} ;
303
328
329
+ //return state with updated component values
304
330
const components = [
305
331
...state . components . filter ( ( comp : ComponentInt ) => {
306
332
if ( comp . id !== componentId ) return comp ;
0 commit comments