Skip to content

Commit 1285511

Browse files
authored
Merge pull request #27 from oslabs-beta/calvin
demo render fixes
2 parents 6084168 + b24ebd6 commit 1285511

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ const DemoRender = (): JSX.Element => {
4242
document.querySelectorAll('a').forEach(element => {
4343
element.addEventListener('click', (event) => {
4444
event.preventDefault();
45-
window.top.postMessage(event.target.href, '*');
46-
})
45+
window.top.postMessage(event.currentTarget.href, '*');
46+
//document.body.style.backgroundColor = 'orange';
47+
}, true)
4748
});
4849
} catch (err) {
4950
const app = document.querySelector('#app');
@@ -57,6 +58,7 @@ const DemoRender = (): JSX.Element => {
5758

5859
//Switch between components when clicking on a link in the live render
5960
window.onmessage = (event) => {
61+
if(event.data === undefined) return;
6062
const component = event.data?.split('/').at(-1);
6163
const componentId = component && state.components?.find((el) => {
6264
return el.name.toLowerCase() === component.toLowerCase();
@@ -70,7 +72,6 @@ const DemoRender = (): JSX.Element => {
7072
const componentBuilder = (array: object, key: number = 0) => {
7173
const componentsToRender = [];
7274
for (const element of array) {
73-
7475
if (element.name !== 'separator') {
7576
const elementType = element.name;
7677
const childId = element.childId;
@@ -79,13 +80,13 @@ const DemoRender = (): JSX.Element => {
7980
const classRender = element.attributes.cssClasses;
8081
const activeLink = element.attributes.compLink;
8182
let renderedChildren;
82-
if (elementType !== 'input' && elementType !== 'img' && element.children.length > 0) {
83+
if (elementType !== 'input' && elementType !== 'img' && elementType !== 'Image' && element.children.length > 0) {
8384
renderedChildren = componentBuilder(element.children);
8485
}
8586
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
8687
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
8788
else if (elementType === 'Image') componentsToRender.push(<Box component='img' src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
88-
else if (elementType === 'a' || elementType === 'Link') componentsToRender.push(<Box component='a' href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}</Box>);
89+
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>);
8990
else if (elementType === 'Switch') componentsToRender.push(<Switch>{renderedChildren}</Switch>);
9091
else if (elementType === 'Route') componentsToRender.push(<Route exact path={activeLink}>{renderedChildren}</Route>);
9192
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>
@@ -98,9 +99,10 @@ const DemoRender = (): JSX.Element => {
9899

99100
let code = '';
100101
const currComponent = state.components.find(element => element.id === state.canvasFocus.componentId);
102+
101103
componentBuilder(currComponent.children).forEach(element => {
102104
try{
103-
code += ReactDOMServer.renderToString(element)
105+
code += ReactDOMServer.renderToString(element);
104106
} catch {
105107
return;
106108
}

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ const reducer = (state: State, action: Action) => {
397397
const canvasFocus = { ...state.canvasFocus, componentId, childId };
398398
//makes it so the code preview will update when clicking on a new component
399399
const components = state.components.map(element => {
400+
console.log('element', element);
400401
return Object.assign({}, element);
401402
});
402403
return { ...state, components, canvasFocus };

server/controllers/cookieController.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const cookieController = {};
22

33
// setSSIDCookie - store the user id from database in cookie
44
cookieController.setSSIDCookie = (req, res, next) => {
5-
console.log('inside setSSIDCookie');
65
// set cookie with key 'ssid' and value to user's id
76
res.cookie('ssid', res.locals.id, {
87
httpOnly: true,

server/controllers/sessionController.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ sessionController.isLoggedIn = (req, res, next) => {
3333

3434
// startSession - create and save a new session into the database
3535
sessionController.startSession = (req, res, next) => {
36-
console.log('inside startSession');
3736
// first check if user is logged in already
3837
Sessions.findOne({ cookieId: res.locals.id }, (err, ses) => {
3938
if (err) {
@@ -70,7 +69,6 @@ sessionController.startSession = (req, res, next) => {
7069
};
7170

7271
sessionController.gitHubResponse = (req, res, next) => {
73-
console.log('inside gitHubResponse');
7472
const { code } = req.query;
7573
if (!code) {
7674
console.log('code not found');
@@ -97,7 +95,6 @@ sessionController.gitHubResponse = (req, res, next) => {
9795
)
9896
.then(res => res.json())
9997
.then(token => {
100-
console.log('token:', token);
10198
res.locals.token = token['access_token'];
10299
return next();
103100
})
@@ -107,7 +104,6 @@ sessionController.gitHubResponse = (req, res, next) => {
107104
};
108105

109106
sessionController.gitHubSendToken = (req, res, next) => {
110-
console.log('inside gitHubSendToken');
111107
const { token } = res.locals;
112108
fetch(`https://api.github.com/user/public_emails`, {
113109
method: 'GET',
@@ -143,7 +139,6 @@ sessionController.gitHubSendToken = (req, res, next) => {
143139

144140
// creates a session when logging in with github
145141
sessionController.githubSession = (req, res, next) => {
146-
console.log('inside gitHubSession');
147142
// req.user is passed in from passport js -> serializeuser/deserializeuser
148143
const cookieId = req.user._id;
149144
Sessions.findOne({ cookieId }, (err, session) => {

server/controllers/userController.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ const randomPassword = () => {
2626
};
2727

2828
userController.createUser = (req, res, next) => {
29-
console.log('inside createUser');
3029
let email, username, password;
3130
// use this condition for Oauth login
3231
if (res.locals.signUpType === 'oauth') {
33-
console.log('line 33 of create user')
3432
email = res.locals.githubEmail;
3533
username = email;
3634
password = randomPassword();
@@ -54,14 +52,12 @@ userController.createUser = (req, res, next) => {
5452
// handle error of creating a new user
5553
if (err) {
5654
if (res.locals.signUpType === 'oauth') {
57-
console.log('line 56 of userController'); // oauth enters this condition
5855
return next();
5956
}
6057
if (err.keyValue.email) {
6158
return res.status(400).json('Email Taken');
6259
}
6360
if (err.keyValue.username && res.locals.signUpType === 'oauth') {
64-
console.log('line 56 of userController');
6561
res.locals.githubPassword = password;
6662
return next();
6763
}
@@ -78,17 +74,14 @@ userController.createUser = (req, res, next) => {
7874
}
7975
// if no error found when creating a new user, send back user ID in res.locals
8076
res.locals.id = newUser.id;
81-
console.log('line 78 of userController');
8277
return next();
8378
});
8479
};
8580

8681
// verifyUser - Obtain username and password from the request body, locate
8782
// the appropriate user in the database, and then authenticate the submitted password against the password stored in the database.
8883
userController.verifyUser = (req, res, next) => {
89-
console.log('inside verifyUser');
9084
let { username, password, isFbOauth } = req.body;
91-
console.log(username, password, isFbOauth);
9285
// handle Oauth
9386
if (res.locals.signUpType === 'oauth') {
9487
username = res.locals.githubEmail;

0 commit comments

Comments
 (0)