Calendar: Implement clicking on a time slot to add an event

You can now click (or select) a time slot to create an event that is
automatically populated with the selected times.

Fixes #8
master
Tom Hacohen 7 years ago
parent 1fd4ee307d
commit 7917b1fbe1

@ -41,6 +41,7 @@ class PimMain extends React.PureComponent {
this.eventClicked = this.eventClicked.bind(this); this.eventClicked = this.eventClicked.bind(this);
this.contactClicked = this.contactClicked.bind(this); this.contactClicked = this.contactClicked.bind(this);
this.floatingButtonClicked = this.floatingButtonClicked.bind(this); this.floatingButtonClicked = this.floatingButtonClicked.bind(this);
this.newEvent = this.newEvent.bind(this);
} }
eventClicked(event: ICAL.Event) { eventClicked(event: ICAL.Event) {
@ -57,15 +58,20 @@ class PimMain extends React.PureComponent {
routeResolver.getRoute('pim.contacts._id', { itemUid: uid })); routeResolver.getRoute('pim.contacts._id', { itemUid: uid }));
} }
newEvent(start?: Date, end?: Date) {
this.props.history!.push(
routeResolver.getRoute('pim.events.new'),
{start, end}
);
}
floatingButtonClicked() { floatingButtonClicked() {
if (this.state.tab === addressBookTitle) { if (this.state.tab === addressBookTitle) {
this.props.history!.push( this.props.history!.push(
routeResolver.getRoute('pim.contacts.new') routeResolver.getRoute('pim.contacts.new')
); );
} else if (this.state.tab === calendarTitle) { } else if (this.state.tab === calendarTitle) {
this.props.history!.push( this.newEvent();
routeResolver.getRoute('pim.events.new')
);
} }
} }
@ -100,7 +106,11 @@ class PimMain extends React.PureComponent {
label={calendarTitle} label={calendarTitle}
> >
<Container> <Container>
<PersistCalendar entries={this.props.events} onItemClick={this.eventClicked} /> <PersistCalendar
entries={this.props.events}
onItemClick={this.eventClicked}
onSlotClick={this.newEvent}
/>
</Container> </Container>
</Tab> </Tab>
</Tabs> </Tabs>

@ -32,6 +32,7 @@ class Calendar extends React.PureComponent {
props: { props: {
entries: Array<EventType>, entries: Array<EventType>,
onItemClick: (contact: EventType) => void, onItemClick: (contact: EventType) => void,
onSlotClick?: (start: Date, end: Date) => void,
}; };
constructor(props: any) { constructor(props: any) {
@ -39,18 +40,27 @@ class Calendar extends React.PureComponent {
this.state = {}; this.state = {};
this.onNavigate = this.onNavigate.bind(this); this.onNavigate = this.onNavigate.bind(this);
this.slotClicked = this.slotClicked.bind(this);
} }
onNavigate(currentDate: Date) { onNavigate(currentDate: Date) {
this.setState({currentDate}); this.setState({currentDate});
} }
slotClicked(slotInfo: {start: Date, end: Date}) {
if (this.props.onSlotClick) {
this.props.onSlotClick(slotInfo.start, slotInfo.end);
}
}
render() { render() {
return ( return (
<div style={{width: '100%', height: 500}}> <div style={{width: '100%', height: 500}}>
<BigCalendar <BigCalendar
events={this.props.entries} events={this.props.entries}
selectable={true}
onSelectEvent={this.props.onItemClick as any} onSelectEvent={this.props.onItemClick as any}
onSelectSlot={this.slotClicked as any}
formats={{agendaHeaderFormat: agendaHeaderFormat}} formats={{agendaHeaderFormat: agendaHeaderFormat}}
eventPropGetter={eventPropGetter} eventPropGetter={eventPropGetter}
date={this.state.currentDate} date={this.state.currentDate}

@ -14,6 +14,9 @@ import DateTimePicker from '../widgets/DateTimePicker';
import ConfirmationDialog from '../widgets/ConfirmationDialog'; import ConfirmationDialog from '../widgets/ConfirmationDialog';
import { Location } from 'history';
import { withRouter } from 'react-router';
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import * as ICAL from 'ical.js'; import * as ICAL from 'ical.js';
@ -43,6 +46,7 @@ class EventEdit extends React.PureComponent {
onSave: (event: EventType, journalUid: string, originalEvent?: EventType) => void; onSave: (event: EventType, journalUid: string, originalEvent?: EventType) => void;
onDelete: (event: EventType, journalUid: string) => void; onDelete: (event: EventType, journalUid: string) => void;
onCancel: () => void; onCancel: () => void;
location: Location;
}; };
constructor(props: any) { constructor(props: any) {
@ -57,6 +61,17 @@ class EventEdit extends React.PureComponent {
journalUid: '', journalUid: '',
showDeleteDialog: false, showDeleteDialog: false,
}; };
const locState = this.props.location.state;
// FIXME: Hack to determine if all day. Should be passed as a proper state.
this.state.allDay = (locState.start &&
(locState.start.getHours() === 0) &&
(locState.start.getMinutes() === 0) &&
(locState.start.getHours() === locState.end.getHours()) &&
(locState.start.getMinutes() === locState.end.getMinutes()));
this.state.start = (locState.start) ? locState.start : undefined;
this.state.end = (locState.end) ? locState.end : undefined;
if (this.props.item !== undefined) { if (this.props.item !== undefined) {
const event = this.props.item; const event = this.props.item;
@ -306,4 +321,4 @@ class EventEdit extends React.PureComponent {
} }
} }
export default EventEdit; export default withRouter(EventEdit);

Loading…
Cancel
Save