-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from engaging-computing/dev
Added Reference Examples and UI improvements
- Loading branch information
Showing
25 changed files
with
698 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render } from './editorActions'; | ||
|
||
import * as types from '../constants/ActionTypes'; | ||
|
||
const refExRef = '/apiv1/referenceExamples/'; | ||
const header = { headers: { 'content-type': 'application/json' } }; | ||
const problem = { | ||
name: "Error", | ||
type: "Unknown", | ||
info: "An unknown error occured. Please try refreshing the page", | ||
suggestedCourse: null, | ||
code: "" | ||
}; | ||
|
||
//Lesson Actions | ||
export function fetchReferenceExample(funcName) { | ||
return (dispatch) => { | ||
fetch(refExRef + funcName, header) | ||
.then(response => { | ||
response.json() | ||
.then(json => { | ||
dispatch(loadReferenceExample(json)); | ||
dispatch(render(json.code || "")); | ||
}) | ||
.catch(err => { | ||
dispatch(loadReferenceExample(problem)); | ||
console.error(err); | ||
}); | ||
}) | ||
.catch(err => { | ||
dispatch(loadReferenceExample(problem)); | ||
console.error(err); | ||
}); | ||
}; | ||
} | ||
|
||
export function loadReferenceExample(refEx) { | ||
return { | ||
type: types.LOAD_REF_EX, | ||
payload: refEx | ||
}; | ||
} | ||
|
||
export default { | ||
loadReferenceExample, | ||
fetchReferenceExample | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { Component } from 'react'; | ||
import { | ||
Button, | ||
Icon | ||
} from '@material-ui/core'; | ||
|
||
class ReferenceExampleBox extends Component { | ||
|
||
suggestedCourse = () => { | ||
const { suggestedCourse, suggestedCourseName } = this.props.referenceExample; | ||
return ( | ||
this.props.referenceExample && suggestedCourseName ? | ||
<Button | ||
variant="raised" | ||
onClick={() => window.location.href = window.origin + '/course/' + suggestedCourse} | ||
color="primary" | ||
className="ref-ex-btn"> | ||
<Icon className="material-icons">school</Icon> | ||
<div id="suggested-course"> | ||
Suggested Course: {suggestedCourseName} | ||
</div> | ||
</Button> | ||
: null | ||
); | ||
} | ||
|
||
renderParams = (functionParams) => { | ||
let returnString = "("; | ||
for (let i = 0; i < functionParams.length; i++) { | ||
returnString += functionParams[i]; | ||
if (i !== functionParams.length - 1) { returnString += ", "; } | ||
} | ||
return returnString += ")"; | ||
// return returnString; | ||
} | ||
|
||
renderTitle = () => { | ||
const { functionName, functionParams } = this.props.referenceExample; | ||
return ( | ||
<h3>{(this.props.referenceExample && functionName) ? | ||
("Function: " + functionName + this.renderParams(functionParams)) | ||
: "Loading..."} | ||
</h3> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id="ref-ex"> | ||
<this.renderTitle /> | ||
<h6>{(this.props.referenceExample && this.props.referenceExample.type) ? "Type: " + this.props.referenceExample.type : "Loading..."}</h6> | ||
<p>{(this.props.referenceExample && this.props.referenceExample.info) ? this.props.referenceExample.info : "Loading..."} </p> | ||
<this.suggestedCourse /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
export default ReferenceExampleBox; |
Oops, something went wrong.