@@ -114,8 +114,8 @@ export default class Agenda extends Component<AgendaProps, State> {
114114 calendarIsReady : false ,
115115 calendarScrollable : false ,
116116 firstReservationLoad : false ,
117- selectedDay : parseDate ( props . selected ) || new XDate ( true ) ,
118- topDay : parseDate ( props . selected ) || new XDate ( true )
117+ selectedDay : this . getSelectedDate ( ) ,
118+ topDay : this . getSelectedDate ( )
119119 } ;
120120
121121 this . currentMonth = this . state . selectedDay . clone ( ) ;
@@ -134,9 +134,9 @@ export default class Agenda extends Component<AgendaProps, State> {
134134 this . state . scrollY . removeAllListeners ( ) ;
135135 }
136136
137- componentDidUpdate ( prevProps : AgendaProps ) {
138- if ( ! sameDate ( parseDate ( this . props . selected ) , parseDate ( prevProps . selected ) ) ) {
139- this . setState ( { selectedDay : parseDate ( this . props . selected ) } ) ;
137+ componentDidUpdate ( prevProps : AgendaProps , prevState : State ) {
138+ if ( this . props . selected && ! sameDate ( new XDate ( this . props . selected ) , prevState . selectedDay ) ) {
139+ this . setState ( { selectedDay : this . getSelectedDate ( ) } ) ;
140140 } else if ( ! prevProps . items ) {
141141 this . loadReservations ( this . props ) ;
142142 }
@@ -149,6 +149,11 @@ export default class Agenda extends Component<AgendaProps, State> {
149149 return null ;
150150 }
151151
152+ getSelectedDate ( ) {
153+ const { selected} = this . props ;
154+ return selected ? parseDate ( selected ) : new XDate ( true ) ;
155+ }
156+
152157 calendarOffset ( ) {
153158 return 96 - this . viewHeight / 2 ;
154159 }
0 commit comments