Farmbot-Web-App/frontend/sequences/step_buttons.tsx

44 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
2018-08-01 18:20:50 -06:00
import { SequenceBodyItem as Step, TaggedSequence } from "farmbot";
2019-12-05 13:52:16 -07:00
import { error } from "../toast/toast";
import { StepDragger, NULL_DRAGGER_ID } from "../draggable/step_dragger";
import { pushStep, closeCommandMenu } from "./actions";
import { StepButtonParams } from "./interfaces";
import { Col } from "../ui/index";
import { t } from "../i18next_wrapper";
2017-06-29 12:54:02 -06:00
2018-01-12 09:06:14 -07:00
export const stepClick =
2019-04-09 19:45:59 -06:00
(dispatch: Function,
step: Step,
seq: TaggedSequence | undefined,
index?: number | undefined) =>
2018-01-12 09:06:14 -07:00
() => {
2019-04-09 19:45:59 -06:00
seq
? pushStep(step, dispatch, seq, index)
: error(t("Select a sequence first"));
2019-04-11 21:17:18 -06:00
dispatch(closeCommandMenu());
2018-01-12 09:06:14 -07:00
};
2017-06-29 12:54:02 -06:00
2019-04-09 19:45:59 -06:00
export function StepButton({ children, step, color, dispatch, current, index }:
2017-06-29 12:54:02 -06:00
StepButtonParams) {
return <Col xs={6} sm={12}>
2017-07-03 13:00:56 -06:00
<div className="block">
<StepDragger
dispatch={dispatch}
2017-06-29 12:54:02 -06:00
step={step}
intent="step_splice"
2019-09-23 12:56:35 -06:00
draggerId={NULL_DRAGGER_ID}>
2017-12-15 16:09:24 -07:00
<button draggable={true}
2019-12-04 12:10:17 -07:00
className={`fb-button full-width block step-block ${color}`}
2020-02-28 09:34:28 -07:00
title={t("add step")}
2019-09-23 12:56:35 -06:00
onClick={stepClick(dispatch, step, current, index)}>
2019-12-04 12:10:17 -07:00
<div className="step-block-drag">
{children}
<i className="fa fa-arrows block-control" />
</div>
2017-06-29 12:54:02 -06:00
</button>
</StepDragger>
</div>
</Col>;
}