diff --git a/src/actions/index.js b/src/actions/index.js
index 149cf440..0e01716f 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -3,4 +3,5 @@ export { default as EditorActions } from './editorActions';
export { default as ProjectActions } from './projectActions';
export { default as SceneActions } from './sceneActions';
export { default as CourseActions } from './courseActions';
-export { default as ClassroomActions } from './classroomActions';
\ No newline at end of file
+export { default as ClassroomActions } from './classroomActions';
+export { default as ReferenceExampleActions } from './referenceExampleActions';
\ No newline at end of file
diff --git a/src/actions/referenceExampleActions.js b/src/actions/referenceExampleActions.js
new file mode 100644
index 00000000..7e917040
--- /dev/null
+++ b/src/actions/referenceExampleActions.js
@@ -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
+};
\ No newline at end of file
diff --git a/src/components/CourseSelect.js b/src/components/CourseSelect.js
index d547b1f2..0e2e77b2 100644
--- a/src/components/CourseSelect.js
+++ b/src/components/CourseSelect.js
@@ -6,7 +6,8 @@ import {
CardContent,
IconButton,
Icon,
- Modal
+ Modal,
+ Tooltip
} from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
@@ -122,6 +123,7 @@ class CourseSelectModal extends Component {
const courses = [].concat(this.props.courses);
return (
+
school
+
{
@@ -305,6 +309,7 @@ class Header extends Component {
handleRender = () => {
try {
let editor = window.ace.edit("ace-editor");
+ this.props.actions.refresh(editor.getSession().getValue());
this.props.actions.render(editor.getSession().getValue(), this.props.user ? this.props.user.uid : 'anon');
} catch (error) {
this.props.actions.render(this.props.text, this.props.user ? this.props.user.uid : 'anon');
@@ -343,8 +348,17 @@ class Header extends Component {
* @summary - When the user clicks save it will upload the information to Firebase
*/
handleSave = () => {
- let editor = window.ace.edit("ace-editor");
- let text = editor.getSession().getValue();
+ let editor, text;
+ if(!this.props.viewOnly) {
+ //If in editor mode, gets text directly from editor
+ editor = window.ace.edit("ace-editor");
+ text = editor.getSession().getValue();
+ this.props.actions.refresh(text, this.props.user ? this.props.user.uid : 'anon');
+ } else {
+ //Otherwise, gets text from state (should be up to date since it is refreshed on editor unmount)
+ text = this.props.text;
+ }
+
if (this.props.user && this.props.user.uid && text) {
this.setState({ spinnerOpen: true });
let ts = Date.now();
@@ -354,6 +368,7 @@ class Header extends Component {
let img = scene.components.screenshot.getCanvas('perspective').toDataURL('image/jpeg', 0.1);
let path = "images/perspective/" + projectId;
let imgRef = storageRef.child(path);
+
imgRef.putString(img, 'data_url').then((snapshot) => {
// Put the new document into the scenes collection
scenes.doc(projectId).set({
@@ -367,7 +382,7 @@ class Header extends Component {
// If we have a new projectId reload page with it
if (this.props.courseName) {
this.setState({ spinnerOpen: false });
- window.open(window.origin + '/' + projectId);
+ //window.open(window.origin + '/' + projectId);
} else if (projectId !== this.props.projectId) {
window.location.href = window.origin + '/' + projectId;
} else {
@@ -454,6 +469,10 @@ class Header extends Component {
this.setState({ classroomOpen: false });
};
+ handleReferenceToggle = () => {
+ this.setState({ referenceOpen: !this.state.referenceOpen });
+ };
+
loadDrawer = () => {
return (
@@ -653,11 +674,17 @@ class Header extends Component {
+ changeView={this.props.sceneActions.changeView}
+ layoutType={this.props.layoutType}
+ referenceOpen={this.state.referenceOpen}
+ handleReferenceToggle={this.handleReferenceToggle}/>
{/*
*/}
-
+
- {
- this.setState({ viewOnlyOnOpen: this.props.viewOnly });
- if(this.props.viewOnly) {
- this.props.changeView();
- }
- }}
- onRequestClose={this.closeTour} />
-