Skip to content

Commit d941fd1

Browse files
authored
Merge pull request #3 from oslabs-beta/frontEnd
Merge FrontEnd with Master
2 parents 18a4b55 + e33110a commit d941fd1

File tree

10 files changed

+43
-24
lines changed

10 files changed

+43
-24
lines changed

app/src/components/bottom/BottomTabs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const BottomTabs = () => {
2525

2626
// breaks if handleChange is commented out
2727
const handleChange = (event: React.ChangeEvent, value: number) => {
28+
// console.log('value', value)
29+
// console.log('setTab', setTab)
2830
setTab(value);
2931
};
3032
// Allows users to toggle project between "next.js" and "Classic React"
@@ -34,6 +36,7 @@ const BottomTabs = () => {
3436
dispatch({ type: 'CHANGE PROJECT TYPE', payload: { projectType } });
3537
};
3638
const { components, HTMLTypes } = state;
39+
// console.log('components', components)
3740

3841
const changeTheme = e => {
3942
setTheme(e.target.value);

app/src/components/bottom/CodePreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const CodePreview: React.FC<{
1616
setTheme: any | null;
1717
}> = ({ theme, setTheme }) => {
1818
const wrapper = useRef();
19+
// console.log('wrapper', wrapper)
1920
const dimensions = useResizeObserver(wrapper);
21+
// console.log('dimensions', dimensions)
2022
const { width, height } =
2123
dimensions || 0;
2224

@@ -25,7 +27,7 @@ const CodePreview: React.FC<{
2527
const currentComponent = state.components.find(
2628
(elem: Component) => elem.id === state.canvasFocus.componentId
2729
);
28-
30+
console.log('currentComp in CodePreview', currentComponent)
2931
const handleCodeSnipChange = val => {
3032
currentComponent.code = val;
3133
};

app/src/components/left/HTMLPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const HTMLPanel = (props): JSX.Element => {
184184
type="text"
185185
name="Tag"
186186
value={tag}
187-
autocomplete="off"
187+
autoComplete="off"
188188
onChange={handleTagChange}
189189
className={isThemeLight ? `${classes.input} ${classes.lightThemeFontColor}` : `${classes.input} ${classes.darkThemeFontColor}`}
190190
style={{ marginBottom: '10px' }}
@@ -206,7 +206,7 @@ const HTMLPanel = (props): JSX.Element => {
206206
name="Tag Name"
207207
value={name}
208208
onChange={handleNameChange}
209-
autocomplete="off"
209+
autoComplete="off"
210210
className={isThemeLight ? `${classes.input} ${classes.lightThemeFontColor}` : `${classes.input} ${classes.darkThemeFontColor}`}
211211
/>
212212

app/src/components/main/Canvas.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function Canvas() {
1212
const currentComponent: Component = state.components.find(
1313
(elem: Component) => elem.id === state.canvasFocus.componentId
1414
);
15-
15+
// console.log('currentComponent', currentComponent)
16+
1617
// changes focus of the canvas to a new component / child
1718
const changeFocus = (componentId: number, childId: number | null) => {
1819
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId } });
@@ -31,6 +32,7 @@ function Canvas() {
3132
if (didDrop) {
3233
return;
3334
}
35+
console.log('item', item)
3436
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
3537
if (item.newInstance) {
3638
dispatch({
@@ -47,6 +49,7 @@ function Canvas() {
4749
dispatch({
4850
type: 'CHANGE POSITION',
4951
payload: {
52+
// name: item.name,
5053
currentChildId: item.childId,
5154
newParentChildId: null
5255
}

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ function DirectChildHTMLNestable({
1212
type,
1313
typeId,
1414
style,
15-
children
15+
children,
16+
name,
1617
}: ChildElement) {
1718
const [state, dispatch] = useContext(StateContext);
1819
const ref = useRef(null);
19-
20+
// console.log('name', name)
21+
// console.log('children', children)
2022
// find the HTML element corresponding with this instance of an HTML element
2123
// find the current component to render on the canvas
2224
const HTMLType: HTMLType = state.HTMLTypes.find(
@@ -31,7 +33,8 @@ function DirectChildHTMLNestable({
3133
newInstance: false,
3234
childId: childId,
3335
instanceType: type,
34-
instanceTypeId: typeId
36+
instanceTypeId: typeId,
37+
name: name //added code <--
3538
},
3639
canDrag: HTMLType.id !== 1000, // dragging not permitted if element is separator
3740
collect: (monitor: any) => {
@@ -58,7 +61,7 @@ function DirectChildHTMLNestable({
5861
payload: {
5962
type: item.instanceType,
6063
typeId: item.instanceTypeId,
61-
childId: childId
64+
childId: childId,
6265
}
6366
});
6467
}
@@ -68,7 +71,7 @@ function DirectChildHTMLNestable({
6871
type: 'CHANGE POSITION',
6972
payload: {
7073
currentChildId: item.childId,
71-
newParentChildId: childId
74+
newParentChildId: childId,
7275
}
7376
});
7477
}
@@ -111,6 +114,7 @@ function DirectChildHTMLNestable({
111114
drag(drop(ref));
112115
return (
113116
<div onClick={onClickHandler} style={combinedStyle} ref={ref}>
117+
{HTMLType.placeHolderShort}
114118
{renderChildren(children)}
115119
</div>
116120
);

app/src/context/initialState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const initialState: State = {
88
components: [
99
{
1010
id: 1,
11-
name: 'index',
11+
name: 'App',
1212
style: {},
1313
code: '<div>Drag in a component or HTML element into the canvas!</div>',
1414
children: [],

app/src/helperFunctions/generateCode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const generateUnformattedCode = (
3434
// declare an array of enriched children
3535

3636
const enrichedChildren = currentComponent.children.map((elem: any) => {
37+
//enrichedChildren is iterating through the children array
3738
const child = { ...elem };
3839

3940
// check if child is a component
@@ -52,7 +53,8 @@ const generateUnformattedCode = (
5253
child['tag'] = referencedHTML.tag;
5354
if (
5455
referencedHTML.tag === 'div' ||
55-
referencedHTML.tag === 'separator'
56+
referencedHTML.tag === 'separator' ||
57+
referencedHTML.tag === 'form'
5658
) {
5759
child.children = getEnrichedChildren(child);
5860
}
@@ -95,9 +97,9 @@ const generateUnformattedCode = (
9597
child.tag
9698
}>`;
9799
} else if (child.tag === 'form') {
98-
return `<${child.tag}${formatStyles(child.style)}>FORM</${
99-
child.tag
100-
}>`;
100+
return `<${child.tag}${formatStyles(
101+
child.style
102+
)}>${writeNestedElements(child.children)}</${child.tag}>`;
101103
} else if (child.tag === 'p') {
102104
return `<${child.tag}${formatStyles(
103105
child.style

app/src/helperFunctions/renderChildren.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const renderChildren = (children: ChildElement[]) => {
3030
/>
3131
);
3232
}
33-
// child is a non-nestable type of HTML element (everything except for divs)
34-
else if (type === 'HTML Element' && typeId !== 11 && typeId !== 1000) {
33+
// child is a non-nestable type of HTML element (everything except for divs and forms)
34+
else if (type === 'HTML Element' && typeId !== 11 && typeId !== 1000 && typeId !== 2) {
3535
return (
3636
<DirectChildHTML
3737
childId={childId}
@@ -43,8 +43,8 @@ const renderChildren = (children: ChildElement[]) => {
4343
/>
4444
);
4545
}
46-
// child is a nestable type of HTML element (divs)
47-
else if (type === 'HTML Element' && typeId === 11) {
46+
// child is a nestable type of HTML element (divs and forms)
47+
else if (type === 'HTML Element' && (typeId === 11 || typeId === 2)) {
4848
return (
4949
<DirectChildHTMLNestable
5050
childId={childId}

app/src/tree/useResizeObserver.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { useEffect, useState } from "react";
2-
import ResizeObserver from "resize-observer-polyfill";
1+
import { useEffect, useState } from 'react';
2+
import ResizeObserver from 'resize-observer-polyfill';
33

4-
const useResizeObserver = ref => {
4+
const useResizeObserver = (ref) => {
55
const [dimensions, setDimensions] = useState(null);
66
useEffect(() => {
77
// the element being observed (div with green border)
88
const observeTarget = ref.current;
9-
const resizeObserver = new ResizeObserver(entries => {
10-
entries.forEach(entry => {
11-
// contentRect is an object containing the dimensions of the observed element
9+
const resizeObserver = new ResizeObserver((entries) => {
10+
entries.forEach((entry) => {
11+
// contentRect is an object containing the dimensions of the observed element
1212
setDimensions(entry.contentRect);
1313
});
1414
});

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@
1010
"Adam Singer",
1111
"Alex Wolinsky",
1212
"Andrew Cho",
13+
"Anthony Torrero",
1314
"Brian Han",
1415
"Charles Finocchiaro",
1516
"Chelsey Fewer",
1617
"Christian Padilla",
1718
"Diego Vazquez",
19+
"Edward Park",
20+
"Elena Conn",
1821
"Eliot Nguyen",
1922
"Fredo Chen",
2023
"Jesse Zuniga",
2124
"Jin Soo Lim",
2225
"Julie Wu",
26+
"Khuong Nguyen",
2327
"Linh Tran",
2428
"Luke Madden",
2529
"Mitchel Severe",
2630
"Natalie Vick",
2731
"Sean Sadykoff",
32+
"Shana Hoehn",
2833
"Shlomo Porges",
2934
"Stormi Hashimoto",
3035
"Sophia Huttner",

0 commit comments

Comments
 (0)