Skip to content

Commit 3f3288f

Browse files
authored
Merge pull request #18 from oslabs-beta/sonya-cleaning
Updated dependencies, TypeScript conversion...
2 parents 24f26ef + a6a0376 commit 3f3288f

File tree

8 files changed

+665
-650
lines changed

8 files changed

+665
-650
lines changed

app/src/components/form/Selector.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ import FormControl from '@mui/material/FormControl';
33
import Select from '@mui/material/Select';
44
import MenuItem from '@mui/material/MenuItem';
55

6+
type Props = {
7+
items: [],
8+
classes: {
9+
configRow: any,
10+
configType: any,
11+
lightThemeFontColor: {color: String},
12+
formControl: any,
13+
select: any,
14+
selectInput: any,
15+
darkThemeFontColor: {color: String},
16+
},
17+
isThemeLight: Boolean,
18+
title: String,
19+
selectValue: any,
20+
handleChange: any,
21+
name: String,
22+
}
23+
624
const FormSelector = (props): JSX.Element => {
725
const items = [];
826
let key = 1;

app/src/components/left/ComponentsContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ComponentsContainer = () => {
2828
name={comp.name}
2929
id={comp.id}
3030
root={false}
31+
isThemeLight={false}
3132
/>
3233
);
3334
})}

app/src/components/right/SimpleModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const styles = (theme: any): any => ({
2828
}
2929
});
3030

