-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Solazzi
committed
Dec 10, 2015
1 parent
c8ceedc
commit 033f8a5
Showing
23 changed files
with
591 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"presets": [ | ||
"es2015-loose", | ||
"react" | ||
], | ||
"env": { | ||
"production": { | ||
"plugins": ["external-helpers-2"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
application/assets/javascripts/components/attendee-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) => ( | ||
<Attendee details={attendee} key={attendee.id} /> | ||
)); | ||
return <ul>{items}</ul>; | ||
} | ||
} | ||
|
||
AttendeeList.propTypes = { | ||
attendees: React.PropTypes.array | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps | ||
)(AttendeeList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Attendee diplayer | ||
* | ||
* @author Marco Solazzi | ||
* @copyright (c) Marco Solazzi | ||
* @module components/attendee | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
export default ({ | ||
details | ||
}) => ( | ||
<li className="c-attendee" id={'attendee-' + details.id}>{details.name}</li> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<form action="" onSubmit={this.handleSubmit.bind(this)}> | ||
<textarea cols="30" ref="attendeeInput" id="edit-form" name="edit-form" rows="10" defaultValue={attendees} /> | ||
<p> | ||
<button type="submit">{'Save'}</button> | ||
<button type="reset">{'Reset'}</button> | ||
</p> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
EditForm.propTypes = { | ||
attendees: React.PropTypes.array, | ||
updateAttendees: React.PropTypes.func.isRequired | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(EditForm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/** | ||
* Contants | ||
* Constants | ||
* | ||
* @author Marco Solazzi | ||
* @copyright (c) Marco Solazzi | ||
* @module constants | ||
*/ | ||
|
||
//ACTIONS | ||
export const ACTION_NAMES_CHANGE = 'ACTION_NAMES_CHANGE'; | ||
export const ACTION_ATTENDEES_CHANGE = 'ACTION_ATTENDEES_CHANGE'; | ||
|
||
export const ACTION_SELECTED_ADD = 'ACTION_SELECTED_ADD'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"test": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import expect, { spyOn } from 'expect'; | ||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
|
||
import {AttendeeList} from '../../assets/javascripts/components/attendee-list'; | ||
|
||
describe('Name Item Component Actions', () => { | ||
|
||
let shallowRenderer, output; | ||
|
||
const data = { | ||
attendees: [{ | ||
id: 0, | ||
name: 'John' | ||
}, { | ||
id: 1, | ||
name: 'Jane' | ||
}] | ||
}; | ||
|
||
beforeEach(() => { | ||
shallowRenderer = TestUtils.createRenderer(); | ||
shallowRenderer.render(<AttendeeList {...data} />); | ||
output = shallowRenderer.getRenderOutput(); | ||
}); | ||
|
||
it('should render an unordered list', () => { | ||
expect(output.type).toBe('ul'); | ||
}); | ||
|
||
it('should render <Attendee> components', () => { | ||
output.props.children.forEach((prop, i) => { | ||
expect(prop.props.details).toEqual(data.attendees[i]); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.