Farmbot-Web-App/frontend/farmware/set_active_farmware_by_name.ts

20 lines
708 B
TypeScript
Raw Permalink Normal View History

2018-06-21 15:04:21 -06:00
import { store } from "../redux/store";
2019-04-26 16:11:33 -06:00
import { lastUrlChunk } from "../util";
2018-06-21 15:04:21 -06:00
import { Actions } from "../constants";
2019-04-26 16:11:33 -06:00
import { farmwareUrlFriendly } from "./index";
2018-06-21 15:04:21 -06:00
export function setActiveFarmwareByName(farmwareNames: (string | undefined)[]) {
2019-04-26 16:11:33 -06:00
const chunk = farmwareUrlFriendly(lastUrlChunk());
if (chunk == "farmware") { return; }
2018-06-21 15:04:21 -06:00
farmwareNames.map(payload => {
if (payload) {
2019-04-26 16:11:33 -06:00
const urlName = farmwareUrlFriendly(payload);
const directMatch = chunk === urlName;
const altMatch = chunk === "weed_detector" && urlName === "plant_detection";
const match = directMatch || altMatch;
match && store.dispatch({ type: Actions.SELECT_FARMWARE, payload });
2018-06-21 15:04:21 -06:00
}
});
}