@@ -10,17 +10,17 @@ import {sameDate} from '../../dateutils';
1010import { toMarkingFormat } from '../../interface' ;
1111import styleConstructor from './style' ;
1212import Reservation , { ReservationProps } from './reservation' ;
13- import { ReservationItemType , ReservationsType , DayReservations } from '../../types' ;
13+ import { AgendaEntry , AgendaSchedule } from '../../types' ;
1414
1515
1616export type ReservationListProps = ReservationProps & {
1717 /** the list of items that have to be displayed in agenda. If you want to render item as empty date
1818 the value of date key kas to be an empty array []. If there exists no value for date key it is
1919 considered that the date in question is not yet loaded */
20- items ?: ReservationsType ;
20+ items ?: AgendaSchedule ;
2121 selectedDay ?: XDate ;
2222 topDay ?: XDate ;
23- /** Show items only for the selected day . Default = false */
23+ /** Show items only for the selected date . Default = false */
2424 showOnlySelectedDayItems ?: boolean ;
2525 /** callback that gets called when day changes while scrolling agenda list */
2626 onDayChange ?: ( day : XDate ) => void ;
@@ -46,8 +46,13 @@ export type ReservationListProps = ReservationProps & {
4646 onRefresh ?: ( ) => void ;
4747} ;
4848
49+ interface DayAgenda {
50+ reservation ?: AgendaEntry ;
51+ date ?: XDate ;
52+ }
53+
4954interface State {
50- reservations : DayReservations [ ] ;
55+ reservations : DayAgenda [ ] ;
5156}
5257
5358class ReservationList extends Component < ReservationListProps , State > {
@@ -61,7 +66,7 @@ class ReservationList extends Component<ReservationListProps, State> {
6166 items : PropTypes . object ,
6267 selectedDay : PropTypes . instanceOf ( XDate ) ,
6368 topDay : PropTypes . instanceOf ( XDate ) ,
64- /** Show items only for the selected day . Default = false */
69+ /** Show items only for the selected date . Default = false */
6570 showOnlySelectedDayItems : PropTypes . bool ,
6671 /** callback that gets called when day changes while scrolling agenda list */
6772 onDayChange : PropTypes . func ,
@@ -130,7 +135,7 @@ class ReservationList extends Component<ReservationListProps, State> {
130135 }
131136 }
132137
133- updateDataSource ( reservations : DayReservations [ ] ) {
138+ updateDataSource ( reservations : DayAgenda [ ] ) {
134139 this . setState ( {
135140 reservations
136141 } ) ;
@@ -156,18 +161,16 @@ class ReservationList extends Component<ReservationListProps, State> {
156161 const day = iterator . clone ( ) ;
157162 const res = props . items ?. [ toMarkingFormat ( day ) ] ;
158163 if ( res && res . length ) {
159- return res . map ( ( reservation : ReservationItemType , i : number ) => {
164+ return res . map ( ( reservation : AgendaEntry , i : number ) => {
160165 return {
161166 reservation,
162- date : i ? undefined : day ,
163- day
167+ date : i ? undefined : day
164168 } ;
165169 } ) ;
166170 } else if ( res ) {
167171 return [
168172 {
169- date : iterator . clone ( ) ,
170- day
173+ date : iterator . clone ( )
171174 }
172175 ] ;
173176 } else {
@@ -181,9 +184,10 @@ class ReservationList extends Component<ReservationListProps, State> {
181184 return { reservations : [ ] , scrollPosition : 0 } ;
182185 }
183186
184- let reservations : DayReservations [ ] = [ ] ;
187+ let reservations : DayAgenda [ ] = [ ] ;
185188 if ( this . state . reservations && this . state . reservations . length ) {
186- const iterator = this . state . reservations [ 0 ] . day . clone ( ) ;
189+ const iterator = this . state . reservations [ 0 ] . date ?. clone ( ) ;
190+ if ( iterator )
187191 while ( iterator . getTime ( ) < selectedDay . getTime ( ) ) {
188192 const res = this . getReservationsForDay ( iterator , props ) ;
189193 if ( ! res ) {
@@ -235,11 +239,13 @@ class ReservationList extends Component<ReservationListProps, State> {
235239 const row = this . state . reservations [ topRow ] ;
236240 if ( ! row ) return ;
237241
238- const day = row . day ;
239- const dateIsSame = this . selectedDay && sameDate ( day , this . selectedDay ) ;
240- if ( ! dateIsSame && this . scrollOver ) {
241- this . selectedDay = day . clone ( ) ;
242- this . props . onDayChange ?.( day . clone ( ) ) ;
242+ const day = row . date ;
243+ if ( day ) {
244+ const dateIsSame = this . selectedDay && sameDate ( day , this . selectedDay ) ;
245+ if ( ! dateIsSame && this . scrollOver ) {
246+ this . selectedDay = day . clone ( ) ;
247+ this . props . onDayChange ?.( day . clone ( ) ) ;
248+ }
243249 }
244250 } ;
245251
@@ -256,17 +262,17 @@ class ReservationList extends Component<ReservationListProps, State> {
256262 return false ;
257263 } ;
258264
259- renderRow = ( { item, index} : { item : DayReservations ; index : number } ) => {
265+ renderRow = ( { item, index} : { item : DayAgenda ; index : number } ) => {
260266 const reservationProps = extractComponentProps ( Reservation , this . props ) ;
261267
262268 return (
263269 < View onLayout = { this . onRowLayoutChange . bind ( this , index ) } >
264- < Reservation { ...reservationProps } item = { item } />
270+ < Reservation { ...reservationProps } item = { item . reservation } date = { item . date } />
265271 </ View >
266272 ) ;
267273 } ;
268274
269- keyExtractor = ( _item : DayReservations , index : number ) => String ( index ) ;
275+ keyExtractor = ( _item : DayAgenda , index : number ) => String ( index ) ;
270276
271277 render ( ) {
272278 const { items, selectedDay, theme, style} = this . props ;
0 commit comments