add toggle sketch action

This commit is contained in:
catarak 2016-05-11 16:13:17 -04:00
parent d1c353fc26
commit 842ba9f367
5 changed files with 35 additions and 6 deletions

View file

@ -8,7 +8,7 @@ class Toolbar extends React.Component {
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"> <div className="toolbar__play-button" onClick={this.props.toggleSketch}>
<img src={playUrl}/> <img src={playUrl}/>
</div> </div>
</div> </div>

View file

@ -12,7 +12,9 @@ class App extends React.Component {
return ( return (
<div className="app"> <div className="app">
<Toolbar <Toolbar
className="toolbar" /> className="toolbar"
isPlaying={this.props.ide.isPlaying}
toggleSketch={this.props.toggleSketch} />
<Editor <Editor
content={this.props.file.content} content={this.props.file.content}
updateFile={this.props.updateFile} /> updateFile={this.props.updateFile} />
@ -20,7 +22,8 @@ class App extends React.Component {
content={this.props.file.content} content={this.props.file.content}
head={ head={
<link type='text/css' rel='stylesheet' href='preview-styles.css' /> <link type='text/css' rel='stylesheet' href='preview-styles.css' />
}/> }
isPlaying={this.props.ide.isPlaying}/>
</div> </div>
); );
} }
@ -28,7 +31,8 @@ class App extends React.Component {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
file: state.file file: state.file,
ide: state.ide
} }
} }

View file

@ -7,3 +7,9 @@ export function updateFile(name, content) {
content: content content: content
} }
} }
export function toggleSketch() {
return {
type: ActionTypes.TOGGLE_SKETCH
}
}

View file

@ -1 +1,18 @@
import * as ActionTypes from '../constants/constants'; import * as ActionTypes from '../constants/constants';
const initialState = {
isPlaying: false
}
const ide = (state = initialState, action) => {
switch (action.type) {
case ActionTypes.TOGGLE_SKETCH:
return {
isPlaying: !state.isPlaying
}
default:
return state
}
}
export default ide;

View file

@ -1,8 +1,10 @@
import { combineReducers } from 'redux' import { combineReducers } from 'redux'
import file from './files' import file from './files'
import ide from './ide'
const rootReducer = combineReducers({ const rootReducer = combineReducers({
file file,
ide
}) })
export default rootReducer export default rootReducer