|
| 1 | +/** |
| 2 | + * @flow |
| 3 | + * |
| 4 | + * Building Hours "report a problem" screen. |
| 5 | + */ |
| 6 | + |
| 7 | +import React from 'react' |
| 8 | +import {ScrollView, Text, StyleSheet} from 'react-native' |
| 9 | +import {TableView, Section, Cell} from 'react-native-tableview-simple' |
| 10 | +import type {BuildingType, NamedBuildingScheduleType} from '../types' |
| 11 | +import type {TopLevelViewPropsType} from '../../types' |
| 12 | + |
| 13 | +export class BuildingHoursProblemReportView extends React.PureComponent { |
| 14 | + static navigationOptions = { |
| 15 | + title: 'Report a Problem', |
| 16 | + } |
| 17 | + |
| 18 | + state: { |
| 19 | + building: BuildingType, |
| 20 | + } = { |
| 21 | + building: this.props.navigation.state.params.initialBuilding, |
| 22 | + } |
| 23 | + |
| 24 | + props: TopLevelViewPropsType & { |
| 25 | + navigation: {state: {params: {initialBuilding: BuildingType}}}, |
| 26 | + } |
| 27 | + |
| 28 | + onChangeSchedule = (index: number, newSchedule: NamedBuildingScheduleType) => { |
| 29 | + this.setState(state => { |
| 30 | + const schedule = [...state.building.schedule] |
| 31 | + schedule.splice(index, 1, newSchedule) |
| 32 | + return {building: {...state.building, schedule}} |
| 33 | + }) |
| 34 | + } |
| 35 | + |
| 36 | + render() { |
| 37 | + console.log(this.state.building) |
| 38 | + |
| 39 | + return ( |
| 40 | + <ScrollView> |
| 41 | + <Text> |
| 42 | + Thanks for spotting a problem! If you could tell us what the new times |
| 43 | + are, we'd greatly appreciate it. |
| 44 | + </Text> |
| 45 | + |
| 46 | + <TableView> |
| 47 | + {this.state.building.schedule} |
| 48 | + <EditableSchedule schedule={{}} /> |
| 49 | + </TableView> |
| 50 | + </ScrollView> |
| 51 | + ) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class EditableSchedule extends React.PureComponent { |
| 56 | + render() { |
| 57 | + return ( |
| 58 | + <Section header="KITCHEN"> |
| 59 | + |
| 60 | + <TitleCell text="Kitchen" /> |
| 61 | + |
| 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" /> |
| 66 | + |
| 67 | + <AddScheduleCell /> |
| 68 | + |
| 69 | + <NotesCell text="The kitchen stops cooking at 8 p.m." /> |
| 70 | + </Section> |
| 71 | + ) |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +// "Title" will become a textfield like the login form |
| 76 | +const TitleCell = ({text, onChange}) => |
| 77 | + <Cell title="Title" cellStyle="RightDetail" detail={text} /> |
| 78 | + |
| 79 | +// "Notes" will become a big textarea |
| 80 | +const NotesCell = ({text, onChange}) => |
| 81 | + <Cell title="Notes" cellStyle="Subtitle" detail={text} /> |
| 82 | + |
| 83 | +const AddScheduleCell = () => |
| 84 | + <Cell title="Add Schedule" accessory="DisclosureIndicator" /> |
| 85 | + |
| 86 | +const TimesCell = ({days, times, onPress}) => |
| 87 | + <Cell |
| 88 | + title={days} |
| 89 | + accessory="Detail" |
| 90 | + cellStyle="RightDetail" |
| 91 | + detail={times} |
| 92 | + /> |
0 commit comments