Skip to content

Commit

Permalink
Update to create events on select slot (jquense#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuanbarreto authored and jquense committed Jul 18, 2018
1 parent cd10e6f commit d1dfa3e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion examples/demos/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Dnd extends React.Component {
events: events,
}

this.moveEvent = this.moveEvent.bind(this)
this.moveEvent = this.moveEvent.bind(this);
this.newEvent = this.newEvent.bind(this);
}

moveEvent({ event, start, end }) {
Expand Down Expand Up @@ -51,6 +52,21 @@ class Dnd extends React.Component {
alert(`${event.title} was resized to ${start}-${end}`)
}

newEvent(event) {
let idList = this.state.events.map((a) => a.id);
let newId = Math.max(...idList) + 1;
let hour = {
id: newId,
title: 'New Event',
allDay: event.slots.length == 1,
start: event.start,
end: event.end,
}
this.setState({
events: this.state.events.concat([hour])
});
}

render() {
return (
<DragAndDropCalendar
Expand All @@ -59,6 +75,7 @@ class Dnd extends React.Component {
onEventDrop={this.moveEvent}
resizable
onEventResize={this.resizeEvent}
onSelectSlot={this.newEvent}
defaultView={BigCalendar.Views.WEEK}
defaultDate={new Date(2015, 3, 12)}
/>
Expand Down

0 comments on commit d1dfa3e

Please sign in to comment.