From 94214c9617e04ee2acbdcc0f890148591e6ff90e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 23 Feb 2018 10:19:29 +0000 Subject: [PATCH] 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 --- src/components/Calendar.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index f67ca63..2c27892 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -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} /> );