From 033f8a5467434d11e9a52c579f4f6aba509439bb Mon Sep 17 00:00:00 2001 From: Marco Solazzi Date: Thu, 10 Dec 2015 18:52:44 +0100 Subject: [PATCH] a bunch of stuff --- .babelrc | 11 ++ .eslintrc | 6 +- application/assets/javascripts/actions.js | 8 +- application/assets/javascripts/application.js | 45 +++++- .../javascripts/components/attendee-list.js | 36 +++++ .../assets/javascripts/components/attendee.js | 15 ++ .../javascripts/components/edit-form.js | 75 +++++++++ application/assets/javascripts/constants.js | 4 +- application/assets/javascripts/reducers.js | 10 +- application/fixtures/api-test.json | 3 + application/test/actions.spec.js | 18 +-- .../test/components/attendee-list.spec.js | 37 +++++ application/test/components/attendee.spec.js | 30 ++++ application/test/components/edit-form.spec.js | 68 ++++++++ application/test/reducers.spec.js | 11 +- application/test/setup.js | 10 +- build/gulp-config/modernizr.conf.json | 153 ++++++++++++++++++ build/gulp-config/webpack.conf.js | 57 ++++--- build/gulp-tasks/lib/middlewares.js | 29 +++- build/gulp-tasks/modernizr.js | 2 +- build/gulp-tasks/scripts.js | 38 ++--- build/gulp-tasks/test.js | 3 +- package.json | 22 +-- 23 files changed, 591 insertions(+), 100 deletions(-) create mode 100644 .babelrc create mode 100644 application/assets/javascripts/components/attendee-list.js create mode 100644 application/assets/javascripts/components/attendee.js create mode 100644 application/assets/javascripts/components/edit-form.js create mode 100644 application/fixtures/api-test.json create mode 100644 application/test/components/attendee-list.spec.js create mode 100644 application/test/components/attendee.spec.js create mode 100644 application/test/components/edit-form.spec.js create mode 100644 build/gulp-config/modernizr.conf.json diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e5a0962 --- /dev/null +++ b/.babelrc @@ -0,0 +1,11 @@ +{ + "presets": [ + "es2015-loose", + "react" + ], + "env": { + "production": { + "plugins": ["external-helpers-2"] + } + } +} diff --git a/.eslintrc b/.eslintrc index c72ccdc..4f34d22 100644 --- a/.eslintrc +++ b/.eslintrc @@ -35,7 +35,7 @@ /** * React */ - "react/display-name": 1, + "react/display-name": 0, "react/forbid-prop-types": 1, "react/jsx-boolean-value": 1, "react/jsx-closing-bracket-location": 1, @@ -43,7 +43,7 @@ "react/jsx-handler-names": 1, "react/jsx-indent-props": 1, "react/jsx-key": 1, - "react/jsx-max-props-per-line": 1, + "react/jsx-max-props-per-line": 0, "react/jsx-no-bind": 1, "react/jsx-no-duplicate-props": 1, "react/jsx-no-literals": 1, @@ -51,7 +51,7 @@ "react/jsx-pascal-case": 1, "react/jsx-quotes": 1, "react/jsx-sort-prop-types": 1, - "react/jsx-sort-props": 1, + "react/jsx-sort-props": 0, "react/jsx-uses-react": 1, "react/jsx-uses-vars": 1, "react/no-danger": 1, diff --git a/application/assets/javascripts/actions.js b/application/assets/javascripts/actions.js index b37bbce..3dbe1fa 100644 --- a/application/assets/javascripts/actions.js +++ b/application/assets/javascripts/actions.js @@ -6,12 +6,12 @@ * @module actions */ -import {ACTION_NAMES_CHANGE, ACTION_SELECTED_ADD} from './constants'; +import {ACTION_ATTENDEES_CHANGE, ACTION_SELECTED_ADD} from './constants'; -export function namesChangeAction(names = []) { +export function attendeeListChangeAction(attendeeList = []) { return { - type: ACTION_NAMES_CHANGE, - names + type: ACTION_ATTENDEES_CHANGE, + attendeeList }; } diff --git a/application/assets/javascripts/application.js b/application/assets/javascripts/application.js index 9e99c28..531b430 100644 --- a/application/assets/javascripts/application.js +++ b/application/assets/javascripts/application.js @@ -6,11 +6,48 @@ * */ -import React from 'react'; +import { applyMiddleware, createStore } from 'redux'; +import createLogger from 'redux-logger'; + +import React, {Component} from 'react'; import ReactDOM from 'react-dom'; -import Provider from 'react-redux'; +import {Provider} from 'react-redux'; + +//redux stuff +import reducers from './reducers'; + +//container Components +import AttendeeListContainer from './components/attendee-list'; +import EditForm from './components/edit-form'; + +const middlewares = []; +if (PRODUCTION === false) { + middlewares.push(createLogger({ + collapsed: true + })); +} + +const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore); +const store = createStoreWithMiddleware(reducers); + +class App extends Component { + + componentDidMount() { + } + + render() { + return ( +
+ + +
+ ); + } +} ReactDOM.render( -
{'test'}
, - document.querySelector('#root') + + + , + document.getElementById('root') ); \ No newline at end of file diff --git a/application/assets/javascripts/components/attendee-list.js b/application/assets/javascripts/components/attendee-list.js new file mode 100644 index 0000000..dcd522f --- /dev/null +++ b/application/assets/javascripts/components/attendee-list.js @@ -0,0 +1,36 @@ +/** + * Applicatino Container: List of attendees + * + * @author Marco Solazzi + * @copyright (c) Marco solazzi + * @module components/attendees-list + */ + +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +import Attendee from './attendee'; + +function mapStateToProps(state) { + return { + attendees: state.attendeeList + }; +} + +export class AttendeeList extends Component { + + render() { + let items = this.props.attendees.map((attendee) => ( + + )); + return ; + } +} + +AttendeeList.propTypes = { + attendees: React.PropTypes.array +}; + +export default connect( + mapStateToProps +)(AttendeeList); \ No newline at end of file diff --git a/application/assets/javascripts/components/attendee.js b/application/assets/javascripts/components/attendee.js new file mode 100644 index 0000000..0773a6c --- /dev/null +++ b/application/assets/javascripts/components/attendee.js @@ -0,0 +1,15 @@ +/** + * Attendee diplayer + * + * @author Marco Solazzi + * @copyright (c) Marco Solazzi + * @module components/attendee + */ + +import React from 'react'; + +export default ({ + details +}) => ( +
  • {details.name}
  • +); diff --git a/application/assets/javascripts/components/edit-form.js b/application/assets/javascripts/components/edit-form.js new file mode 100644 index 0000000..7424f6b --- /dev/null +++ b/application/assets/javascripts/components/edit-form.js @@ -0,0 +1,75 @@ +/** + * Attendee edit form + * + * @author Marco Solazzi + * @copyright (c) AQuest + * @module components/edit-form + */ + +import React, {Component} from 'react'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import {attendeeListChangeAction} from '../actions'; + + +function mapStateToProps(state) { + return { + attendees: state.attendeeList + }; +} + +function mapDispatchToProps(dispatch) { + return { + updateAttendees: bindActionCreators(attendeeListChangeAction, dispatch) + }; +} + +export class EditForm extends Component { + + handleSubmit(e) { + e.preventDefault(); + const value = (this.refs.attendeeInput.value || '').trim(); + const attendees = EditForm.filterAttendees(value) + .map((name, id) => { + return {id, name}; + }); + + this.props.updateAttendees(attendees); + + } + + static filterAttendees(value = '') { + return value.split("\n") + .map((line) => line.replace(/[\s]+/g, ' ').trim()) + .filter((line) => !!line.length); + } + + getAttendees() { + return this.props.attendees.map((attendee) => attendee.name).join("\n").trim(); + } + + render() { + + let attendees = this.getAttendees(); + + return ( +
    +