From 3a23efe2f75898090aa952ae06f7a0f4accd4874 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 8 Nov 2016 17:47:56 +0100 Subject: add select2 with reactux --- .../javascripts/es6_browserified/actions/index.js | 5 +- .../es6_browserified/components/BSelect2.js | 96 ++++++++++++++++++++++ .../es6_browserified/components/Todo.js | 74 +++++++++-------- .../es6_browserified/components/TodoList.js | 44 +++++----- .../javascripts/es6_browserified/reducers/todos.js | 14 ++-- .../javascripts/es6_browserified/stop_points.js | 16 ++-- 6 files changed, 179 insertions(+), 70 deletions(-) create mode 100644 app/assets/javascripts/es6_browserified/components/BSelect2.js (limited to 'app/assets/javascripts') diff --git a/app/assets/javascripts/es6_browserified/actions/index.js b/app/assets/javascripts/es6_browserified/actions/index.js index c0f64005e..8967c0322 100644 --- a/app/assets/javascripts/es6_browserified/actions/index.js +++ b/app/assets/javascripts/es6_browserified/actions/index.js @@ -1,25 +1,21 @@ module.exports = { - addStop : () => { return { type: 'ADD_STOP' } }, - moveStopUp : (index) => { return { type: 'MOVE_STOP_UP', index } }, - moveStopDown : (index) => { return { type: 'MOVE_STOP_DOWN', index } }, - deleteStop: (index) => { return { type: 'DELETE_STOP', @@ -27,6 +23,7 @@ module.exports = { } }, updateInputValue: (index, text) => { + console.log('action',index, text) return { type : "UPDATE_INPUT_VALUE", index, diff --git a/app/assets/javascripts/es6_browserified/components/BSelect2.js b/app/assets/javascripts/es6_browserified/components/BSelect2.js new file mode 100644 index 000000000..7e4782563 --- /dev/null +++ b/app/assets/javascripts/es6_browserified/components/BSelect2.js @@ -0,0 +1,96 @@ +var React = require('react') +var PropTypes = require('react').PropTypes +var Select2 = require('react-select2') + +// get JSON full path +var origin = window.location.origin +var path = window.location.pathname.split('/', 3).join('/') + +class BSelect3 extends React.Component{ + constructor(props) { + super(props) + this.state = { + edit: false + } + } + onToggleEdit(e) { + e.preventDefault() + this.setState({edit: !this.state.edit}) + } + onChange(e) { + console.log(e.currentTarget.value, e.currentTarget.textContent) + this.props.onChange(this.props.index, {text: e.currentTarget.textContent, id: e.currentTarget.value}) + this.setState({edit: false}) + } + render() { + if(this.state.edit) + return ( +