2020-02-26 09:11:06 +00:00
|
|
|
type route =
|
2020-02-26 09:30:37 +00:00
|
|
|
| Model(string)
|
2020-02-26 12:21:30 +00:00
|
|
|
| DistBuilder
|
2020-02-27 12:09:04 +00:00
|
|
|
| DistBuilder2
|
2020-03-24 00:04:48 +00:00
|
|
|
| DistBuilder3
|
2020-02-26 09:11:06 +00:00
|
|
|
| Home
|
|
|
|
| NotFound;
|
|
|
|
|
|
|
|
let routeToPath = route =>
|
|
|
|
switch (route) {
|
2020-02-26 10:31:34 +00:00
|
|
|
| Model(modelId) => "/m/" ++ modelId
|
2020-02-26 12:21:30 +00:00
|
|
|
| DistBuilder => "/dist-builder"
|
2020-02-27 12:09:04 +00:00
|
|
|
| DistBuilder2 => "/dist-builder2"
|
2020-03-24 00:04:48 +00:00
|
|
|
| DistBuilder3 => "/dist-builder3"
|
2020-02-26 09:11:06 +00:00
|
|
|
| Home => "/"
|
|
|
|
| _ => "/"
|
|
|
|
};
|
|
|
|
|
2020-02-26 09:36:26 +00:00
|
|
|
module Models = {
|
|
|
|
let all = [|
|
|
|
|
EAFunds.Interface.model,
|
|
|
|
GlobalCatastrophe.Interface.model,
|
|
|
|
Human.Interface.model,
|
|
|
|
|];
|
|
|
|
let getById = id => E.A.getBy(all, r => r.id == id);
|
|
|
|
};
|
|
|
|
|
2020-02-26 09:11:06 +00:00
|
|
|
module Menu = {
|
|
|
|
module Styles = {
|
|
|
|
open Css;
|
|
|
|
let menu =
|
|
|
|
style([
|
|
|
|
position(`relative),
|
|
|
|
marginTop(em(0.25)),
|
|
|
|
marginBottom(em(0.25)),
|
|
|
|
selector(
|
|
|
|
"a",
|
|
|
|
[
|
|
|
|
borderRadius(em(0.25)),
|
|
|
|
display(`inlineBlock),
|
|
|
|
backgroundColor(`hex("eee")),
|
|
|
|
padding(em(1.)),
|
|
|
|
cursor(`pointer),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
selector("a:hover", [backgroundColor(`hex("bfcad4"))]),
|
|
|
|
selector("a:hover", [backgroundColor(`hex("bfcad4"))]),
|
|
|
|
selector(
|
|
|
|
"a:not(:first-child):not(:last-child)",
|
|
|
|
[marginRight(em(0.25)), marginLeft(em(0.25))],
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
|
|
|
|
module Item = {
|
|
|
|
[@react.component]
|
|
|
|
let make = (~href, ~children) => {
|
|
|
|
<a
|
|
|
|
href
|
|
|
|
onClick={e => {
|
|
|
|
e->ReactEvent.Synthetic.preventDefault;
|
|
|
|
ReasonReactRouter.push(href);
|
|
|
|
}}>
|
|
|
|
children
|
|
|
|
</a>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
[@react.component]
|
|
|
|
let make = () => {
|
|
|
|
<div className=Styles.menu>
|
|
|
|
<Item href={routeToPath(Home)} key="home"> {"Home" |> E.ste} </Item>
|
2020-02-26 09:36:26 +00:00
|
|
|
{Models.all
|
|
|
|
|> E.A.fmap((model: Prop.Model.t) => {
|
2020-02-26 10:31:34 +00:00
|
|
|
<Item href={routeToPath(Model(model.id))} key={model.id}>
|
2020-02-26 09:36:26 +00:00
|
|
|
{model.name |> E.ste}
|
|
|
|
</Item>
|
|
|
|
})
|
|
|
|
|> ReasonReact.array}
|
2020-02-26 12:21:30 +00:00
|
|
|
<Item href={routeToPath(DistBuilder)} key="dist-builder">
|
|
|
|
{"Dist Builder" |> E.ste}
|
2020-02-26 10:31:34 +00:00
|
|
|
</Item>
|
2020-03-03 06:33:33 +00:00
|
|
|
<Item href={routeToPath(DistBuilder2)} key="dist-builder-2">
|
2020-02-27 12:09:04 +00:00
|
|
|
{"Dist Builder 2" |> E.ste}
|
|
|
|
</Item>
|
2020-03-24 00:04:48 +00:00
|
|
|
<Item href={routeToPath(DistBuilder3)} key="dist-builder-3">
|
|
|
|
{"Dist Builder 3" |> E.ste}
|
|
|
|
</Item>
|
2020-02-26 09:11:06 +00:00
|
|
|
</div>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-10 20:37:12 +00:00
|
|
|
[@react.component]
|
|
|
|
let make = () => {
|
2020-02-26 09:11:06 +00:00
|
|
|
let url = ReasonReactRouter.useUrl();
|
|
|
|
|
|
|
|
let routing =
|
|
|
|
switch (url.path) {
|
2020-02-26 09:30:37 +00:00
|
|
|
| ["m", modelId] => Model(modelId)
|
2020-02-26 12:21:30 +00:00
|
|
|
| ["dist-builder"] => DistBuilder
|
2020-02-27 12:09:04 +00:00
|
|
|
| ["dist-builder2"] => DistBuilder2
|
2020-03-24 00:04:48 +00:00
|
|
|
| ["dist-builder3"] => DistBuilder3
|
2020-02-26 09:11:06 +00:00
|
|
|
| [] => Home
|
|
|
|
| _ => NotFound
|
|
|
|
};
|
|
|
|
|
2020-02-10 20:37:12 +00:00
|
|
|
<div className="w-full max-w-screen-xl mx-auto px-6">
|
2020-02-26 09:11:06 +00:00
|
|
|
<Menu />
|
|
|
|
{switch (routing) {
|
2020-02-26 10:31:34 +00:00
|
|
|
| Model(id) =>
|
|
|
|
switch (Models.getById(id)) {
|
|
|
|
| Some(model) => <FormBuilder.ModelForm model key=id />
|
2020-02-26 09:36:26 +00:00
|
|
|
| None => <div> {"Page is not found" |> E.ste} </div>
|
|
|
|
}
|
2020-02-26 12:21:30 +00:00
|
|
|
| DistBuilder => <DistBuilder />
|
2020-02-27 12:09:04 +00:00
|
|
|
| DistBuilder2 => <DistBuilder2 />
|
2020-03-24 00:04:48 +00:00
|
|
|
| DistBuilder3 => <DistBuilder3 />
|
2020-02-26 09:11:06 +00:00
|
|
|
| Home => <div> {"Welcome" |> E.ste} </div>
|
|
|
|
| _ => <div> {"Page is not found" |> E.ste} </div>
|
|
|
|
}}
|
2020-02-10 20:37:12 +00:00
|
|
|
</div>;
|
2020-03-24 00:04:48 +00:00
|
|
|
};
|