2017-06-29 12:54:02 -06:00
|
|
|
import * as React from "react";
|
|
|
|
import { Everything } from "../../interfaces";
|
|
|
|
import { connect } from "react-redux";
|
2018-11-30 21:59:52 -07:00
|
|
|
import { history } from "../../history";
|
2017-11-24 07:36:10 -07:00
|
|
|
import { svgToUrl } from "../../open_farm/icons";
|
2018-11-30 21:59:52 -07:00
|
|
|
import { CropLiveSearchResult, OpenfarmSearch } from "../interfaces";
|
2018-04-27 23:57:17 -06:00
|
|
|
import { setDragIcon } from "../actions";
|
2018-11-30 21:59:52 -07:00
|
|
|
import { getCropHeaderProps, searchForCurrentCrop } from "./crop_info";
|
|
|
|
import { DesignerPanel, DesignerPanelHeader } from "./designer_panel";
|
|
|
|
import { OFSearch } from "../util";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2018-11-30 21:59:52 -07:00
|
|
|
export const mapStateToProps = (props: Everything): AddPlantProps =>
|
|
|
|
({
|
2017-09-08 06:22:29 -06:00
|
|
|
cropSearchResults: props
|
|
|
|
.resources
|
|
|
|
.consumers
|
|
|
|
.farm_designer
|
2018-11-30 21:59:52 -07:00
|
|
|
.cropSearchResults,
|
|
|
|
dispatch: props.dispatch,
|
|
|
|
openfarmSearch: OFSearch,
|
|
|
|
});
|
|
|
|
|
|
|
|
const AddPlantDescription = ({ svgIcon }: { svgIcon: string | undefined }) =>
|
|
|
|
<div>
|
|
|
|
<img className="crop-drag-info-image"
|
|
|
|
src={svgToUrl(svgIcon)}
|
|
|
|
alt={t("plant icon")}
|
|
|
|
width={100}
|
|
|
|
height={100}
|
|
|
|
onDragStart={setDragIcon(svgIcon)} />
|
|
|
|
<b>{t("Drag and drop")}</b> {t("the icon onto the map or ")}
|
|
|
|
<b>{t("CLICK anywhere within the grid")}</b> {t(`to add the plant
|
|
|
|
to the map. You can add the plant as many times as you need to
|
|
|
|
before pressing DONE to finish.`)}
|
|
|
|
</div>;
|
2017-09-08 06:22:29 -06:00
|
|
|
|
2017-09-19 01:28:38 -06:00
|
|
|
export interface AddPlantProps {
|
|
|
|
cropSearchResults: CropLiveSearchResult[];
|
2018-11-30 21:59:52 -07:00
|
|
|
dispatch: Function;
|
|
|
|
openfarmSearch: OpenfarmSearch;
|
2017-09-19 01:28:38 -06:00
|
|
|
}
|
|
|
|
|
2019-09-19 13:09:00 -06:00
|
|
|
export class RawAddPlant extends React.Component<AddPlantProps, {}> {
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2018-11-30 21:59:52 -07:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.dispatch(searchForCurrentCrop(this.props.openfarmSearch));
|
|
|
|
}
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2018-11-30 21:59:52 -07:00
|
|
|
render() {
|
|
|
|
const { cropSearchResults } = this.props;
|
|
|
|
const { crop, result, basePath, backgroundURL } =
|
|
|
|
getCropHeaderProps({ cropSearchResults });
|
|
|
|
const panelName = "add-plant";
|
|
|
|
return <DesignerPanel
|
|
|
|
panelName={panelName}
|
|
|
|
panelColor={"green"}>
|
|
|
|
<DesignerPanelHeader
|
|
|
|
panelName={panelName}
|
|
|
|
panelColor={"green"}
|
|
|
|
title={result.crop.name}
|
|
|
|
style={{ background: backgroundURL }}
|
|
|
|
descriptionElement={
|
|
|
|
<AddPlantDescription svgIcon={result.crop.svg_icon} />}>
|
|
|
|
<a className="right-button"
|
|
|
|
onClick={() => history.push(basePath + crop)}>
|
|
|
|
{t("Done")}
|
|
|
|
</a>
|
|
|
|
</DesignerPanelHeader>
|
|
|
|
</DesignerPanel>;
|
2017-06-29 12:54:02 -06:00
|
|
|
}
|
|
|
|
}
|
2019-09-19 13:09:00 -06:00
|
|
|
|
|
|
|
export const AddPlant = connect(mapStateToProps)(RawAddPlant);
|