import * as React from "react"; import { Navbar } from "../nav/navbar"; import { ToggleButton } from "./toggle_button"; import { DirectionButton } from "./direction_button"; import { sendCommand, changeStepSize, changeAxisBuffer, commitAxisChanges, pinToggle } from "../devices/actions"; import { BotState } from "../devices/interfaces"; import { connect } from "react-redux"; import { Everything } from "../interfaces"; import { WebcamSaveBtn } from "./webcam_save_btn"; import { t } from "i18next"; interface AxisInputBoxProps { bot: BotState; axis: string; label: string; dispatch: Function; }; export class AxisInputBox extends React.Component { primary(): string { return this.props.bot.axisBuffer[this.props.axis] || ""; } secondary(): string { let num = (this.props.bot.hardware as any)[this.props.axis]; if (_.isNumber(num)) { return String(num); // Prevent 0 from being falsy. } else { return num; }; } style() { return { border: (this.primary()) ? "1px solid red" : "" }; } change(key: string, dispatch: Function): React.EventHandler { return function (event) { dispatch(changeAxisBuffer(key, (event.target as any).value )); }; } render() { return
; } } export class StepSizeSelector extends React.Component { cssForIndex(num: number) { let choices = this.props.choices; let css = "move-amount no-radius "; if (num === _.first(choices)) { css += "leftmost "; } if (num === _.last(choices)) { css += "rightmost "; } if (num === this.props.selected) { css += "move-amount-selected "; } return css; } render() { return (
{ this.props.choices.map( (item: number, inx: number) => ) }
); } } @connect(state => state) export class Controls extends React.Component { render() { let bot = this.props.bot; let url = ((this.props.bot.account && this.props.bot.account.webcam_url) || (`${this.props.auth.iss}/webcam_url_not_set.jpeg`)); let dirty = !!this.props.bot.account.dirty; return (
Move
{t(`Use these manual control buttons to move FarmBot in realtime. Press the arrows for relative movements or type in new coordinates and press GO for an absolute movement. Tip: Press the Home button when you are done so FarmBot is ready to get back to work. Note: Currently all buttons except for Home work.`)}
this.props.dispatch(changeStepSize(num))} selected={bot.stepSize} />
Tools
{t(`Use these toggle switches to control FarmBot's tools and peripherals in realtime. To edit and create new tools, press the button. Make sure to turn things off when you're done! Coming soon: a working edit button.`)}

{t("Pin 9")}

this.props.dispatch(pinToggle(9)) } />

{t("Pin 10")}

this.props.dispatch(pinToggle(10)) } />

{t("Pin 13")}

this.props.dispatch(pinToggle(13)) } />
{t("Camera")}
{t(`Press the button to add the URL of a livestream of your FarmBot. Coming soon: A working edit button and the ability to save your webcam URL in the backend.`)}
{showUrl(url, dirty)}
); } }; const showUrl = (url: string, dirty: boolean) => { if (dirty) { return

Press save to view.

; } else { return ; }; }; const updateWebcamUrl = (dispatch: Function) => (event: React.KeyboardEvent) => { dispatch({ type: "CHANGE_WEBCAM_URL", payload: (event.target as any)["value"] }); };