2018-08-01 18:13:44 -06:00
|
|
|
import * as React from "react";
|
|
|
|
import { Everything } from "../../interfaces";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { history } from "../../history";
|
2019-11-22 12:57:22 -07:00
|
|
|
import { unselectPlant } from "../map/actions";
|
2018-08-01 18:13:44 -06:00
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
selectAllSavedGardens, selectAllPlantTemplates, selectAllPlantPointers,
|
2018-08-01 18:13:44 -06:00
|
|
|
} from "../../resources/selectors";
|
2018-09-13 16:00:14 -06:00
|
|
|
import { SavedGardenList } from "./garden_list";
|
2019-11-06 10:01:05 -07:00
|
|
|
import { SavedGardensProps, SavedGardensState } from "./interfaces";
|
2018-09-13 16:00:14 -06:00
|
|
|
import { closeSavedGarden } from "./actions";
|
2018-11-30 21:59:52 -07:00
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
DesignerPanel, DesignerPanelContent, DesignerPanelTop,
|
2019-12-10 13:09:52 -07:00
|
|
|
} from "../designer_panel";
|
2019-10-25 09:33:33 -06:00
|
|
|
import { DesignerNavTabs, Panel } from "../panel_header";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2019-11-06 10:01:05 -07:00
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
EmptyStateWrapper, EmptyStateGraphic,
|
2019-11-06 10:01:05 -07:00
|
|
|
} from "../../ui/empty_state_wrapper";
|
|
|
|
import { Content } from "../../constants";
|
2020-04-13 19:15:11 -06:00
|
|
|
import { SearchField } from "../../ui/search_field";
|
2018-08-01 18:13:44 -06:00
|
|
|
|
2018-11-14 17:36:52 -07:00
|
|
|
export const mapStateToProps = (props: Everything): SavedGardensProps => ({
|
|
|
|
savedGardens: selectAllSavedGardens(props.resources.index),
|
|
|
|
plantTemplates: selectAllPlantTemplates(props.resources.index),
|
|
|
|
dispatch: props.dispatch,
|
|
|
|
plantPointerCount: selectAllPlantPointers(props.resources.index).length,
|
|
|
|
openedSavedGarden: props.resources.consumers.farm_designer.openedSavedGarden,
|
|
|
|
});
|
2018-08-01 18:13:44 -06:00
|
|
|
|
2019-11-06 10:01:05 -07:00
|
|
|
export class RawSavedGardens
|
|
|
|
extends React.Component<SavedGardensProps, SavedGardensState> {
|
|
|
|
state: SavedGardensState = { searchTerm: "" };
|
2018-08-01 18:13:44 -06:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
unselectPlant(this.props.dispatch)();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-10-25 09:33:33 -06:00
|
|
|
return <DesignerPanel panelName={"saved-garden"} panel={Panel.SavedGardens}>
|
2019-10-10 11:43:44 -06:00
|
|
|
<DesignerNavTabs />
|
2019-11-06 10:01:05 -07:00
|
|
|
<DesignerPanelContent panelName={"saved-garden"}>
|
|
|
|
<DesignerPanelTop
|
|
|
|
panel={Panel.SavedGardens}
|
|
|
|
linkTo={"/app/designer/gardens/add"}
|
|
|
|
title={t("Add garden")}>
|
2020-04-13 19:15:11 -06:00
|
|
|
<SearchField searchTerm={this.state.searchTerm}
|
|
|
|
placeholder={t("Search your gardens...")}
|
|
|
|
onChange={searchTerm => this.setState({ searchTerm })} />
|
2019-11-06 10:01:05 -07:00
|
|
|
</DesignerPanelTop>
|
2019-08-23 15:18:28 -06:00
|
|
|
<EmptyStateWrapper
|
|
|
|
notEmpty={this.props.savedGardens.length > 0}
|
|
|
|
title={t("No saved gardens yet.")}
|
2019-11-06 10:01:05 -07:00
|
|
|
text={t(Content.NO_GARDENS)}
|
2019-08-23 15:18:28 -06:00
|
|
|
colorScheme="gardens"
|
|
|
|
graphic={EmptyStateGraphic.plants}>
|
2019-11-06 10:01:05 -07:00
|
|
|
<SavedGardenList {...this.props} searchTerm={this.state.searchTerm} />
|
2019-08-23 15:18:28 -06:00
|
|
|
</EmptyStateWrapper>
|
2018-11-30 21:59:52 -07:00
|
|
|
</DesignerPanelContent>
|
|
|
|
</DesignerPanel>;
|
2018-08-01 18:13:44 -06:00
|
|
|
}
|
|
|
|
}
|
2018-08-27 13:29:01 -06:00
|
|
|
|
2018-11-14 17:36:52 -07:00
|
|
|
/** Sticky an indicator and actions menu when a SavedGarden is open. */
|
2018-09-13 16:00:14 -06:00
|
|
|
export const SavedGardenHUD = (props: { dispatch: Function }) =>
|
|
|
|
<div className="saved-garden-indicator">
|
|
|
|
<label>{t("Viewing saved garden")}</label>
|
|
|
|
<button className="fb-button gray"
|
2020-02-28 09:34:28 -07:00
|
|
|
title={t("open saved gardens panel")}
|
2019-11-06 10:01:05 -07:00
|
|
|
onClick={() => history.push("/app/designer/gardens")}>
|
2018-09-13 16:00:14 -06:00
|
|
|
{t("Menu")}
|
|
|
|
</button>
|
|
|
|
<button className="fb-button green"
|
2020-02-28 09:34:28 -07:00
|
|
|
title={t("open plants panel")}
|
2018-09-21 16:22:17 -06:00
|
|
|
onClick={() => {
|
|
|
|
history.push("/app/designer/plants");
|
|
|
|
unselectPlant(props.dispatch)();
|
|
|
|
}}>
|
2018-09-13 16:00:14 -06:00
|
|
|
{t("Edit")}
|
|
|
|
</button>
|
|
|
|
<button className="fb-button red"
|
2020-02-28 09:34:28 -07:00
|
|
|
title={t("close saved garden")}
|
2018-09-13 16:00:14 -06:00
|
|
|
onClick={() => props.dispatch(closeSavedGarden())}>
|
|
|
|
{t("Exit")}
|
|
|
|
</button>
|
|
|
|
</div>;
|
2019-09-19 13:09:00 -06:00
|
|
|
|
|
|
|
export const SavedGardens = connect(mapStateToProps)(RawSavedGardens);
|