Skip to content

Commit a051a72

Browse files
authored
Merge pull request #2 from oslabs-beta/ron-william-changes
ReactRouter components added to DragDrop panel, LinkTo - styles appear in CodePreview
2 parents 7329a36 + 13874b4 commit a051a72

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

app/src/components/left/DragDropPanel.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,38 @@ const DragDropPanel = (props): JSX.Element => {
4646
<Grid
4747
id="HTMLItemsGrid"
4848
>
49-
{htmlTypesToRender.map(option => (
50-
<HTMLItem
51-
name={option.name}
52-
key={`html-${option.name}`}
53-
id={option.id}
54-
Icon={option.icon}
55-
handleDelete={handleDelete}
56-
isThemeLight={isThemeLight}
57-
/>
58-
))}
49+
<h3>HTML ELEMENTS</h3>
50+
{htmlTypesToRender.map(option => {
51+
if(option.id !== 17 || option.id !== 18) {
52+
return (
53+
<HTMLItem
54+
name={option.name}
55+
key={`html-${option.name}`}
56+
id={option.id}
57+
Icon={option.icon}
58+
handleDelete={handleDelete}
59+
isThemeLight={isThemeLight}
60+
/>
61+
);
62+
}
63+
64+
})}
65+
<h3>REACT ROUTER</h3>
66+
{htmlTypesToRender.map(option => {
67+
if(option.id === 17 || option.id === 18) {
68+
return (
69+
<HTMLItem
70+
name={option.name}
71+
key={`html-${option.name}`}
72+
id={option.id}
73+
Icon={option.icon}
74+
handleDelete={handleDelete}
75+
isThemeLight={isThemeLight}
76+
/>
77+
);
78+
}
79+
})}
80+
5981
</Grid>
6082
</div>
6183
</div>

app/src/components/left/HTMLItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ const HTMLItem : React.FC<{
122122
// updated the id's to reflect the new element types input and label
123123
return ( // HTML Elements
124124
<Grid item xs={5} key={`html-g${name}`}>
125-
{ id <= 17 &&
125+
{ id <= 18 &&
126126
<div ref={drag} className={isThemeLight ? `${classes.HTMLPanelItem} ${classes.lightThemeFontColor}` : `${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`} id="HTMLItem">
127127
<h3>{name}</h3>
128128
</div>}
129-
{id > 17 &&
129+
{id > 18 &&
130130
<span id="customHTMLElement">
131131
<div ref={drag} className={isThemeLight ? `${classes.HTMLPanelItem} ${classes.lightThemeFontColor}` : `${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`} id="HTMLItem">
132132
<h3>{name}</h3>

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Canvas() {
2525
function onClickHandler(event) {
2626
event.stopPropagation();
2727
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
28+
console.log(state.canvasFocus);
2829
changeFocus(state.canvasFocus.componentId, null);
2930
};
3031

app/src/context/HTMLTypes.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ const HTMLTypes: HTMLType[] = [
163163
style: {},
164164
placeHolderShort: 'Switch',
165165
placeHolderLong: '',
166-
icon: HeaderIcon
166+
icon: ListIcon
167+
},
168+
{
169+
id: 18,
170+
tag: 'Link',
171+
name: 'LinkTo',
172+
style: {},
173+
placeHolderShort: 'link to',
174+
placeHolderLong: '',
175+
icon: ListIcon
167176
},
168177
{
169178
id: -1,

app/src/helperFunctions/generateCode.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const generateUnformattedCode = (
6060
referencedHTML.tag === 'ol' ||
6161
referencedHTML.tag === 'menu' ||
6262
referencedHTML.tag === 'li' ||
63+
referencedHTML.tag === 'Link' ||
6364
referencedHTML.tag === 'Switch' ||
6465
referencedHTML.tag === 'Route'
6566
) {
@@ -81,10 +82,16 @@ const generateUnformattedCode = (
8182
// Raised formatStyles so that it is declared before it is referenced. It was backwards.
8283
// format styles stored in object to match React inline style format
8384
const formatStyles = (styleObj: any) => {
85+
console.log(styleObj);
86+
8487
if (Object.keys(styleObj).length === 0) return ``;
8588
const formattedStyles = [];
8689
for (let i in styleObj) {
87-
const styleString = i + ': ' + "'" + styleObj[i] + "'";
90+
let styleString = i + ': ' + "'" + styleObj[i] + "'";
91+
// if(i === 'style') {
92+
// styleString = i + ':' + JSON.stringify(styleObj[i]);
93+
// }
94+
8895
formattedStyles.push(styleString);
8996
}
9097
return ' style={{' + formattedStyles.join(',') + '}}';
@@ -134,6 +141,10 @@ const generateUnformattedCode = (
134141
return `${levelSpacer(level, 5)}<${childElement.tag} href="${activeLink}" ${elementTagDetails(childElement)}>${innerText}</${childElement.tag}>${levelSpacer(2, (3 + level))}`;
135142
} else if (childElement.tag === 'input') {
136143
return `${levelSpacer(level, 5)}<${childElement.tag}${elementTagDetails(childElement)}></${childElement.tag}>${levelSpacer(2, (3 + level))}`;
144+
} else if (childElement.tag === 'Link') {
145+
return `${levelSpacer(level, 5)}<${childElement.tag} to="${activeLink}" ${elementTagDetails(childElement)}>${innerText}
146+
${tabSpacer(level)}${writeNestedElements(childElement.children, level + 1)}
147+
${tabSpacer(level - 1)}</${childElement.tag}>${levelSpacer(2, (3 + level))}`;
137148
} else if (nestable) {
138149
const routePath = (childElement.tag === 'Route') ? (' ' + 'exact path="' + activeLink + '"') : '';
139150
return `${levelSpacer(level, 5)}<${childElement.tag}${elementTagDetails(childElement)}${routePath}>${innerText}
@@ -205,6 +216,8 @@ const generateUnformattedCode = (
205216

206217
// create final component code. component code differs between classic react, next.js, gatsby.js
207218
// classic react code
219+
220+
//import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
208221
if (projectType === 'Classic React') {
209222
return `
210223
${stateful && !classBased ? `import React, {useState} from 'react';` : ''}

app/src/helperFunctions/renderChildren.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const renderChildren = (children: ChildElement[]) => {
3434
}
3535
// ommitted orderedlists, unorderedlists, and menus, ommitted li items as non-nestable types because they can be nested within.
3636
// child is a non-nestable type of HTML element (everything except for divs and forms)
37-
else if (type === 'HTML Element' && typeId !== 11 && typeId !== 1000 && typeId !== 2 && typeId !== 3 && typeId !== 14 && typeId !== 15 && typeId !== 16 && typeId !== 17 && typeId !== -1) {
37+
else if (type === 'HTML Element' && typeId !== 11 && typeId !== 1000 && typeId !== 2 && typeId !== 3 && typeId !== 14 && typeId !== 15 && typeId !== 16 && typeId !== 17 && typeId !== 18 && typeId !== -1) {
3838
return (
3939
<DirectChildHTML
4040
childId={childId}
@@ -48,7 +48,7 @@ const renderChildren = (children: ChildElement[]) => {
4848
}
4949
// Added Orderedlists, Unorderedlists, and Menus, changed lists to nestable because they are nestable.
5050
// child is a nestable type of HTML element (divs and forms)
51-
else if (type === 'HTML Element' && (typeId === 11 || typeId === 2 || typeId === 3 || typeId === 14 || typeId === 15 || typeId === 16 || typeId === 17 || typeId === -1)) {
51+
else if (type === 'HTML Element' && (typeId === 11 || typeId === 2 || typeId === 3 || typeId === 14 || typeId === 15 || typeId === 16 || typeId === 17 || typeId === 18 || typeId === -1)) {
5252
return (
5353
<DirectChildHTMLNestable
5454
childId={childId}

0 commit comments

Comments
 (0)