Skip to content

Commit 530f747

Browse files
authored
Merge pull request #1818 from wix/fix/Agenda_selected
Agenda - fix for 'selected' as undefined
2 parents 3efd6a4 + 7699425 commit 530f747

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/agenda/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,10 @@ 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+
const newSelectedDate = this.getSelectedDate();
139+
if (!sameDate(newSelectedDate, prevState.selectedDay)) {
140+
this.setState({selectedDay: newSelectedDate});
140141
} else if (!prevProps.items) {
141142
this.loadReservations(this.props);
142143
}
@@ -149,6 +150,11 @@ export default class Agenda extends Component<AgendaProps, State> {
149150
return null;
150151
}
151152

153+
getSelectedDate() {
154+
const {selected} = this.props;
155+
return selected ? parseDate(selected) : new XDate(true);
156+
}
157+
152158
calendarOffset() {
153159
return 96 - this.viewHeight / 2;
154160
}

0 commit comments

Comments
 (0)