diff --git a/src/actions/arduinoActions.js b/src/actions/arduinoActions.js
new file mode 100644
index 0000000..c0936b8
--- /dev/null
+++ b/src/actions/arduinoActions.js
@@ -0,0 +1,150 @@
+import { GET_ARDUINO_EXAMPLES } from './types';
+
+import axios from 'axios';
+import { returnErrors, returnSuccess } from './messageActions';
+
+
+export const getArduinoExamples = () => (dispatch) => {
+ const config = {
+ success: res => {
+ var examples = res.data.arduinoExamples;
+ console.log(examples);
+ dispatch({
+ type: GET_ARDUINO_EXAMPLES,
+ payload: examples
+ });
+ dispatch(returnSuccess(res.data.message, res.status));
+ },
+ error: err => {
+ if (err.response) {
+ dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_PROJECTS_FAIL'));
+ }
+ }
+ };
+ axios.get(`${process.env.REACT_APP_BLOCKLY_API}/arduino`, config)
+ .then(res => {
+ res.config.success(res);
+ })
+ .catch(err => {
+ err.config.error(err);
+ });
+};
+
+// export const updateProject = (type, id) => (dispatch, getState) => {
+// var workspace = getState().workspace;
+// var body = {
+// xml: workspace.code.xml,
+// title: workspace.name,
+// board: getState().board.board,
+// };
+// var project = getState().project;
+// if (type === 'gallery') {
+// body.description = project.description;
+// }
+// const config = {
+// success: res => {
+// var project = res.data[type];
+// var projects = getState().project.projects;
+// var index = projects.findIndex(res => res._id === project._id);
+// projects[index] = project;
+// dispatch({
+// type: GET_PROJECTS,
+// payload: projects
+// });
+// if (type === 'project') {
+// dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS'));
+// } else {
+// dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_UPDATE_SUCCESS'));
+// }
+// },
+// error: err => {
+// if (err.response) {
+// if (type === 'project') {
+// dispatch(returnErrors(err.response.data.message, err.response.status, 'PROJECT_UPDATE_FAIL'));
+// } else {
+// dispatch(returnErrors(err.response.data.message, err.response.status, 'GALLERY_UPDATE_FAIL'));
+// }
+// }
+// }
+// };
+// axios.put(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`, body, config)
+// .then(res => {
+// res.config.success(res);
+// })
+// .catch(err => {
+// err.config.error(err);
+// });
+// };
+
+// export const deleteProject = (type, id) => (dispatch, getState) => {
+// const config = {
+// success: res => {
+// var projects = getState().project.projects;
+// var index = projects.findIndex(res => res._id === id);
+// projects.splice(index, 1)
+// dispatch({
+// type: GET_PROJECTS,
+// payload: projects
+// });
+// if (type === 'project') {
+// dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_DELETE_SUCCESS'));
+// } else {
+// dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_DELETE_SUCCESS'));
+// }
+// },
+// error: err => {
+// dispatch(returnErrors(err.response.data.message, err.response.status, 'PROJECT_DELETE_FAIL'));
+// }
+// };
+// axios.delete(`${process.env.REACT_APP_BLOCKLY_API}/${type}/${id}`, config)
+// .then(res => {
+// res.config.success(res);
+// })
+// .catch(err => {
+// if (err.response && err.response.status !== 401) {
+// err.config.error(err);
+// }
+// });
+// };
+
+
+// export const shareProject = (title, type, id) => (dispatch, getState) => {
+// var body = {
+// title: title,
+// board: getState().board.board
+// };
+// if (type === 'project') {
+// body.projectId = id;
+// } else {
+// body.xml = getState().workspace.code.xml;
+// }
+// axios.post(`${process.env.REACT_APP_BLOCKLY_API}/share`, body)
+// .then(res => {
+// var shareContent = res.data.content;
+// if (body.projectId) {
+// var projects = getState().project.projects;
+// var index = projects.findIndex(res => res._id === id);
+// projects[index].shared = shareContent.expiresAt;
+// dispatch({
+// type: GET_PROJECTS,
+// payload: projects
+// });
+// }
+// dispatch(returnSuccess(res.data.message, shareContent._id, 'SHARE_SUCCESS'));
+// })
+// .catch(err => {
+// if (err.response) {
+// dispatch(returnErrors(err.response.data.message, err.response.status, 'SHARE_FAIL'));
+// }
+// });
+// };
+
+
+// export const resetProject = () => (dispatch) => {
+// dispatch({
+// type: GET_PROJECTS,
+// payload: []
+// });
+// dispatch(setType(''));
+// dispatch(setDescription(''));
+// };
diff --git a/src/actions/boardAction.js b/src/actions/boardActions.js
similarity index 100%
rename from src/actions/boardAction.js
rename to src/actions/boardActions.js
diff --git a/src/actions/projectActions.js b/src/actions/projectActions.js
index 0cd8f0e..54c7789 100644
--- a/src/actions/projectActions.js
+++ b/src/actions/projectActions.js
@@ -90,7 +90,8 @@ export const updateProject = (type, id) => (dispatch, getState) => {
var workspace = getState().workspace;
var body = {
xml: workspace.code.xml,
- title: workspace.name
+ title: workspace.name,
+ board: getState().board.board,
};
var project = getState().project;
if (type === 'gallery') {
@@ -165,7 +166,8 @@ export const deleteProject = (type, id) => (dispatch, getState) => {
export const shareProject = (title, type, id) => (dispatch, getState) => {
var body = {
- title: title
+ title: title,
+ board: getState().board.board
};
if (type === 'project') {
body.projectId = id;
diff --git a/src/actions/types.js b/src/actions/types.js
index c67ad2a..62936e7 100644
--- a/src/actions/types.js
+++ b/src/actions/types.js
@@ -64,5 +64,7 @@ export const GET_PROJECTS = "GET_PROJECTS";
export const PROJECT_TYPE = "PROJECT_TYPE";
export const PROJECT_DESCRIPTION = "PROJECT_DESCRIPTION";
+export const GET_ARDUINO_EXAMPLES = "GET_ARDUINO_EXAMPLES";
+
//board
export const BOARD = "BOARD";
diff --git a/src/components/CodeEditor/Sidebar.js b/src/components/CodeEditor/Sidebar.js
index 5e2b976..25a21c9 100644
--- a/src/components/CodeEditor/Sidebar.js
+++ b/src/components/CodeEditor/Sidebar.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { useEffect } from "react";
import Blockly from "blockly";
import { useSelector } from "react-redux";
import Accordion from "@material-ui/core/Accordion";
@@ -10,17 +10,20 @@ import { useMonaco } from "@monaco-editor/react";
import { Button } from "@material-ui/core";
import SerialMonitor from "./SerialMonitor.js";
import axios from "axios";
+import { useDispatch } from "react-redux";
+import { getArduinoExamples } from "../../actions/arduinoActions";
+//import getArduinoExamples from "../../reducers/arduinoReducer"
const Sidebar = () => {
- //const [examples, setExamples] = React.useState([]);
+
+
+ const examples = useSelector((state) => state.arduino.examples);
const user = useSelector((state) => state.auth.user);
- // useEffect(() => {
- // axios
- // .get("https://coelho.opensensemap.org/items/blocklysamples")
- // .then((res) => {
- // setExamples(res.data.data);
- // });
- // }, []);
+ const dispatch = useDispatch()
+
+ useEffect(() => {
+ dispatch(getArduinoExamples());
+ }, [dispatch]);
const monaco = useMonaco();
const loadCode = (code) => {
monaco.editor.getModels()[0].setValue(code);
@@ -52,7 +55,7 @@ const Sidebar = () => {
) : null}
- {/*
+
{
key={i}
onClick={() => loadCode(object.code)}
>
- {object.name}
+ {object.title}
);
})}
- */}
+
{user ? (
({
link: {
diff --git a/src/components/Home.js b/src/components/Home.js
index 13a4661..357d306 100644
--- a/src/components/Home.js
+++ b/src/components/Home.js
@@ -2,10 +2,10 @@ import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { clearStats, workspaceName } from "../actions/workspaceActions";
-
+import { setBoard } from "../actions/boardActions";
import * as Blockly from "blockly/core";
import { createNameId } from "mnemonic-id";
-
+import * as BoardHelper from "./Blockly/helpers/board";
import WorkspaceStats from "./Workspace/WorkspaceStats";
import WorkspaceFunc from "./Workspace/WorkspaceFunc";
import BlocklyWindow from "./Blockly/BlocklyWindow";
@@ -66,6 +66,10 @@ class Home extends Component {
this.setState({ stats: window.localStorage.getItem("stats") });
if (!this.props.project) {
this.props.workspaceName(createNameId());
+ } else {
+ console.log(this.props.project);
+ this.props.setBoard(this.props.project.board);
+ BoardHelper.setBoard(this.props.project.board);
}
if (this.props.message && this.props.message.id === "GET_SHARE_FAIL") {
this.setState({
@@ -187,7 +191,8 @@ class Home extends Component {
) : null}
-
+ {!this.props.board ? : null}
+ {/* */}
{/* */}
{this.props.platform ? (