1
1
// Future developers: This file needs to move to right folder: src/components/right
2
-
3
2
import React , { useState , useContext , useEffect , useCallback } from 'react' ;
4
- import StateContext from '../../context/context' ;
5
- import { styled } from '@mui/material/styles' ;
6
3
import makeStyles from '@mui/styles/makeStyles' ;
7
4
import {
8
5
Button ,
@@ -19,15 +16,13 @@ import { addComponent } from '../../redux/reducers/slice/appStateSlice';
19
16
20
17
21
18
// The component panel section of the left panel displays all components and has the ability to add new components
22
- const ComponentPanel = ( { isThemeLight} ) : JSX . Element => {
19
+ const ComponentPanel = ( { isThemeLight } ) : JSX . Element => {
23
20
const classes = useStyles ( ) ;
24
- // const [state, dispatch] = useContext(StateContext);
25
-
26
21
const { state, contextParam } = useSelector ( ( store ) => ( {
27
22
state : store . appState ,
28
23
contextParam : store . contextSlice ,
29
24
} ) ) ;
30
- const dispatch = useDispatch ( ) ;
25
+ const dispatch = useDispatch ( ) ;
31
26
32
27
33
28
//state hooks for inputted component name, component id and array of components
@@ -76,14 +71,14 @@ const dispatch = useDispatch();
76
71
} ;
77
72
78
73
const checkIfRoot = ( inputName : String ) : boolean => {
79
- let rootDupe = false ;
74
+ let rootDupe = false ;
80
75
// checks to see if inputted comp name is equal to root component name. Want to prevent that
81
-
76
+
82
77
//carly console logs
83
- const rootComponents = state . rootComponents ;
84
- const allComponents = state . components ;
78
+ const rootComponents = state . rootComponents ;
79
+ const allComponents = state . components ;
85
80
86
- if ( inputName . toLowerCase ( ) === 'index' || inputName . toLowerCase ( ) === 'app' ) {
81
+ if ( inputName . toLowerCase ( ) === 'index' || inputName . toLowerCase ( ) === 'app' ) {
87
82
rootDupe = true ;
88
83
}
89
84
return rootDupe ;
@@ -103,10 +98,6 @@ const dispatch = useDispatch();
103
98
? inputNameClean . charAt ( 0 ) . toUpperCase ( ) + inputNameClean . slice ( 1 ) // capitalizes first letter
104
99
: inputNameClean ;
105
100
// add new component to state
106
- // dispatch({
107
- // type: 'ADD COMPONENT',
108
- // payload: { componentName: formattedName, root: isRoot }
109
- // });
110
101
dispatch ( addComponent ( { componentName : formattedName , root : isRoot , contextParam : contextParam } ) ) ;
111
102
// reset root toggle back to default position
112
103
setIsRoot ( false ) ;
@@ -145,88 +136,88 @@ const dispatch = useDispatch();
145
136
146
137
const keyBindCreateComponent = useCallback ( ( e ) => {
147
138
148
- if ( e . key === 'Enter' && e . target . tagName !== "TEXTAREA" ) {
139
+ if ( e . key === 'Enter' && e . target . tagName !== "TEXTAREA" ) {
149
140
e . preventDefault ( ) ;
150
141
document . getElementById ( 'addComponentButton' ) . click ( ) ;
151
142
}
152
143
} , [ ] ) ;
153
-
144
+
154
145
useEffect ( ( ) => {
155
146
document . addEventListener ( 'keydown' , keyBindCreateComponent ) ;
156
147
return ( ) => {
157
148
document . removeEventListener ( 'keydown' , keyBindCreateComponent )
158
149
}
159
150
} , [ ] ) ;
160
-
151
+ console . log ( isThemeLight )
161
152
return (
162
153
< div className = { `${ classes . panelWrapper } ` } >
163
154
{ /* Add a new component*/ }
164
155
< div className = { classes . addComponentWrapper } >
165
- < h4
166
- className = { isThemeLight ? `${ classes . newComponent } ${ classes . lightThemeFontColor } ` : `${ classes . newComponent } ${ classes . darkThemeFontColor } ` }
167
- >
168
- New Component
169
- </ h4 >
170
- { /* input for new component */ }
171
- < div style = { { display : 'flex' , justifyContent :'center' , marginTop : '20px' , marginBottom : '20px' , alignItems :'baseline' } } >
172
- < div style = { { alignSelf :'center' } } >
173
- < InputLabel className = { isThemeLight ? `${ classes . inputLabel } ${ classes . lightThemeFontColor } ` : `${ classes . inputLabel } ${ classes . darkThemeFontColor } ` } >
174
- Name:
175
- </ InputLabel >
176
- < div className = { classes . inputWrapper } >
177
- < TextField
178
- // label='New Component Name'
179
- color = 'primary'
180
- variant = "outlined"
181
- className = { isThemeLight ? `${ classes . inputField } ${ classes . lightThemeFontColor } ` : `${ classes . inputField } ${ classes . darkThemeFontColor } ` }
182
- // inputprops and helpertext must be lowercase
183
- inputProps = { { className : classes . input } }
184
- value = { compName }
185
- // Doesn't accept boolean value needs to be a string
186
- error = { errorStatus }
187
- // Updated
188
- helperText = { errorStatus ? errorMsg : '' }
189
- onChange = { handleNameInput }
190
- style = { { } }
191
- InputProps = { {
192
- style : {
193
- color : isThemeLight ? 'black' : 'white'
194
- }
195
- } }
196
- />
197
- </ div >
198
- </ div >
199
-
200
- < div className = { classes . btnGroup } id = "checkboxContainer" style = { { marginBottom : '30px' } } >
201
- < FormControlLabel
202
- value = "top"
203
- control = {
204
- < Checkbox
205
- className = { isThemeLight ? `${ classes . rootCheckBox } ${ classes . lightThemeFontColor } ` : `${ classes . rootCheckBox } ${ classes . darkThemeFontColor } ` }
206
- color = "primary"
207
- checked = { isRoot }
208
- onChange = { toggleRootStatus }
209
-
210
- />
211
- }
212
- label = { state . projectType === 'Next.js' || state . projectType === 'Gatsby.js' ? 'Page' : 'Root' } // name varies depending on mode
213
- className = { isThemeLight ? `${ classes . rootCheckBoxLabel } ${ classes . lightThemeFontColor } ` : `${ classes . rootCheckBoxLabel } ${ classes . darkThemeFontColor } ` }
214
- labelPlacement = "top"
156
+ < h4
157
+ className = { isThemeLight ? `${ classes . newComponent } ${ classes . lightThemeFontColor } ` : `${ classes . newComponent } ${ classes . darkThemeFontColor } ` }
158
+ >
159
+ New Component
160
+ </ h4 >
161
+ { /* input for new component */ }
162
+ < div style = { { display : 'flex' , justifyContent : 'center' , marginTop : '20px' , marginBottom : '20px' , alignItems : 'baseline' } } >
163
+ < div style = { { alignSelf : 'center' } } >
164
+ < InputLabel className = { isThemeLight ? `${ classes . inputLabel } ${ classes . lightThemeFontColor } ` : `${ classes . inputLabel } ${ classes . darkThemeFontColor } ` } >
165
+ Name:
166
+ </ InputLabel >
167
+ < div className = { classes . inputWrapper } >
168
+ < TextField
169
+ // label='New Component Name'
170
+ color = 'primary'
171
+ variant = "outlined"
172
+ className = { isThemeLight ? `${ classes . inputField } ${ classes . lightThemeFontColor } ` : `${ classes . inputField } ${ classes . darkThemeFontColor } ` }
173
+ // inputprops and helpertext must be lowercase
174
+ inputProps = { { className : classes . input } }
175
+ value = { compName }
176
+ // Doesn't accept boolean value needs to be a string
177
+ error = { errorStatus }
178
+ // Updated
179
+ helperText = { errorStatus ? errorMsg : '' }
180
+ onChange = { handleNameInput }
181
+ style = { { } }
182
+ InputProps = { {
183
+ style : {
184
+ color : isThemeLight ? 'black' : 'white'
185
+ }
186
+ } }
215
187
/>
216
188
</ div >
217
189
</ div >
218
- < div style = { { display : 'flex' , justifyContent : 'center' } } >
219
- < br />
220
- < Button
221
- className = { isThemeLight ? `${ classes . addComponentButton } ${ classes . lightThemeFontColor } ` : `${ classes . addComponentButton } ${ classes . darkThemeFontColor } ` }
222
- color = 'primary'
223
- variant = 'contained'
224
- id = "addComponentButton"
225
- onClick = { handleNameSubmit }
226
- >
227
- Create
228
- </ Button >
190
+
191
+ < div className = { classes . btnGroup } id = "checkboxContainer" style = { { marginBottom : '30px' } } >
192
+ < FormControlLabel
193
+ value = "top"
194
+ control = {
195
+ < Checkbox
196
+ className = { isThemeLight ? `${ classes . rootCheckBox } ${ classes . lightThemeFontColor } ` : `${ classes . rootCheckBox } ${ classes . darkThemeFontColor } ` }
197
+ color = "primary"
198
+ checked = { isRoot }
199
+ onChange = { toggleRootStatus }
200
+
201
+ />
202
+ }
203
+ label = { state . projectType === 'Next.js' || state . projectType === 'Gatsby.js' ? 'Page' : 'Root' } // name varies depending on mode
204
+ className = { isThemeLight ? `${ classes . rootCheckBoxLabel } ${ classes . lightThemeFontColor } ` : `${ classes . rootCheckBoxLabel } ${ classes . darkThemeFontColor } ` }
205
+ labelPlacement = "top"
206
+ />
229
207
</ div >
208
+ </ div >
209
+ < div style = { { display : 'flex' , justifyContent : 'center' } } >
210
+ < br />
211
+ < Button
212
+ className = { isThemeLight ? `${ classes . addComponentButton } ${ classes . lightThemeFontColor } ` : `${ classes . addComponentButton } ${ classes . darkThemeFontColor } ` }
213
+ color = 'primary'
214
+ variant = 'contained'
215
+ id = "addComponentButton"
216
+ onClick = { handleNameSubmit }
217
+ >
218
+ Create
219
+ </ Button >
220
+ </ div >
230
221
</ div >
231
222
</ div >
232
223
) ;
@@ -256,9 +247,9 @@ const useStyles = makeStyles({
256
247
} ,
257
248
panelWrapper : {
258
249
display : 'flex' ,
259
- flexDirection :'column' ,
260
- alignItems :'center' ,
261
- flexGrow : 1 ,
250
+ flexDirection : 'column' ,
251
+ alignItems : 'center' ,
252
+ flexGrow : 1 ,
262
253
color : '#000000' ,
263
254
} ,
264
255
addComponentWrapper : {
@@ -315,16 +306,6 @@ const useStyles = makeStyles({
315
306
}
316
307
}
317
308
} ) ;
318
- // change to Button to make styling consistent
319
- // const CreateButton = styled(Button)({
320
- // background: "#0099E6",
321
- // border: 0,
322
- // borderRadius: 3,
323
- // boxShadow: "0 0px 0px 2px #1a1a1a",
324
- // color: "white",
325
- // height: 24,
326
- // width: 60,
327
- // padding: "0 30px",
328
- // });
309
+
329
310
330
311
export default ComponentPanel ;
0 commit comments