Adds a route

This commit is contained in:
Roman Galochkin 2020-02-26 13:31:34 +03:00
parent ee0ff39326
commit 8f49870113

View File

@ -1,11 +1,13 @@
type route = type route =
| Model(string) | Model(string)
| FormBuilder
| Home | Home
| NotFound; | NotFound;
let routeToPath = route => let routeToPath = route =>
switch (route) { switch (route) {
| Model(i) => "/m/" ++ i | Model(modelId) => "/m/" ++ modelId
| FormBuilder => "/form-builder"
| Home => "/" | Home => "/"
| _ => "/" | _ => "/"
}; };
@ -66,11 +68,14 @@ module Menu = {
<Item href={routeToPath(Home)} key="home"> {"Home" |> E.ste} </Item> <Item href={routeToPath(Home)} key="home"> {"Home" |> E.ste} </Item>
{Models.all {Models.all
|> E.A.fmap((model: Prop.Model.t) => { |> E.A.fmap((model: Prop.Model.t) => {
<Item href={routeToPath(Model(model.id))} key="ea-funds"> <Item href={routeToPath(Model(model.id))} key={model.id}>
{model.name |> E.ste} {model.name |> E.ste}
</Item> </Item>
}) })
|> ReasonReact.array} |> ReasonReact.array}
<Item href={routeToPath(FormBuilder)} key="form-builder">
{"Form Builder" |> E.ste}
</Item>
</div>; </div>;
}; };
}; };
@ -82,6 +87,7 @@ let make = () => {
let routing = let routing =
switch (url.path) { switch (url.path) {
| ["m", modelId] => Model(modelId) | ["m", modelId] => Model(modelId)
| ["form-builder"] => FormBuilder
| [] => Home | [] => Home
| _ => NotFound | _ => NotFound
}; };
@ -89,11 +95,12 @@ let make = () => {
<div className="w-full max-w-screen-xl mx-auto px-6"> <div className="w-full max-w-screen-xl mx-auto px-6">
<Menu /> <Menu />
{switch (routing) { {switch (routing) {
| Model(n) => | Model(id) =>
switch (Models.getById(n)) { switch (Models.getById(id)) {
| Some(model) => <FormBuilder.ModelForm model /> | Some(model) => <FormBuilder.ModelForm model key=id />
| None => <div> {"Page is not found" |> E.ste} </div> | None => <div> {"Page is not found" |> E.ste} </div>
} }
| FormBuilder => <div> {"Form Builder" |> E.ste} </div>
| Home => <div> {"Welcome" |> E.ste} </div> | Home => <div> {"Welcome" |> E.ste} </div>
| _ => <div> {"Page is not found" |> E.ste} </div> | _ => <div> {"Page is not found" |> E.ste} </div>
}} }}