Farmbot-Web-App/webpack/route_config.ts

121 lines
3.6 KiB
TypeScript
Raw Normal View History

2018-03-02 10:32:09 -07:00
import { App } from "./app";
import { crashPage } from "./crash_page";
2018-03-05 15:14:35 -07:00
import { RouterState, RedirectFunction, PlainRoute } from "react-router";
2018-03-02 10:32:09 -07:00
/** These methods are a way to determine how to load certain modules
* based on the device (mobile or desktop) for optimization/css purposes.
*/
2018-03-04 15:56:10 -07:00
export function maybeReplaceDesignerModules(next: RouterState,
replace: RedirectFunction) {
2018-03-02 10:32:09 -07:00
if (next.location.pathname === "/app/designer") {
replace(`${next.location.pathname}/plants`);
}
}
2018-03-05 15:14:35 -07:00
/** Create a react router config for a specific route. */
function page<T>(path: string,
getter: () => Promise<T>,
key: keyof T): PlainRoute {
return {
path,
2018-03-05 15:17:25 -07:00
getComponent(_, cb): void {
2018-03-05 15:14:35 -07:00
const ok = (mod: T) => cb(undefined, mod[key] as any);
const no = (e: object) => cb(undefined, crashPage(e));
2018-03-05 15:17:25 -07:00
/** Whatever you do, make sure this function stays void or you will get a
* bunch of silent errors. - RC*/
getter().then(ok, no);
}
};
}
2018-03-05 14:36:06 -07:00
2018-03-05 13:13:03 -07:00
const controlsRoute: PlainRoute =
2018-03-05 15:14:35 -07:00
page("app/controls",
() => import("./controls/controls"), "Controls");
2018-03-05 13:13:03 -07:00
export const designerRoutes: PlainRoute = {
path: "app/designer",
2018-03-05 13:13:03 -07:00
getComponent(_, cb) {
import("./farm_designer/index")
.then(module => cb(undefined, module.FarmDesigner))
2018-03-02 10:32:09 -07:00
.catch((e: object) => cb(undefined, crashPage(e)));
},
childRoutes: [
page("plants",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/plant_inventory"),
"Plants"),
page("plants/crop_search",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/crop_catalog"),
"CropCatalog"),
page("plants/crop_search/:crop",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/crop_info"),
"CropInfo"),
page("plants/crop_search/:crop/add",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/add_plant"),
"AddPlant"),
page("plants/select",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/select_plants"),
"SelectPlants"),
page("plants/move_to",
() => import("./farm_designer/plants/move_to"),
"MoveTo"),
2018-03-07 13:15:26 -07:00
page("plants/create_point",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/create_points"),
"CreatePoints"),
page("plants/:plant_id",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/plant_info"),
"PlantInfo"),
page("plants/:plant_id/edit",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/plants/edit_plant_info"),
"EditPlantInfo"),
page("farm_events",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/farm_events/farm_events"),
"FarmEvents"),
page("farm_events/add",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/farm_events/add_farm_event"),
"AddFarmEvent"),
page("farm_events/:farm_event_id",
2018-03-05 15:14:35 -07:00
() => import("./farm_designer/farm_events/edit_farm_event"),
"EditFarmEvent"),
]
2018-03-02 10:32:09 -07:00
};
2018-03-05 13:13:03 -07:00
export const topLevelRoutes: PlainRoute = {
2018-03-02 10:32:09 -07:00
component: App,
indexRoute: controlsRoute,
childRoutes: [
2018-03-05 15:14:35 -07:00
page("app/account",
() => import("./account/index"),
"Account"),
2018-03-02 10:32:09 -07:00
controlsRoute,
2018-03-05 15:14:35 -07:00
page("app/device",
() => import("./devices/devices"),
"Devices"),
page("app/farmware",
() => import("./farmware/index"),
"FarmwarePage"),
2018-03-05 14:36:06 -07:00
designerRoutes,
2018-03-05 15:14:35 -07:00
page("app/regimens",
() => import("./regimens/index"),
"Regimens"),
page("app/regimens/:regimen",
() => import("./regimens/index"),
"Regimens"),
page("app/sequences",
() => import("./sequences/sequences"),
"Sequences"),
page("app/sequences/:sequence",
() => import("./sequences/sequences"),
"Sequences"),
page("app/tools",
() => import("./tools/index"),
"Tools"),
page("app/logs",
() => import("./logs/index"),
"Logs"),
page("*",
() => import("./404"),
"FourOhFour"),
2018-03-02 10:32:09 -07:00
]
};