Skip to content

Commit

Permalink
hide event form by default
Browse files Browse the repository at this point in the history
  • Loading branch information
iasoon committed Oct 28, 2015
1 parent 8c34184 commit a8dd6d3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
38 changes: 36 additions & 2 deletions app/assets/javascripts/components/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,49 @@ import Event from './timeline/event';
import EventForm from './timeline/event_form';

class Timeline extends Component {
constructor(props, context) {
super(props, context);
this.state = {showForm: false}
}

submitEvent(e){
this.hideForm();
this.props.eventActions.add(e);
}

showForm() {
this.setState({showForm: true});
}

hideForm() {
this.setState({showForm: false});
}

renderForm() {
const eventActions = this.props.eventActions;
if (this.state.showForm){
return <EventForm onSubmit={this.submitEvent.bind(this)}
onCancel={this.hideForm.bind(this)}/>
} else {
return (
<div className='button-container'>
<button onClick={this.showForm.bind(this)}
className='btn btn-primary pull-right'>
Add event
</button>
</div>
);
}
}

renderEvent(event) {
return <Event {...event}/>
}

render() {
const eventActions = this.props.eventActions;
return (
<div>
<EventForm onSubmit={eventActions.add}/>
{this.renderForm()}
{this.props.events.map(this.renderEvent)}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/timeline/event_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class EventForm extends Component {
constructor(props, context) {
super(props, context);
if (this.props.event === undefined) {
this.state = {};
this.state = { moment: moment().add(30, 'minutes')};
} else {
this.state = this.props.event;
}
Expand All @@ -27,6 +27,7 @@ export default class EventForm extends Component {
<DateTimeField
dateTime={this.state.moment}
onChange={ e => this.setState({moment: new Date(- -e)}) }
minDate={moment()}
/>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/events.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
resize: none;
}
}

.button-container {
overflow: hidden;
margin-bottom: 15px;
}

0 comments on commit a8dd6d3

Please sign in to comment.