var React = require('react/addons')
var ReactRouter = require('react-router')
var CodeEditor = require('./CodeEditor')
var Catalyst = require('../Mixins/Catalyst')
var Select = require('react-select')
var PlanetActions = require('../Actions/PlanetActions')
var PlanetStore = require('../Stores/PlanetStore')
// TODO: remove
var options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
]
var SnippetForm = React.createClass({
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
propTypes: {
close: React.PropTypes.func
},
getInitialState: function () {
return {
snippet: {
description: '',
mode: 'javascript',
content: '',
callSign: '',
Tags: []
}
}
},
handleSnippetTagsChange: function (selected, all) {
var snippet = this.state.snippet
snippet.Tags = all
this.setState({snippet: snippet})
},
handleSnippetContentChange: function (e, value) {
var snippet = this.state.snippet
snippet.content = value
this.setState({snippet: snippet})
},
submit: function () {
var params = this.getParams()
var userName = params.userName
var planetName = params.planetName
var snippet = Object.assign({}, this.state.snippet)
snippet.Tags = snippet.Tags.map(function (tag) {
return tag.value
})
PlanetActions.createSnippet(userName + '/' + planetName, snippet)
},
render: function () {
return (
)
}
})
var BlueprintForm = React.createClass({
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
propTypes: {
close: React.PropTypes.func
},
getInitialState: function () {
return {
blueprint: {
title: '',
content: '',
Tags: []
}
}
},
handleBlueprintTagsChange: function (selected, all) {
var blueprint = this.state.blueprint
blueprint.Tags = all
this.setState({blueprint: blueprint})
},
handleBlueprintContentChange: function (e, value) {
var blueprint = this.state.blueprint
blueprint.content = value
this.setState({blueprint: blueprint})
},
submit: function () {
console.log(this.state.blueprint)
},
render: function () {
return (
)
}
})
var LaunchModal = React.createClass({
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
propTypes: {
submit: React.PropTypes.func,
close: React.PropTypes.func
},
getInitialState: function () {
return {
currentTab: 'snippet'
}
},
componentDidMount: function () {
this.unsubscribe = PlanetStore.listen(this.onListen)
},
componentWillUnmount: function () {
this.unsubscribe()
},
onListen: function (res) {
switch (res.status) {
case 'snippetCreated':
this.props.close()
break
}
},
handleClick: function (e) {
e.stopPropagation()
},
selectSnippetTab: function () {
this.setState({currentTab: 'snippet'})
},
selectBlueprintTab: function () {
this.setState({currentTab: 'blueprint'})
},
submit: function () {
// this.props.submit('yolo')
if (this.state.currentTab === 'snippet') {
console.log(this.state.snippet)
} else {
console.log(this.state.blueprint)
}
},
render: function () {
var modalBody
if (this.state.currentTab === 'snippet') {
modalBody = (
)
} else {
modalBody = (
)
}
return (
)
}
})
module.exports = LaunchModal