31-
const SimpleModal = (props: any) => {
31+
const SimpleModal = (props) => {
3232
const {
3333
classes,
3434
open,
@@ -67,7 +67,8 @@ const SimpleModal = (props: any) => {
6767
fontSize: '17px',
6868
fontWeight: 'bold'
6969
}}
70-
size="large">
70+
size="large"
71+
>
7172
<CloseIcon />
7273
</IconButton>
7374
<Typography variant="h6" id="modal-title">

app/src/helperFunctions/generateCode.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, ChildElement, HTMLType } from '../interfaces/Interfaces';
1+
import {
2+
Component,
3+
ChildElement,
4+
HTMLType,
5+
ChildStyle,
6+
StateProp
7+
} from '../interfaces/Interfaces';
28
declare global {
39
interface Window {
410
api: any;
@@ -52,7 +58,7 @@ const generateUnformattedCode = (
5258
// declare an array of enriched children
5359
const enrichedChildren = currentComponent.children?.map((elem: any) => {
5460
//enrichedChildren is iterating through the children array
55-
const child = { ...elem };
61+
const child: ChildElement = { ...elem };
5662
// check if child is a component
5763
if (child.type === 'Component') {
5864
// verify that the child is in the components array in state
@@ -106,10 +112,10 @@ const generateUnformattedCode = (
106112
};
107113
// Raised formatStyles so that it is declared before it is referenced. It was backwards.
108114
// format styles stored in object to match React inline style format
109-
const formatStyles = (styleObj: any) => {
115+
const formatStyles = (styleObj: ChildStyle) => {
110116
if (Object.keys(styleObj).length === 0) return ``;
111-
const formattedStyles = [];
112-
let styleString;
117+
const formattedStyles: String[] = [];
118+
let styleString: String;
113119
for (let i in styleObj) {
114120
if (i === 'style') {
115121
styleString = i + '=' + '{' + JSON.stringify(styleObj[i]) + '}';
@@ -124,7 +130,7 @@ const generateUnformattedCode = (
124130
let customizationDetails = '';
125131
let passedInPropsString = '';
126132
if (childElement.type === 'Component') {
127-
let childComponent;
133+
let childComponent: Component;
128134
for (let i = 0; i < components.length; i++) {
129135
if (childElement.name === components[i].name) {
130136
childComponent = components[i];
@@ -152,7 +158,7 @@ const generateUnformattedCode = (
152158
Object.keys(childElement.style).length > 0 &&
153159
tailwind === false
154160
)
155-
customizationDetails += ' ' + formatStyles(childElement);
161+
customizationDetails += ' ' + formatStyles(childElement.style);
156162
if (
157163
childElement.style &&
158164
Object.keys(childElement.style).length > 0 &&
@@ -167,7 +173,7 @@ const generateUnformattedCode = (
167173
width,
168174
justifyContent
169175
} = childElement.style;
170-
let w, h, items, bg, d, flexDir, justCon, cssClasses;
176+
let w:String, h:String, items:String, bg:String, d:String, flexDir:String, justCon:String, cssClasses:String;
171177
if (childElement.style.alignItems) {
172178
if (alignItems === 'center') items = 'items-center ';
173179
else if (alignItems === 'flex-start') items = 'items-start ';
@@ -337,7 +343,7 @@ const generateUnformattedCode = (
337343
// write all code that will be under the "return" of the component
338344
const writeNestedElements = (enrichedChildren: any, level: number = 2) => {
339345
return `${enrichedChildren
340-
.map((child: any) => {
346+
.map((child: ChildElement) => {
341347
if (child.type === 'Component') {
342348
return `<${child.name} ${elementTagDetails(child)}/>`;
343349
} else if (child.type === 'HTML Element') {
@@ -363,14 +369,14 @@ const generateUnformattedCode = (
363369
.join('')}`;
364370
};
365371
// function to properly incorporate the user created state that is stored in the application state
366-
const writeStateProps = (stateArray: any) => {
367-
let stateToRender = '';
372+
const writeStateProps = (stateArray: String[]) => {
373+
let stateToRender:String = '';
368374
for (const element of stateArray) {
369375
stateToRender += levelSpacer(2, 2) + element + ';';
370376
}
371377
return stateToRender;
372378
};
373-
const enrichedChildren: any = getEnrichedChildren(currComponent);
379+
const enrichedChildren: ChildElement[] = getEnrichedChildren(currComponent);
374380
// import statements differ between root (pages) and regular components (components)
375381
const importsMapped =
376382
projectType === 'Next.js' || projectType === 'Gatsby.js'
@@ -386,7 +392,7 @@ const generateUnformattedCode = (
386392
return `import ${comp} from './${comp}'`;
387393
})
388394
.join('\n');
389-
const createState = (stateProps) => {
395+
const createState = (stateProps:StateProp[]) => {
390396
let state = '{';
391397
stateProps.forEach((ele) => {
392398
state += ele.key + ':' + JSON.stringify(ele.value) + ', ';
@@ -462,7 +468,7 @@ const generateUnformattedCode = (
462468
return importStr;
463469
};
464470

465-
const createEventHandler = (children) => {
471+
const createEventHandler = (children:ChildElement[]) => {
466472
let importStr = '';
467473
children.map((child) => {
468474
if (child.type === 'HTML Element') {

app/src/interfaces/Interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export interface StateProp {
7171
value: any;
7272
type: unknown;
7373
}
74-
7574
export interface Action {
7675
type: string;
7776
payload: any;

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const updateAllIds = (comp: Component[] | ChildElement[]) => {
128128
// put components' names and ids into an obj
129129
const obj = { spr: 1000, others: 1 };
130130
// for each of the components, if it has children, iterate through that children array
131-
comp.forEach((el) => {
131+
comp.forEach((el:Component | ChildElement) => {
132132
if (el.children.length > 0) {
133133
for (let i = 0; i < el.children.length; i++) {
134134
// update each child's childId
@@ -180,7 +180,7 @@ const deleteById = (id: number, name: string, state: State): Component[] => {
180180
const checkChildren = (child: Component[] | ChildElement[]) => {
181181
// for each of the components in the passed in components array, if the child
182182
// component has a children array, iterate through the array of children
183-
child.forEach((el) => {
183+
child.forEach((el:Component | ChildElement) => {
184184
if (el.children.length) {
185185
const arr: ChildElement[] = [];
186186
for (let i = 0; i < el.children.length; i++) {
@@ -206,7 +206,7 @@ const deleteById = (id: number, name: string, state: State): Component[] => {
206206
return updateIds(filteredArr);
207207
};
208208

209-
const updateUseStateCodes = (currentComponent) => {
209+
const updateUseStateCodes = (currentComponent: Component | ChildElement) => {
210210
// array of snippets of state prop codes
211211
const localStateCode: string[] = []; // avoid never by assigning it to string
212212
currentComponent.stateProps
@@ -359,7 +359,7 @@ const appStateSlice = createSlice({
359359
// if the newChild Element is an input or img type, delete the children key/value pair
360360
// if (newChild.name === 'input' && newChild.name === 'img')
361361
// delete newChild.children;
362-
let directParent;
362+
let directParent: HTMLElement | any;
363363
if (childId === null) {
364364
if (parentComponent) {
365365
parentComponent.children.push(topSeparator);
@@ -417,7 +417,7 @@ const appStateSlice = createSlice({
417417
state.tailwind = action.payload;
418418
},
419419
changeFocus: (state, action) => {
420-
const { componentId, childId } = action.payload;
420+
const { componentId, childId} = action.payload;
421421
if (childId < 1000) {
422422
// makes separators not selectable
423423
state.canvasFocus = { ...state.canvasFocus, componentId, childId };
@@ -894,7 +894,7 @@ const appStateSlice = createSlice({
894894
state.components[focusIndex].past.length - 1
895895
];
896896
// the last element of the past array gets popped off
897-
const poppedEl = state.components[focusIndex].past.pop();
897+
const poppedEl: Component = state.components[focusIndex].past.pop();
898898
// the last element of the past array gets popped off and pushed into the future array
899899
state.components[focusIndex].future.push(poppedEl);
900900
//generate code for the Code Preview
@@ -922,7 +922,7 @@ const appStateSlice = createSlice({
922922
state.components[focusIndex].future.length - 1
923923
];
924924
//the last element of the future array gets pushed into the past
925-
const poppedEl = state.components[focusIndex].future.pop();
925+
const poppedEl: Component = state.components[focusIndex].future.pop();
926926
//the last element of the future array gets popped out
927927
state.components[focusIndex].past.push(poppedEl);
928928
// generate code for the Code Preview
@@ -978,7 +978,7 @@ const appStateSlice = createSlice({
978978
}
979979

980980
//find the parent for deleting instances of where the parent is passing props to children
981-
let parent;
981+
let parent: Component;
982982
for (let i = 0; i < components.length; i++) {
983983
let currComponent = components[i];
984984
for (let j = 0; j < currComponent.children.length; j++) {
@@ -1034,7 +1034,7 @@ const appStateSlice = createSlice({
10341034
);
10351035

10361036
//find the parent of the component that we are deleting from
1037-
let parent;
1037+
let parent: Component;
10381038
for (let i = 0; i < components.length; i++) {
10391039
let currComponent = components[i];
10401040
for (let j = 0; j < currComponent.children.length; j++) {
@@ -1046,8 +1046,8 @@ const appStateSlice = createSlice({
10461046
}
10471047

10481048
//deletes all instances of passedInProps from the children arrays of the current Component
1049-
const deletePassedInPropsChildren = (currComponent) => {
1050-
const innerFunc = (currChild) => {
1049+
const deletePassedInPropsChildren = (currComponent:Component) => {
1050+
const innerFunc = (currChild:Component|ChildElement) => {
10511051
// when there are no children, return up a level
10521052
if (
10531053
currChild.children.filter((el) => el.type === 'Component')
@@ -1080,7 +1080,7 @@ const appStateSlice = createSlice({
10801080
);
10811081
};
10821082
//delete from the components passedInProps array
1083-
const deletePassedInProps = (myComponent) => {
1083+
const deletePassedInProps = (myComponent:Component) => {
10841084
if (
10851085
myComponent.children.filter((el) => el.type === 'Component')
10861086
.length === 0

0 commit comments

Comments
 (0)