63 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-08-06 12:04:08 +03:00
import { observer } from "mobx-react";
import * as React from "react";
import { Form } from "semantic-ui-react";
import { DateOfYear, Schedule, TimeOfDay, Weekday } from "@common/sprinklersRpc";
import ScheduleDate from "./ScheduleDate";
import ScheduleTimes from "./ScheduleTimes";
import WeekdaysView from "./WeekdaysView";
2018-08-07 21:21:26 +03:00
import "@client/styles/ScheduleView";
2018-08-13 15:11:36 +03:00
import { action } from "mobx";
2018-08-06 12:04:08 +03:00
export interface ScheduleViewProps {
label?: string | React.ReactNode | undefined;
schedule: Schedule;
editing?: boolean;
}
@observer
export default class ScheduleView extends React.Component<ScheduleViewProps> {
render() {
const { schedule, label } = this.props;
const editing = this.props.editing || false;
let labelNode: React.ReactNode;
if (typeof label === "string") {
2018-08-06 12:10:34 +03:00
labelNode = <label>{label}</label>;
2018-08-06 12:04:08 +03:00
} else if (label != null) {
labelNode = label;
}
return (
<Form.Field className="scheduleView">
{labelNode}
2018-08-06 12:10:34 +03:00
<ScheduleTimes times={schedule.times} editing={editing} onChange={this.updateTimes} />
<WeekdaysView weekdays={schedule.weekdays} editing={editing} onChange={this.updateWeekdays} />
<ScheduleDate label="From" date={schedule.from} editing={editing} onChange={this.updateFromDate} />
<ScheduleDate label="To" date={schedule.to} editing={editing} onChange={this.updateToDate} />
2018-08-06 12:04:08 +03:00
</Form.Field>
);
}
2018-08-13 15:11:36 +03:00
@action.bound
private updateTimes(newTimes: TimeOfDay[]) {
2018-08-06 12:04:08 +03:00
this.props.schedule.times = newTimes;
}
2018-08-13 15:11:36 +03:00
@action.bound
private updateWeekdays(newWeekdays: Weekday[]) {
2018-08-06 12:04:08 +03:00
this.props.schedule.weekdays = newWeekdays;
}
2018-08-13 15:11:36 +03:00
@action.bound
private updateFromDate(newFromDate: DateOfYear | null) {
2018-08-06 12:04:08 +03:00
this.props.schedule.from = newFromDate;
}
2018-08-13 15:11:36 +03:00
@action.bound
private updateToDate(newToDate: DateOfYear | null) {
2018-08-06 12:04:08 +03:00
this.props.schedule.to = newToDate;
}
}