From 472d79cbf27dfbe130d1ce3a1216a31e8b41c141 Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Thu, 9 Jul 2015 01:48:49 +0900 Subject: [PATCH] add ModalBase, LaunchModal & install Reflux --- bower.json | 3 +- browser/main/Components/CodeEditor.jsx | 48 ++++++ browser/main/Components/CodeViewer.jsx | 14 +- browser/main/Components/LaunchModal.jsx | 148 ++++++++++++++++++ browser/main/Components/ModalBase.jsx | 23 +++ browser/main/Components/ModeSelect.jsx | 7 + browser/main/Containers/LoginContainer.jsx | 4 +- browser/main/Containers/PlanetContainer.jsx | 23 ++- browser/main/Containers/RegisterContainer.jsx | 8 +- browser/main/Containers/SnippetContainer.jsx | 52 +++++- browser/main/Mixins/Catalyst.js | 38 +++++ browser/main/index.html | 1 + browser/main/index.jsx | 1 + browser/styles/main/index.styl | 31 ++-- browser/styles/shared/btn.styl | 1 + browser/styles/shared/modal.styl | 30 ++++ package.json | 4 +- webpack.config.js | 3 +- 18 files changed, 415 insertions(+), 24 deletions(-) create mode 100644 browser/main/Components/CodeEditor.jsx create mode 100644 browser/main/Components/LaunchModal.jsx create mode 100644 browser/main/Components/ModalBase.jsx create mode 100644 browser/main/Components/ModeSelect.jsx create mode 100644 browser/main/Mixins/Catalyst.js create mode 100644 browser/styles/shared/modal.styl diff --git a/bower.json b/bower.json index d3bad4c6..547988d2 100644 --- a/bower.json +++ b/bower.json @@ -3,6 +3,7 @@ "dependencies": { "react": "~0.13.3", "fontawesome": "~4.3.0", - "react-router": "~0.13.3" + "react-router": "~0.13.3", + "reflux": "~0.2.8" } } diff --git a/browser/main/Components/CodeEditor.jsx b/browser/main/Components/CodeEditor.jsx new file mode 100644 index 00000000..089c652f --- /dev/null +++ b/browser/main/Components/CodeEditor.jsx @@ -0,0 +1,48 @@ +var React = require('react/addons') + +var ace = require('ace') +var CodeEditor = React.createClass({ + propTypes: { + code: React.PropTypes.string, + mode: React.PropTypes.string, + onChange: React.PropTypes.func + }, + componentDidMount: function () { + var el = React.findDOMNode(this.refs.target) + var editor = ace.edit(el) + editor.setValue(this.props.code) + editor.$blockScrolling = Infinity + editor.renderer.setShowGutter(true) + editor.setTheme('ace/theme/xcode') + + var session = editor.getSession() + session.setMode('ace/mode/' + this.props.mode) + session.setUseSoftTabs(true) + session.setOption('useWorker', false) + + session.on('change', function (e) { + if (this.props.onChange != null) { + var value = editor.getValue() + this.props.onChange(e, value) + } + }.bind(this)) + + this.setState({editor: editor}) + }, + componentDidUpdate: function (prevProps) { + if (this.state.editor.getValue() !== this.props.code) { + this.state.editor.setValue(this.props.code) + this.state.editor.clearSelection() + } + if (prevProps.mode !== this.props.mode) { + this.state.editor.getSession().setMode('ace/mode/' + this.props.mode) + } + }, + render: function () { + return ( +
+ ) + } +}) + +module.exports = CodeEditor diff --git a/browser/main/Components/CodeViewer.jsx b/browser/main/Components/CodeViewer.jsx index 159a0835..bb04eef5 100644 --- a/browser/main/Components/CodeViewer.jsx +++ b/browser/main/Components/CodeViewer.jsx @@ -13,16 +13,24 @@ var CodeViewer = React.createClass({ editor.$blockScrolling = Infinity editor.renderer.setShowGutter(false) editor.setReadOnly(true) + editor.setTheme('ace/theme/xcode') + editor.setHighlightActiveLine(false) var session = editor.getSession() session.setMode('ace/mode/' + this.props.mode) session.setUseSoftTabs(true) + session.setOption('useWorker', false) this.setState({editor: editor}) }, - componentDidUpdate: function () { - this.state.editor.setValue(this.props.code) - this.state.editor.getSession().setMode('ace/mode/' + this.props.mode) + componentDidUpdate: function (prevProps) { + if (this.state.editor.getValue() !== this.props.code) { + this.state.editor.setValue(this.props.code) + this.state.editor.clearSelection() + } + if (prevProps.mode !== this.props.mode) { + this.state.editor.getSession().setMode('ace/mode/' + this.props.mode) + } }, render: function () { return ( diff --git a/browser/main/Components/LaunchModal.jsx b/browser/main/Components/LaunchModal.jsx new file mode 100644 index 00000000..ea3f72f5 --- /dev/null +++ b/browser/main/Components/LaunchModal.jsx @@ -0,0 +1,148 @@ +var React = require('react/addons') +var CodeEditor = require('./CodeEditor') +var Catalyst = require('../Mixins/Catalyst') + +var Select = require('react-select') + +// TODO: remove +var options = [ + { value: 'one', label: 'One' }, + { value: 'two', label: 'Two' } +] + +var LaunchModal = React.createClass({ + mixins: [Catalyst.LinkedStateMixin], + propTypes: { + submit: React.PropTypes.func, + close: React.PropTypes.func + }, + getInitialState: function () { + return { + snippet: { + description: '', + mode: 'javascript', + content: '', + callSign: '', + tags: [] + }, + blueprint: { + title: '', + content: '', + tags: [] + }, + currentTab: 'snippet' + } + }, + handleClick: function (e) { + e.stopPropagation() + }, + selectSnippetTab: function () { + this.setState({currentTab: 'snippet'}) + }, + selectBlueprintTab: function () { + this.setState({currentTab: 'blueprint'}) + }, + 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}) + }, + 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 () { + // this.props.submit('yolo') + if (this.state.currentTab === 'snippet') { + console.log(this.state.snippet) + } else { + console.log(this.state.blueprint) + } + }, + render: function () { + var form + if (this.state.currentTab === 'snippet') { + form = ( +
+
+