make start and stop buttons work

This commit is contained in:
catarak 2016-05-12 17:40:49 -04:00
parent 62c4e2244b
commit 8b04d04bb3
6 changed files with 35 additions and 4 deletions

View file

@ -34,6 +34,7 @@
}, },
"dependencies": { "dependencies": {
"babel-core": "^6.8.0", "babel-core": "^6.8.0",
"classnames": "^2.2.5",
"codemirror": "^5.14.2", "codemirror": "^5.14.2",
"express": "^4.13.4", "express": "^4.13.4",
"react": "^15.0.2", "react": "^15.0.2",

View file

@ -4,17 +4,23 @@ var Isvg = require('react-inlinesvg');
var playUrl = require('../../../images/play.svg'); var playUrl = require('../../../images/play.svg');
var logoUrl = require('../../../images/p5js-logo.svg'); var logoUrl = require('../../../images/p5js-logo.svg');
var stopUrl = require('../../../images/stop.svg'); var stopUrl = require('../../../images/stop.svg');
var classNames = require('classnames');
class Toolbar extends React.Component { class Toolbar extends React.Component {
render() { render() {
let playButtonClass = classNames({
"toolbar__play-button": true,
"playing": this.props.isPlaying
});
return ( return (
<div className="toolbar"> <div className="toolbar">
<img className="toolbar__logo" src={logoUrl}/> <img className="toolbar__logo" src={logoUrl}/>
<div className="toolbar__play-button" onClick={this.props.toggleSketch}> <div className={playButtonClass} onClick={this.props.startSketch}>
<Isvg src={playUrl} alt="Play Sketch" /> <Isvg src={playUrl} alt="Play Sketch" />
</div> </div>
{ this.props.isPlaying ? { this.props.isPlaying ?
<div className="toolbar__stop-button"> <div className="toolbar__stop-button" onClick={this.props.stopSketch}>
<Isvg src={stopUrl} alt="Stop Sketch" /> <Isvg src={stopUrl} alt="Stop Sketch" />
</div> </div>
: null } : null }

View file

@ -14,7 +14,8 @@ class App extends React.Component {
<Toolbar <Toolbar
className="toolbar" className="toolbar"
isPlaying={this.props.ide.isPlaying} isPlaying={this.props.ide.isPlaying}
toggleSketch={this.props.toggleSketch} /> startSketch={this.props.startSketch}
stopSketch={this.props.stopSketch}/>
<Editor <Editor
content={this.props.file.content} content={this.props.file.content}
updateFile={this.props.updateFile} /> updateFile={this.props.updateFile} />

View file

@ -12,4 +12,16 @@ export function toggleSketch() {
return { return {
type: ActionTypes.TOGGLE_SKETCH type: ActionTypes.TOGGLE_SKETCH
} }
}
export function startSketch() {
return {
type: ActionTypes.START_SKETCH
}
}
export function stopSketch() {
return {
type: ActionTypes.STOP_SKETCH
}
} }

View file

@ -1,2 +1,5 @@
export const CHANGE_SELECTED_FILE = 'CHANGE_SELECTED_FILE'; export const CHANGE_SELECTED_FILE = 'CHANGE_SELECTED_FILE';
export const TOGGLE_SKETCH = 'TOGGLE_SKETCH'; export const TOGGLE_SKETCH = 'TOGGLE_SKETCH';
export const START_SKETCH = 'START_SKETCH';
export const STOP_SKETCH = 'STOP_SKETCH';

View file

@ -10,6 +10,14 @@ const ide = (state = initialState, action) => {
return { return {
isPlaying: !state.isPlaying isPlaying: !state.isPlaying
} }
case ActionTypes.START_SKETCH:
return {
isPlaying: true
}
case ActionTypes.STOP_SKETCH:
return {
isPlaying: false
}
default: default:
return state return state
} }