Farmbot-Web-App/frontend/regimens/bulk_scheduler/week_row.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { WeekRowProps, DayProps, DAYS } from "./interfaces";
2017-06-29 12:54:02 -06:00
import { toggleDay } from "./actions";
2019-04-02 13:59:37 -06:00
import { t } from "../../i18next_wrapper";
2017-06-29 12:54:02 -06:00
export function WeekRow({ index, dispatch, week }: WeekRowProps) {
return <div className="week-row">
<label className="week-label">{t("Week")} {index + 1}</label>
{
DAYS.map(function (day, i) {
2017-08-28 05:49:13 -06:00
const id = `${index}-${day}`;
2017-07-21 15:32:51 -06:00
return <Day day={i + 1}
2017-07-21 15:26:42 -06:00
week={index}
2017-06-29 12:54:02 -06:00
dispatch={dispatch}
id={id}
key={id}
active={week.days[day]} />;
2017-06-29 12:54:02 -06:00
})
}
</div>;
}
2017-08-28 05:49:13 -06:00
const select = (dispatch: Function, day: number, week: number) => () =>
2017-06-29 12:54:02 -06:00
dispatch(toggleDay({ day, week }));
function Day({ day, id, dispatch, week, active }: DayProps) {
return <div className="day-selector-wrapper">
<input type="checkbox"
id={id}
className="day"
onClick={select(dispatch, day, week)}
checked={active}
2017-08-23 16:26:09 -06:00
readOnly={true} />
2017-06-29 12:54:02 -06:00
<label className="day-label left-most" htmlFor={id}>
2017-07-21 15:29:28 -06:00
{(week * 7) + day}
2017-06-29 12:54:02 -06:00
</label>
</div>;
}