Calendar: fix switching back to months view when going back to calendar

Currently we preserve the watched date, so it's preserved when going
back to a calendar page. Now we also preserve the view.

Fixes #10
master
Tom Hacohen 7 years ago
parent 99ccfaf441
commit 94214c9617

@ -1,5 +1,5 @@
import * as React from 'react';
import BigCalendar from 'react-big-calendar';
import BigCalendar, { View } from 'react-big-calendar';
import 'react-big-calendar/lib/css/react-big-calendar.css';
import * as moment from 'moment';
import 'moment/locale/en-gb';
@ -27,6 +27,7 @@ function agendaHeaderFormat(date: {start: Date, end: Date}, culture: string, loc
class Calendar extends React.PureComponent {
state: {
currentDate?: Date;
view?: View;
};
props: {
@ -40,6 +41,7 @@ class Calendar extends React.PureComponent {
this.state = {};
this.onNavigate = this.onNavigate.bind(this);
this.onView = this.onView.bind(this);
this.slotClicked = this.slotClicked.bind(this);
}
@ -47,6 +49,10 @@ class Calendar extends React.PureComponent {
this.setState({currentDate});
}
onView(view: string) {
this.setState({view});
}
slotClicked(slotInfo: {start: Date, end: Date}) {
if (this.props.onSlotClick) {
this.props.onSlotClick(slotInfo.start, slotInfo.end);
@ -66,6 +72,8 @@ class Calendar extends React.PureComponent {
eventPropGetter={eventPropGetter}
date={this.state.currentDate}
onNavigate={this.onNavigate}
view={this.state.view}
onView={this.onView}
/>
</div>
);

Loading…
Cancel
Save