Skip to content

Commit 00ea81e

Browse files
Merge pull request #8 from oslabs-beta/huyBranch
Finished documentation for launch
2 parents 2494646 + 9bc2c48 commit 00ea81e

File tree

9 files changed

+224
-82
lines changed

9 files changed

+224
-82
lines changed

CHANGE_LOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
<h1 align="center">ReacType Change Log</h1>
44
</p>
55

6+
**Version 12.0.0 Changes**
7+
8+
-Context Visualizer: You can now visually see what component is consuming which context. As you click on the interactive tree, the component assigned to the context will be revealed.
9+
-React 18: Updated to React 18
10+
-Export Feature: Created an exportable context file, integrated with original codebase.
11+
Ready to go code: Added boilerplate codes to components based on which contexts they are consuming.
12+
13+
**A note to future contributors**
14+
15+
Attempted to implement Facebook and Google OAuth via passport but as of Electron’s current version, neither of them not compatible with electron.
16+
617
**Version 11.0.0 Changes:**
718

819
- Added Next.js functionality

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ How to use
3030
- **Start a project (only after registration)**: Registered users can create a new project and select whether they want their project to be a Next.js, Gatsby.js, or classic React project. Also, registered users can save projects to return to them at a later time.
3131
- **Add Components**: Create components on the right panel. Components can be associated with a route, or they can be used within other components.
3232
- **Delete Components**: Delete components after focusing on them in the right panel. Be careful when deleting components: Upon deletion, all instances of the component will be removed within the application/project.
33+
- **Context Visualizer**: You can now visually see what component is consuming which context. As you click on the interactive tree, the component assigned to the context will be revealed.
34+
- **Context Code Preview**: Once contexts have been assigned to the desired components, click ‘Export’ to incorporate context into your existing codebase so you can save it as a file.
35+
- **Ready to go code**: Added boilerplate codes to components based on which contexts they are consuming.
3336
- **Add Custom Elements**: Create custom elements or add provided HTML elements into the application. Once the project is exported, the HTML tags generated in the code preview will function as expected. You can specify functionality for custom elements in the code preview. The tutorial on HTML Elements explains more on how to do this.
3437
- **Delete Custom HTML Elements**: Delete custom HTML elements by clicking on the ‘X’ button adjacent to the element. Be careful when deleting custom elements: All instances of the element will be deleted within the application/project.
3538
- **Create Instances on the Canvas**: Each component has its own canvas. Add an element to a component by dragging it onto the canvas. Div components are arbitrarily nestable and useful for complex layouts. Next.js and Gatsby.js projects have Link components to enable client-side navigation to other routes.
@@ -107,6 +110,8 @@ How to use
107110

