66
77import React from 'react'
88import { ScrollView , Text , StyleSheet } from 'react-native'
9+ import moment from 'moment-timezone'
910import { TableView , Section , Cell } from 'react-native-tableview-simple'
1011import type { BuildingType , NamedBuildingScheduleType } from '../types'
1112import type { TopLevelViewPropsType } from '../../types'
13+ import { summarizeDays , formatBuildingTimes } from '../lib'
1214
1315export class BuildingHoursProblemReportView extends React . PureComponent {
1416 static navigationOptions = {
@@ -25,7 +27,10 @@ export class BuildingHoursProblemReportView extends React.PureComponent {
2527 navigation : { state : { params : { initialBuilding : BuildingType } } } ,
2628 }
2729
28- onChangeSchedule = ( index : number , newSchedule : NamedBuildingScheduleType ) => {
30+ onChangeSchedule = (
31+ index : number ,
32+ newSchedule : NamedBuildingScheduleType ,
33+ ) => {
2934 this . setState ( state => {
3035 const schedule = [ ...state . building . schedule ]
3136 schedule . splice ( index , 1 , newSchedule )
@@ -34,7 +39,7 @@ export class BuildingHoursProblemReportView extends React.PureComponent {
3439 }
3540
3641 render ( ) {
37- console . log ( this . state . building )
42+ const schedules = this . state . building . schedule || [ ]
3843
3944 return (
4045 < ScrollView >
@@ -44,29 +49,37 @@ export class BuildingHoursProblemReportView extends React.PureComponent {
4449 </ Text >
4550
4651 < TableView >
47- { this . state . building . schedule }
48- < EditableSchedule schedule = { { } } />
52+ { schedules . map ( s => < EditableSchedule key = { s . title } schedule = { s } /> ) }
4953 </ TableView >
5054 </ ScrollView >
5155 )
5256 }
5357}
5458
5559class EditableSchedule extends React . PureComponent {
60+ props : {
61+ schedule : NamedBuildingScheduleType ,
62+ }
63+
5664 render ( ) {
57- return (
58- < Section header = "KITCHEN" >
65+ const { schedule } = this . props
66+ const now = moment ( )
5967
60- < TitleCell text = "Kitchen" />
68+ return (
69+ < Section header = { schedule . title . toUpperCase ( ) } footer = { schedule . notes } >
70+ < TitleCell text = { schedule . title } />
6171
62- < TimesCell days = "Mon-Thu" times = "7:30AM — 8PM" />
63- < TimesCell days = "Friday" times = "7:30AM — 8PM" />
64- < TimesCell days = "Saturday" times = "9AM — 8PM" />
65- < TimesCell days = "Sunday" times = "9AM — 8PM" />
72+ { schedule . hours . map ( ( set , i ) =>
73+ < TimesCell
74+ key = { i }
75+ days = { summarizeDays ( set . days ) }
76+ times = { formatBuildingTimes ( set , now ) }
77+ /> ,
78+ ) }
6679
6780 < AddScheduleCell />
6881
69- < NotesCell text = "The kitchen stops cooking at 8 p.m." />
82+ < NotesCell text = { schedule . notes } />
7083 </ Section >
7184 )
7285 }
0 commit comments