Skip to content

Commit 6ff29e7

Browse files
committed
theme changer for code preview ONLY
2 parents efbd6c7 + eb926f0 commit 6ff29e7

File tree

7 files changed

+116
-78
lines changed

7 files changed

+116
-78
lines changed

app/src/components/bottom/BottomPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const BottomPanel = () => {
1010
return (
1111
<Resizable
1212
enable={{
13-
top: true,
13+
top: true
1414
}}
1515
>
1616
<div className="bottom-panel">
@@ -20,4 +20,4 @@ const BottomPanel = () => {
2020
);
2121
};
2222

23-
export default BottomPanel;
23+
export default BottomPanel;

app/src/components/bottom/BottomTabs.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CodePreview from './CodePreview';
88
import Box from '@material-ui/core/Box';
99
import Tree from '../../tree/TreeChart';
1010
import { emitKeypressEvents } from 'readline';
11+
import 'ace-builds/src-noconflict/theme-monokai';
1112

1213
const BottomTabs = () => {
1314
// state that controls which tab the user is on
@@ -16,13 +17,16 @@ const BottomTabs = () => {
1617
const classes = useStyles();
1718
treeWrapper: HTMLDivElement;
1819

20+
const [theme, setTheme] = useState('monokai');
21+
// console.log('theme:', theme);
22+
1923
// method changes the
2024
const handleChange = (event: React.ChangeEvent, value: number) => {
2125
setTab(value);
2226
};
2327

2428
const { HTMLTypes } = state;
25-
const { components } = state;
29+
const { components } = state;
2630

2731
return (
2832
<div className={classes.root}>
@@ -47,7 +51,7 @@ const BottomTabs = () => {
4751
/>
4852
</Tabs>
4953
</Box>
50-
{tab === 0 && <CodePreview />}
54+
{tab === 0 && <CodePreview theme={theme} setTheme={setTheme} />}
5155
{tab === 1 && <Tree data={components} />}
5256
</div>
5357
);

app/src/components/bottom/CodePreview.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ const useStyles = makeStyles(theme => ({
2323
}
2424
}));
2525

26-
const CodePreview = () => {
26+
const optionColor = '#252526';
27+
28+
const CodePreview = ({ theme, setTheme }) => {
2729
const [state, dispatch] = useContext(stateContext);
28-
const [theme, setTheme] = useState('monokai');
30+
// const [theme, setTheme] = useState('monokai');
2931
const classes = useStyles();
3032
const currentComponent = state.components.find(
3133
(elem: Component) => elem.id === state.canvasFocus.componentId
@@ -44,15 +46,14 @@ const CodePreview = () => {
4446
style={{
4547
height: '90%',
4648
paddingLeft: '0px',
47-
// paddingTop: '1rem',
48-
// paddingBottom: '1rem',
49+
paddingBottom: '8%',
4950
// overflow: 'auto',
5051
maxWidth: '100%',
5152
// display: 'flex',
5253
justifyContent: 'center'
5354
}}
5455
>
55-
<FormControl fullWidth={true} className={classes.formControl}>
56+
<FormControl className={classes.formControl}>
5657
<div className="flex-container">
5758
<div className="flex1">Change Theme:</div>
5859
<NativeSelect

app/src/components/left/HTMLPanel.tsx

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const HTMLPanel = (): JSX.Element => {
1414
const [errorMsg, setErrorMsg] = useState('');
1515
const [errorStatus, setErrorStatus] = useState(false);
1616

17-
1817
const handleTagChange = (e: React.ChangeEvent<HTMLInputElement>) => {
1918
resetError();
2019
setTag(e.target.value);
@@ -31,7 +30,10 @@ const HTMLPanel = (): JSX.Element => {
3130
// checks to see if inputted comp name already exists
3231
let dupe = false;
3332
checkList.forEach(HTMLTag => {
34-
if ((HTMLTag.name.toLowerCase() === inputName.toLowerCase()) || (HTMLTag.tag.toLowerCase() === inputName.toLowerCase())) {
33+
if (
34+
HTMLTag.name.toLowerCase() === inputName.toLowerCase() ||
35+
HTMLTag.tag.toLowerCase() === inputName.toLowerCase()
36+
) {
3537
dupe = true;
3638
}
3739
});
@@ -58,7 +60,8 @@ const HTMLPanel = (): JSX.Element => {
5860
const createOption = (inputTag: String, inputName: String) => {
5961
// format name so first letter is capitalized and there are no whitespaces
6062
let inputNameClean = inputName.replace(/\s+/g, '');
61-
const formattedName = inputNameClean.charAt(0).toUpperCase() + inputNameClean.slice(1);
63+
const formattedName =
64+
inputNameClean.charAt(0).toUpperCase() + inputNameClean.slice(1);
6265
// add new component to state
6366
const newElement = {
6467
id: currentID,
@@ -82,18 +85,18 @@ const HTMLPanel = (): JSX.Element => {
8285
let letterNumber = /^[0-9a-zA-Z]+$/;
8386
if (input.match(letterNumber)) return true;
8487
return false;
85-
}
88+
};
8689

87-
const handleSubmit = (e) => {
90+
const handleSubmit = e => {
8891
e.preventDefault();
8992
let letters = /[a-zA-Z]/;
90-
if ((!tag.charAt(0).match(letters)) || (!name.charAt(0).match(letters))) {
93+
if (!tag.charAt(0).match(letters) || !name.charAt(0).match(letters)) {
9194
triggerError('letters');
9295
return;
9396
} else if (!alphanumeric(tag) || !alphanumeric(name)) {
9497
triggerError('symbolsDetected');
9598
return;
96-
} else if ((tag.trim() === '') || (name.trim() === '')) {
99+
} else if (tag.trim() === '' || name.trim() === '') {
97100
triggerError('empty');
98101
return;
99102
} else if (checkNameDupe(tag) || checkNameDupe(name)) {
@@ -102,28 +105,45 @@ const HTMLPanel = (): JSX.Element => {
102105
}
103106
createOption(tag, name);
104107
resetError();
105-
}
108+
};
106109

107110
return (
108111
<div>
109112
<h4> HTML Elements</h4>
110113
<div className={classes.addComponentWrapper}>
111-
<div className={classes.inputWrapper} >
112-
<form onSubmit={handleSubmit} >
114+
<div className={classes.inputWrapper}>
115+
<form onSubmit={handleSubmit}>
113116
<h4>Create New Element: </h4>
114117
<label className={classes.inputLabel}>
115118
Tag:
116-
<input color={'primary'} type="text" name="Tag" value={tag} onChange={handleTagChange} className={classes.input} />
117-
{errorStatus &&
118-
<span>{errorMsg}</span>}
119+
<input
120+
color={'primary'}
121+
type="text"
122+
name="Tag"
123+
value={tag}
124+
onChange={handleTagChange}
125+
className={classes.input}
126+
/>
127+
{errorStatus && <span>{errorMsg}</span>}
119128
</label>
120129
<label className={classes.inputLabel}>
121130
Tag Name:
122-
<input color={'primary'} type="text" name="Tag Name" value={name} onChange={handleNameChange} className={classes.input} />
123-
{errorStatus &&
124-
<span>{errorMsg}</span>}
131+
<input
132+
color={'primary'}
133+
type="text"
134+
name="Tag Name"
135+
value={name}
136+
onChange={handleNameChange}
137+
className={classes.input}
138+
/>
139+
{errorStatus && <span>{errorMsg}</span>}
125140
</label>
126-
<input className={classes.button} color="primary" type="submit" value="Add Element" />
141+
<input
142+
className={classes.button}
143+
color="primary"
144+
type="submit"
145+
value="Add Element"
146+
/>
127147
</form>
128148
</div>
129149
</div>

app/src/reducers/componentReducer.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import initialState from '../context/initialState';
88
import generateCode from '../helperFunctions/generateCode';
99
import cloneDeep from '../helperFunctions/cloneDeep';
10-
import HTMLTypes from '../context/HTMLTypes';
1110

1211
const reducer = (state: State, action: Action) => {
1312
// if the project type is set as Next.js, next component code should be generated
@@ -103,13 +102,14 @@ const reducer = (state: State, action: Action) => {
103102
});
104103
});
105104
return isChild;
106-
}
105+
};
107106

108107
const updateIds = (components: Component[]) => {
109-
components.forEach((comp, i) => comp.id = i + 1);
110-
}
108+
components.forEach((comp, i) => (comp.id = i + 1));
109+
};
111110

112-
const deleteById = (id: number): Component[] => [...state.components].filter(comp => comp.id != id);
111+
const deleteById = (id: number): Component[] =>
112+
[...state.components].filter(comp => comp.id != id);
113113

114114
switch (action.type) {
115115
// Add a new component type
@@ -172,10 +172,10 @@ const reducer = (state: State, action: Action) => {
172172
return state;
173173
}
174174

175-
let newName = HTMLTypes.reduce((name, el) => {
175+
let newName = state.HTMLTypes.reduce((name, el) => {
176176
if (typeId === el.id) name = el.tag;
177177
return name;
178-
},'');
178+
}, '');
179179

180180
const newChild: ChildElement = {
181181
type,
@@ -195,7 +195,6 @@ const reducer = (state: State, action: Action) => {
195195
parentComponent.children.push(newChild);
196196
}
197197
// 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
198-
199198
else {
200199
const directParent = findChild(parentComponent, childId);
201200
directParent.children.push(newChild);
@@ -329,31 +328,33 @@ const reducer = (state: State, action: Action) => {
329328
updateIds(components);
330329

331330
// rebuild root components
332-
const rootComponents: number[] = [];
331+
const rootComponents: number[] = [];
333332
components.forEach(comp => {
334333
if (comp.isPage) rootComponents.push(comp.id);
335334
});
336-
335+
337336
//TODO: where should canvas focus after deleting comp?
338-
const canvasFocus = { componentId: 1, childId: null }
337+
const canvasFocus = { componentId: 1, childId: null };
339338

340-
return {...state, rootComponents, components, canvasFocus}
339+
return { ...state, rootComponents, components, canvasFocus };
341340
}
342-
case 'DELETE REUSABLE COMPONENT' : {
341+
case 'DELETE REUSABLE COMPONENT': {
343342
// TODO: bug when deleting element inside page
344-
// can't edit component name
345-
// happens sometimes. not sure exactly when
343+
// can't edit component name
344+
// happens sometimes. not sure exactly when
346345

347346
const id: number = state.canvasFocus.componentId;
348347
// check if component is a child element of a page
349348
// check if id is inside root components
350-
if(isChildOfPage(id)) {
349+
if (isChildOfPage(id)) {
351350
// TODO: include name of parent in alert
352351
// TODO: change canvas focus to parent
353352
// TODO: modal
354-
console.log('Reusable components inside of a page must be deleted from the page');
353+
console.log(
354+
'Reusable components inside of a page must be deleted from the page'
355+
);
355356
//const canvasFocus:Object = { componentId: id, childId: null };
356-
return { ...state }
357+
return { ...state };
357358
}
358359
// filter out components that don't match id
359360
const components: Component[] = deleteById(id);
@@ -362,7 +363,7 @@ const reducer = (state: State, action: Action) => {
362363

363364
// TODO: temporary fix. should point to id directly
364365
const canvasFocus = { componentId: 1, childId: null };
365-
return {...state, components, canvasFocus};
366+
return { ...state, components, canvasFocus };
366367
}
367368

368369
case 'SET INITIAL STATE': {
@@ -450,7 +451,7 @@ const reducer = (state: State, action: Action) => {
450451
return {
451452
...state,
452453
HTMLTypes
453-
}
454+
};
454455
}
455456
default:
456457
return state;

0 commit comments

Comments
 (0)