Skip to content

Commit

Permalink
Setup basic page routing
Browse files Browse the repository at this point in the history
  • Loading branch information
rennemannd committed May 5, 2020
1 parent 98247f9 commit a0b6876
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 380 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
### `/`

- #### `client/`
[Client](/client/#client) is the frontend of the applcation. It is powered by [React](https://reactjs.org/) and [Blockly](https://developers.google.com/blockly).
[Client](/client/#client) is the frontend of the application. It is powered by [React](https://reactjs.org/) and [Blockly](https://developers.google.com/blockly).

- #### `cms/`

[Cms](/cms#cms) is the REST API and admin portal that powers the backend. It is powered by [Node](https://nodejs.org/en/) and [Strapi]().

- #### `compile/`

[Compile](/compile/#compile) is an arduino compilier service. It is an unofficial fork of [Chromeduino](https://github.com/spaceneedle/Chromeduino).
[Compile](/compile/#compile) is an arduino compiler service. It is an unofficial fork of [Chromeduino](https://github.com/spaceneedle/Chromeduino).

<br/>

Expand All @@ -25,7 +25,7 @@
This project's dependencies are managed through [yarn](https://classic.yarnpkg.com/en/docs/install/#mac-stable)
The following are the available scripts we can use with the client and server:

The development environment is comprised of three services managed by docker compose.
The development environment is comprised of four servers managed by docker compose.

* `sc-client-dev` => localhost:3000
* `sc-cms-dev` => localhost:1337
Expand Down Expand Up @@ -57,7 +57,7 @@ Ideally, we want our flow to resemble this. Master and develop are locked for di
- `master` - Deployed version of the application
- `develop` - Working version of the application
- `feature/<scaffold>-<feature-name>` - Based off of develop
- ex. `feature/server-strapi`
- ex. `feature/cms-strapi`
- `hotfix/<scaffold>-<fix-name>` - Based off of master
- ex. hotfix/client-cors

Expand Down
2 changes: 1 addition & 1 deletion client/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ ! -d "node_modules" ]; then
yarn install
fi

echo "Starting the client developement server"
echo "Starting the client development server"

# Run the rest of the commands
exec "$@"
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"cross-env": "^7.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1"
},
"scripts": {
Expand Down
174 changes: 17 additions & 157 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,164 +1,24 @@
import React, {useState, useEffect, useRef} from "react";
import AvrgirlArduino from './avrgirl-arduino';
import "./App.css";
import React, {useState} from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import Workspace from "./views/Workspace"
import Home from "./views/Home"
import NotFound from "./views/NotFound"

import {cms, compile} from './config/development.json'
const App = () => {
const [selectedActivity, setSelectedActivity] = useState();

function App() {
let workspace;

// If current workspace ref is not set on initial load, set it
useEffect(() => {
workspace = window.Blockly.inject('blockly-canvas', {toolbox: document.getElementById('toolbox')});
},[]);

// Generates javascript code from blockly canvas
const getJS = () => {
window.Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
let code = window.Blockly.JavaScript.workspaceToCode(workspace);
alert(code)
return(code);
};

// Generates Arduino code from blockly canvas
const getArduino = () => {
window.Blockly.Arduino.INFINITE_LOOP_TRAP = null;
let code = window.Blockly.Arduino.workspaceToCode(workspace);
alert(code);
return(code);
};

// Sends compiled arduino code to server and returns hex to flash board with
const compileArduinoCode = async() => {
let body = {
"board": "arduino:avr:uno",
"sketch": getArduino()
};

// gets compiled hex from server
let Hex;
window.$.post(`${compile}/compile`, body, (data) => {
// converting base 64 to hex
Hex = atob(data.hex).toString();

const avrgirl = new AvrgirlArduino({
board: "",
debug: true
});

// TODO: Remove hardcoded file path
avrgirl.flash(Hex, (err) => {
if (err) {
console.log(err);
} else {
console.log('done correctly.');
}
})

});
};

return (
return(
<div>
<div id="container" className="flex flex-column">
<div id="nav-container" className="flex vertical-container space-between">
<h1 id="title">STEM+C</h1>
<div id="action-btn-container" className="flex space-between">
<i onClick={getJS} className={"fab fa-js hvr-grow"}/>
<i onClick={getArduino} className="hvr-grow">A</i>
<i onClick={compileArduinoCode} className="fas fa-play hvr-grow"/>
</div>
</div>
<div id="top-container" className="flex flex-column vertical-container">
<div id="description-container" className="flex flex-column card">
<h3>Maker Activity X</h3>
<p><b>Instructions / Science Brief: </b>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<div id="bottom-container" className="flex vertical-container">
<div id="blockly-canvas" style={{"height": "800px", "width": "100%"}}/>
<div id="models-container" className="flex flex-column card space-between">
<h3>Activity Models</h3>
<img src="assets/arduino.png" id="model-img"/>
<div id="model-btn-container" className="flex space-between">
<span>
<input type="radio" value="arduino" name="model-btn" />
<label htmlFor="btn-arduino">Arduino</label>
</span>
<span>
<input type="radio" value="maker" name="model-btn"/>
<label htmlFor="btn-maker">Maker</label>
</span>
<span>
<input type="radio" value="science" name="model-btn"/>
<label htmlFor="btn-science">Science</label>
</span>
</div>
</div>
</div>
<Switch>
<Route exact path={"/Home"} render={(props) => <Home selectedActivity={selectedActivity} setSelectedActivity={setSelectedActivity} /> } />
<Route exact path ="/" >
<Redirect to={"/Home"} />
</Route>
<Route path={"/Home/:projectId"} component = { Workspace } />
<Route component={NotFound} />
</Switch>
</div>

{/* This xml is for the blocks' menu we will provide. Here are examples on how to include categories and subcategories */}
<xml id="toolbox" style={{"display": "none"}}>
<category name="Conditionals">
<category name="Operations">
<block type="controls_if"/>
<block type="logic_compare"/>
<block type="controls_whileUntil"/>
</category>
</category>
<category name="Input and Output">
<category name="Numeric">
<block type="math_number"/>
<block type="math_arithmetic"/>
</category>
<category name="Text">
<block type="text"/>
<block type="text_print"/>
</category>
<category name="Your Variables" custom="VARIABLE"/>
</category>
Here I input Ardublockly category and blocks. Check: ardublockly_toolbox.js
<category id="catInputOutput" name="Input/Output">
<block type="io_digitalwrite">
<value name="STATE">
<block type="io_highlow"/>
</value>
</block>
<block type="io_digitalread"/>
<block type="io_builtin_led">
<value name="STATE">
<block type="io_highlow"/>
</value>
</block>
<block type="io_analogwrite"/>
<block type="io_analogread"/>
<block type="io_highlow"/>
<block type="io_pulsein">
<value name="PULSETYPE">
<shadow type="io_highlow"/>
</value>
</block>
<block type="io_pulsetimeout">
<value name="PULSETYPE">
<shadow type="io_highlow"/>
</value>
<value name="TIMEOUT">
<shadow type="math_number">
<field name="NUM">100</field>
</shadow>
</value>
</block>
</category>
</xml>
</div>
);

)
}

export default App;
9 changes: 0 additions & 9 deletions client/src/App.test.js

This file was deleted.

File renamed without changes.
5 changes: 3 additions & 2 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { BrowserRouter as Router} from 'react-router-dom'
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<React.StrictMode>
<Router>
<App />
</React.StrictMode>,
</Router>,
document.getElementById('root')
);

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions client/src/views/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React , {useState, useEffect} from "react";
import {Link} from "react-router-dom";

function Home(props) {
return <div>Home</div>
}

export default Home;
5 changes: 5 additions & 0 deletions client/src/views/NotFound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const NotFound = () => {
return "Page Not Found"
}

export default NotFound;
Loading

0 comments on commit a0b6876

Please sign in to comment.