108111
[Anthony Torrero](https://www.linkedin.com/in/anthony-torrero-4b8798159/) [@Anthonytorrero](https://github.com/Anthonytorrero)
109112

113+
[Bianca Picasso](linkedin.com/in/bianca-picasso) [@BiancaPicasso](https://github.com/BiancaPicasso)
114+
110115
[Brian Han](https://www.linkedin.com/in/brianjisoohan/) [@brianjshan](https://github.com/brianjshan)
111116

112117
[Bryan Chau](https://www.linkedin.com/in/chaubryan1/) [@bchauu](https://github.com/bchauu)
@@ -139,6 +144,8 @@ How to use
139144

140145
[Fredo Chen](https://www.linkedin.com/in/fredochen/) [@fredosauce](https://github.com/fredosauce)
141146

147+
[Huy Pham](linkedin.com/in/huypham048) [@huypham048](https://github.com/huypham048)
148+
142149
[Jonathan Calvo Ramirez](https://www.linkedin.com/in/jonathan-calvo/) [@jonocr](https://github.com/jonocr)
143150

144151
[Jesse Zuniga](https://linkedin.com/in/jesse-zuniga) [@jzuniga206](https://github.com/jzuniga206)
@@ -149,6 +156,8 @@ How to use
149156

150157
[Katrina Henderson](https://www.linkedin.com/in/katrinahenderson/) [@kchender](https://github.com/kchender)
151158

159+
[Ken Bains](linkedin.com/in/ken-bains) [@ken-Bains](https://github.com/ken-Bains)
160+
152161
[Kevin Park](https://www.linkedin.com/in/xkevinpark/) [@xkevinpark](https://github.com/xkevinpark)
153162

154163
[Khuong Nguyen](https://www.linkedin.com/in/khuong-nguyen/) [@khuongdn16](https://github.com/khuongdn16)
@@ -171,6 +180,8 @@ How to use
171180

172181
[Ron Fu](https://www.linkedin.com/in/ronfu)[@rfvisuals](https://github.com/rfvisuals)
173182

183+
[Salvatore Saluga](linkedin.com/in/salvatore-saluga) [@SalSaluga](https://github.com/SalSaluga)
184+
174185
[Sean Sadykoff](https://www.linkedin.com/in/sean-sadykoff/) [@sean1292](https://github.com/sean1292)
175186

176187
[Shana Hoehn](https://www.linkedin.com/in/shana-hoehn-70297b169/) [@slhoehn](https://github.com/slhoehn)

app/src/components/ContextAPIManager/AssignTab/AssignContainer.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ComponentTable from './components/ComponentTable';
99
import { Button } from '@mui/material';
1010
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
1111
import * as actions from '../../../redux/actions/actions';
12+
import StateContext from '../../../context/context';
1213

1314
const AssignContainer = () => {
1415
const store = useStore();
@@ -20,7 +21,9 @@ const AssignContainer = () => {
2021
const [contextInput, setContextInput] = React.useState(null);
2122
const [componentInput, setComponentInput] = React.useState(null);
2223
const [componentTable, setComponentTable] = useState([]);
24+
const [stateContext, dispatchContext] = useContext(StateContext);
2325

26+
//fetching data from redux store
2427
useEffect(() => {
2528
setState(store.getState().contextSlice);
2629
}, []);
@@ -32,7 +35,8 @@ const AssignContainer = () => {
3235
setTableState(targetContext.values);
3336
}
3437
};
35-
//checks if state is no longer an array, thus an object and will eventually render out the fetched
38+
39+
//construct data for table displaying component table
3640
const renderComponentTable = targetComponent => {
3741
//target Component is main
3842

@@ -47,18 +51,30 @@ const AssignContainer = () => {
4751
listOfContexts.push(context.name);
4852
}
4953
});
50-
console.log('setting component table with ', listOfContexts);
5154
setComponentTable(listOfContexts);
5255
}
5356
};
5457

58+
//handling assignment of contexts to components
5559
const handleAssignment = () => {
60+
if (
61+
contextInput === '' ||
62+
contextInput === null ||
63+
componentInput === '' ||
64+
componentInput === null
65+
)
66+
return;
5667
dispatch(
5768
actions.addComponentToContext({
5869
context: contextInput,
5970
component: componentInput
6071
})
6172
);
73+
//trigger generateCode(), update code preview tab
74+
dispatchContext({
75+
type: 'DELETE ELEMENT',
76+
payload: 'FAKE_ID'
77+
});
6278

6379
setState(store.getState().contextSlice);
6480
renderComponentTable(componentInput);

app/src/components/ContextAPIManager/CreateTab/CreateContainer.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useState, useContext } from 'react';
22
import { useStore } from 'react-redux';
33
import { useDispatch } from 'react-redux';
44
import Divider from '@mui/material/Divider';
@@ -8,44 +8,57 @@ import AddDataForm from './components/AddDataForm';
88
import AddContextForm from './components/AddContextForm';
99
import * as actions from '../../../redux/actions/actions';
1010
import { Typography } from '@mui/material';
11+
import StateContext from '../../../context/context';
1112

1213
const CreateContainer = () => {
1314
const defaultTableData = [{ key: 'Enter Key', value: 'Enter value' }];
1415
const store = useStore();
1516
const [state, setState] = useState([]);
1617
const [tableState, setTableState] = React.useState(defaultTableData);
1718
const [contextInput, setContextInput] = React.useState(null);
19+
const [stateContext, dispatchContext] = useContext(StateContext);
1820

21+
//pulling data from redux store
1922
useEffect(() => {
2023
setState(store.getState().contextSlice);
2124
}, []);
2225

2326
const dispatch = useDispatch();
2427

28+
//update data store when user adds a new context
2529
const handleClickSelectContext = () => {
2630
//prevent user from adding duplicate context
2731
for (let i = 0; i < state.allContext.length; i += 1) {
2832
if (state.allContext[i].name === contextInput.name) {
2933
return;
3034
}
3135
}
36+
setContextInput('');
3237
dispatch(actions.addContextActionCreator(contextInput));
3338
setState(store.getState().contextSlice);
3439
};
3540

41+
//update data store when user add new key-value pair to context
3642
const handleClickInputData = ({ name }, { inputKey, inputValue }) => {
3743
dispatch(
3844
actions.addContextValuesActionCreator({ name, inputKey, inputValue })
3945
);
4046
setState(store.getState().contextSlice);
4147
};
4248

49+
//update data store when user deletes context
4350
const handleDeleteContextClick = () => {
4451
dispatch(actions.deleteContext(contextInput));
4552
setContextInput('');
4653
setState(store.getState().contextSlice);
54+
setTableState(defaultTableData);
55+
dispatchContext({
56+
type: 'DELETE ELEMENT',
57+
payload: 'FAKE_ID'
58+
});
4759
};
4860

61+
//re-render data table when there's new changes
4962
const renderTable = targetContext => {
5063
if (
5164
targetContext === null ||

app/src/components/ContextAPIManager/DisplayTab/DisplayContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const DisplayContainer = () => {
88
const { allContext } = store.getState().contextSlice;
99
const [contextData, setContextData] = useState([]);
1010

11+
//build data for Google charts, tree rendering
1112
useEffect(() => {
1213
transformData(allContext);
1314
}, []);

app/src/components/main/DemoRender.tsx

Lines changed: 103 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect, useRef, useContext } from 'react';
2-
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
2+
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
33
import Box from '@material-ui/core/Box';
44
import cssRefresher from '../../helperFunctions/cssRefresh';
55
import { useSelector } from 'react-redux';
@@ -17,12 +17,12 @@ const DemoRender = (): JSX.Element => {
1717
(elem: Component) => elem.id === state.canvasFocus.componentId
1818
);
1919

20-
// Create React ref to inject transpiled code in inframe
20+
// Create React ref to inject transpiled code in inframe
2121
const iframe = useRef<any>();
2222
const demoContainerStyle = {
2323
width: '100%',
2424
backgroundColor: '#FBFBFB',
25-
border: '2px Solid grey',
25+
border: '2px Solid grey'
2626
};
2727

2828
const html = `
@@ -55,14 +55,19 @@ const DemoRender = (): JSX.Element => {
5555
`;
5656

5757
//Switch between components when clicking on a link in the live render
58-
window.onmessage = (event) => {
59-
if(event.data === undefined) return;
60-
const component:string = event.data?.split('/').at(-1);
61-
const componentId = component && state.components?.find((el) => {
62-
return el.name.toLowerCase() === component.toLowerCase();
63-
}).id;
64-
componentId && dispatch({ type: 'CHANGE FOCUS', payload: {componentId, childId: null}})
65-
58+
window.onmessage = event => {
59+
if (event.data === undefined) return;
60+
const component: string = event.data?.split('/').at(-1);
61+
const componentId =
62+
component &&
63+
state.components?.find(el => {
64+
return el.name.toLowerCase() === component.toLowerCase();
65+
}).id;
66+
componentId &&
67+
dispatch({
68+
type: 'CHANGE FOCUS',
69+
payload: { componentId, childId: null }
70+
});
6671
};
6772

6873
// This function is the heart of DemoRender it will take the array of components stored in state and dynamically construct the desired React component for the live demo
@@ -78,28 +83,94 @@ const DemoRender = (): JSX.Element => {
7883
const classRender = element.attributes.cssClasses;
7984
const activeLink = element.attributes.compLink;
8085
let renderedChildren;
81-
if (elementType !== 'input' && elementType !== 'img' && elementType !== 'Image' && element.children.length > 0) {
86+
if (
87+
elementType !== 'input' &&
88+
elementType !== 'img' &&
89+
elementType !== 'Image' &&
90+
element.children.length > 0
91+
) {
8292
renderedChildren = componentBuilder(element.children);
8393
}
84-
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
85-
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
86-
else if (elementType === 'Image') componentsToRender.push(<Box component='img' src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
87-
else if (elementType === 'a' || elementType === 'Link') componentsToRender.push(<Box component='a' href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>);
88-
else if (elementType === 'Switch') componentsToRender.push(<Switch>{renderedChildren}</Switch>);
89-
else if (elementType === 'Route') componentsToRender.push(<Route exact path={activeLink}>{renderedChildren}</Route>);
90-
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>
91-
);
94+
if (elementType === 'input')
95+
componentsToRender.push(
96+
<Box
97+
component={elementType}
98+
className={classRender}
99+
style={elementStyle}
100+
key={key}
101+
id={`rend${childId}`}
102+
></Box>
103+
);
104+
else if (elementType === 'img')
105+
componentsToRender.push(
106+
<Box
107+
component={elementType}
108+
src={activeLink}
109+
className={classRender}
110+
style={elementStyle}
111+
key={key}
112+
id={`rend${childId}`}
113+
></Box>
114+
);
115+
else if (elementType === 'Image')
116+
componentsToRender.push(
117+
<Box
118+
component="img"
119+
src={activeLink}
120+
className={classRender}
121+
style={elementStyle}
122+
key={key}
123+
id={`rend${childId}`}
124+
></Box>
125+
);
126+
else if (elementType === 'a' || elementType === 'Link')
127+
componentsToRender.push(
128+
<Box
129+
component="a"
130+
href={activeLink}
131+
className={classRender}
132+
style={elementStyle}
133+
key={key}
134+
id={`rend${childId}`}
135+
>
136+
{innerText}
137+
{renderedChildren}
138+
</Box>
139+
);
140+
else if (elementType === 'Switch')
141+
componentsToRender.push(<Switch>{renderedChildren}</Switch>);
142+
else if (elementType === 'Route')
143+
componentsToRender.push(
144+
<Route exact path={activeLink}>
145+
{renderedChildren}
146+
</Route>
147+
);
148+
else
149+
componentsToRender.push(
150+
<Box
151+
component={elementType}
152+
className={classRender}
153+
style={elementStyle}
154+
key={key}
155+
id={`rend${childId}`}
156+
>
157+
{innerText}
158+
{renderedChildren}
159+
</Box>
160+
);
92161
key += 1;
93162
}
94163
}
95164
return componentsToRender;
96165
};
97166

98167
let code = '';
99-
const currComponent = state.components.find(element => element.id === state.canvasFocus.componentId);
168+
const currComponent = state.components.find(
169+
element => element.id === state.canvasFocus.componentId
170+
);
100171

101172
componentBuilder(currComponent.children).forEach(element => {
102-
try{
173+
try {
103174
code += ReactDOMServer.renderToString(element);
104175
} catch {
105176
return;
@@ -108,17 +179,23 @@ const DemoRender = (): JSX.Element => {
108179

109180
useEffect(() => {
110181
cssRefresher();
111-
}, [])
182+
}, []);
112183

113184
useEffect(() => {
114185
iframe.current.contentWindow.postMessage(code, '*');
115-
}, [code])
186+
}, [code]);
116187

117188
return (
118189
<div id={'renderFocus'} style={demoContainerStyle}>
119-
<iframe ref={iframe} sandbox='allow-scripts' srcDoc={html} width='100%' height='100%' />
190+
<iframe
191+
ref={iframe}
192+
sandbox="allow-scripts"
193+
srcDoc={html}
194+
width="100%"
195+
height="100%"
196+
/>
120197
</div>
121198
);
122199
};
123200

124-
export default DemoRender;
201+
export default DemoRender;

0 commit comments

Comments
 (0)