2020-04-02 10:53:55 -06:00
|
|
|
import { CropLiveSearchResult, DrawnPointPayl, DrawnWeedPayl } from "./interfaces";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { generateReducer } from "../redux/generate_reducer";
|
2018-01-20 07:46:44 -07:00
|
|
|
import { DesignerState, HoveredPlantPayl } from "./interfaces";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { cloneDeep } from "lodash";
|
2020-04-02 10:53:55 -06:00
|
|
|
import { TaggedResource, PointType } from "farmbot";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { Actions } from "../constants";
|
2017-12-30 02:41:51 -07:00
|
|
|
import { BotPosition } from "../devices/interfaces";
|
2019-10-30 12:25:29 -06:00
|
|
|
import { PointGroupSortType } from "farmbot/dist/resources/api_resources";
|
2020-04-02 10:53:55 -06:00
|
|
|
import { UUID } from "../resources/interfaces";
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2019-12-10 12:53:20 -07:00
|
|
|
export const initialState: DesignerState = {
|
2020-04-02 10:53:55 -06:00
|
|
|
selectedPoints: undefined,
|
|
|
|
selectionPointType: undefined,
|
2017-06-29 12:54:02 -06:00
|
|
|
hoveredPlant: {
|
|
|
|
plantUUID: undefined,
|
|
|
|
icon: ""
|
|
|
|
},
|
2019-11-07 12:17:50 -07:00
|
|
|
hoveredPoint: undefined,
|
2018-01-29 23:17:54 -07:00
|
|
|
hoveredPlantListItem: undefined,
|
2019-12-30 09:08:48 -07:00
|
|
|
hoveredToolSlot: undefined,
|
2017-06-29 12:54:02 -06:00
|
|
|
cropSearchQuery: "",
|
2017-12-30 02:41:51 -07:00
|
|
|
cropSearchResults: [],
|
2018-11-28 15:29:46 -07:00
|
|
|
cropSearchInProgress: false,
|
2017-12-30 02:41:51 -07:00
|
|
|
chosenLocation: { x: undefined, y: undefined, z: undefined },
|
2020-04-02 10:53:55 -06:00
|
|
|
drawnPoint: undefined,
|
|
|
|
drawnWeed: undefined,
|
2018-09-13 16:00:14 -06:00
|
|
|
openedSavedGarden: undefined,
|
2019-10-30 12:25:29 -06:00
|
|
|
tryGroupSortType: undefined,
|
2020-03-13 15:21:44 -06:00
|
|
|
editGroupAreaInMap: false,
|
2017-06-29 12:54:02 -06:00
|
|
|
};
|
|
|
|
|
2019-12-10 12:53:20 -07:00
|
|
|
export const designer = generateReducer<DesignerState>(initialState)
|
2017-06-29 12:54:02 -06:00
|
|
|
.add<string>(Actions.SEARCH_QUERY_CHANGE, (s, { payload }) => {
|
2018-11-28 15:29:46 -07:00
|
|
|
s.cropSearchInProgress = true;
|
2017-08-28 05:49:13 -06:00
|
|
|
const state = cloneDeep(s);
|
2017-06-29 12:54:02 -06:00
|
|
|
state.cropSearchQuery = payload;
|
|
|
|
return state;
|
|
|
|
})
|
2018-11-30 21:59:52 -07:00
|
|
|
.add<boolean>(Actions.OF_SEARCH_RESULTS_START, (s) => {
|
|
|
|
s.cropSearchInProgress = true;
|
|
|
|
return s;
|
|
|
|
})
|
2018-11-28 15:29:46 -07:00
|
|
|
.add<boolean>(Actions.OF_SEARCH_RESULTS_NO, (s) => {
|
|
|
|
s.cropSearchInProgress = false;
|
|
|
|
return s;
|
|
|
|
})
|
2020-04-02 10:53:55 -06:00
|
|
|
.add<UUID[] | undefined>(Actions.SELECT_POINT, (s, { payload }) => {
|
|
|
|
s.selectedPoints = payload;
|
2017-06-29 12:54:02 -06:00
|
|
|
return s;
|
|
|
|
})
|
2020-04-02 10:53:55 -06:00
|
|
|
.add<PointType[] | undefined>(
|
|
|
|
Actions.SET_SELECTION_POINT_TYPE, (s, { payload }) => {
|
|
|
|
s.selectionPointType = payload;
|
|
|
|
return s;
|
|
|
|
})
|
2017-06-29 12:54:02 -06:00
|
|
|
.add<HoveredPlantPayl>(Actions.TOGGLE_HOVERED_PLANT, (s, { payload }) => {
|
|
|
|
s.hoveredPlant = payload;
|
|
|
|
return s;
|
|
|
|
})
|
2018-01-29 23:17:54 -07:00
|
|
|
.add<string | undefined>(Actions.HOVER_PLANT_LIST_ITEM, (s, { payload }) => {
|
|
|
|
s.hoveredPlantListItem = payload;
|
|
|
|
return s;
|
|
|
|
})
|
2019-11-07 12:17:50 -07:00
|
|
|
.add<string | undefined>(Actions.TOGGLE_HOVERED_POINT, (s, { payload }) => {
|
|
|
|
s.hoveredPoint = payload;
|
|
|
|
return s;
|
|
|
|
})
|
2019-12-30 09:08:48 -07:00
|
|
|
.add<string | undefined>(Actions.HOVER_TOOL_SLOT, (s, { payload }) => {
|
|
|
|
s.hoveredToolSlot = payload;
|
|
|
|
return s;
|
|
|
|
})
|
2020-04-02 10:53:55 -06:00
|
|
|
.add<DrawnPointPayl | undefined>(
|
|
|
|
Actions.SET_DRAWN_POINT_DATA, (s, { payload }) => {
|
|
|
|
const { color } = (!payload || !payload.color) ?
|
|
|
|
(s.drawnPoint || { color: "green" }) : payload;
|
|
|
|
s.drawnPoint = payload;
|
|
|
|
s.drawnPoint && (s.drawnPoint.color = color);
|
|
|
|
return s;
|
|
|
|
})
|
|
|
|
.add<DrawnWeedPayl | undefined>(
|
|
|
|
Actions.SET_DRAWN_WEED_DATA, (s, { payload }) => {
|
2020-02-07 16:05:16 -07:00
|
|
|
const { color } = (!payload || !payload.color) ?
|
2020-04-02 10:53:55 -06:00
|
|
|
(s.drawnWeed || { color: "red" }) : payload;
|
|
|
|
s.drawnWeed = payload;
|
|
|
|
s.drawnWeed && (s.drawnWeed.color = color);
|
2020-02-07 16:05:16 -07:00
|
|
|
return s;
|
|
|
|
})
|
2017-06-29 12:54:02 -06:00
|
|
|
.add<CropLiveSearchResult[]>(Actions.OF_SEARCH_RESULTS_OK, (s, a) => {
|
2018-04-23 09:52:56 -06:00
|
|
|
s.cropSearchResults = a.payload;
|
2018-11-28 15:29:46 -07:00
|
|
|
s.cropSearchInProgress = false;
|
2018-04-23 09:52:56 -06:00
|
|
|
return s;
|
2017-06-29 12:54:02 -06:00
|
|
|
})
|
2018-03-13 16:37:24 -06:00
|
|
|
.add<TaggedResource>(Actions.DESTROY_RESOURCE_OK, (s) => {
|
2020-04-02 10:53:55 -06:00
|
|
|
s.selectedPoints = undefined;
|
2017-09-27 18:04:45 -06:00
|
|
|
s.hoveredPlant = { plantUUID: undefined, icon: "" };
|
2017-06-29 12:54:02 -06:00
|
|
|
return s;
|
2017-12-30 02:41:51 -07:00
|
|
|
})
|
|
|
|
.add<BotPosition>(Actions.CHOOSE_LOCATION, (s, { payload }) => {
|
|
|
|
s.chosenLocation = payload;
|
|
|
|
return s;
|
2018-09-13 16:00:14 -06:00
|
|
|
})
|
|
|
|
.add<string | undefined>(Actions.CHOOSE_SAVED_GARDEN, (s, { payload }) => {
|
|
|
|
s.openedSavedGarden = payload;
|
|
|
|
return s;
|
2019-10-30 12:25:29 -06:00
|
|
|
})
|
|
|
|
.add<PointGroupSortType | undefined>(Actions.TRY_SORT_TYPE, (s, { payload }) => {
|
|
|
|
s.tryGroupSortType = payload;
|
|
|
|
return s;
|
2020-03-13 15:21:44 -06:00
|
|
|
})
|
|
|
|
.add<boolean>(Actions.EDIT_GROUP_AREA_IN_MAP, (s, { payload }) => {
|
|
|
|
s.editGroupAreaInMap = payload;
|
|
|
|
return s;
|
2017-06-29 12:54:02 -06:00
|
|
|
});
|