import * as moment from "moment"; import * as React from "react"; import { Form } from "semantic-ui-react"; import { TimeOfDay } from "@common/sprinklersRpc"; import TimeInput from "./TimeInput"; function timeToString(time: TimeOfDay) { return moment(time).format("LTS"); } export default class ScheduleTimes extends React.Component<{ times: TimeOfDay[]; onChange: (newTimes: TimeOfDay[]) => void; editing: boolean; }> { render() { const { times, editing } = this.props; let timesNode: React.ReactNode; if (editing) { timesNode = times.map((time, i) => ( )); } else { timesNode = ( {times.map(time => timeToString(time)).join(", ")} ); } return ( {timesNode} ); } private onTimeChange = (newTime: TimeOfDay, index: number) => { const { times, onChange } = this.props; const newTimes = times.slice(); newTimes[index] = newTime; onChange(newTimes); }; }