Commit 79d448b2 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Refactored rendering

parent 9f7f0e7ebb24
......@@ -108,7 +108,7 @@ let renderLoadedInitialSchema =
| Hypermedia.ArrayType(_) => <div> (ReasonReact.string("Loading")) </div>
| Hypermedia.ObjectType(_) => <div> (ReasonReact.string("Loading")) </div>
| Hypermedia.RootType(rootSchema) =>
Root.renderRoot(self, goto, rootSchema)
Rendering.renderRoot(self, goto, rootSchema)
| Hypermedia.PrimitiveType(ptype) =>
<div> (ReasonReact.string(ptype)) </div>
};
......@@ -119,7 +119,21 @@ let renderLoadedWithData =
schema: Hypermedia.schemaType,
data: Hypermedia.entityValue,
) =>
<div />;
switch (schema) {
| Hypermedia.ArrayType(arrayType) =>
let values =
switch (data) {
| Hypermedia.ValueArray(x) => x
| _ => []
};
Rendering.renderCollection(self, goto, arrayType, values);
| Hypermedia.ObjectType(_) =>
<div> (ReasonReact.string("TODO: Display the object")) </div>
| Hypermedia.RootType(rootSchema) =>
Rendering.renderRoot(self, goto, rootSchema)
| Hypermedia.PrimitiveType(ptype) =>
<div> (ReasonReact.string(ptype)) </div>
};
let make = _children => {
...component,
......
......@@ -28,4 +28,50 @@ let renderRoot =
|> Array.of_list
|> ReasonReact.array
)
</div>;
\ No newline at end of file
</div>;
let renderCollection =
(
self: ReasonReact.self(_, _, _),
goto,
schema: Hypermedia.schemaArrayType,
data: list(Hypermedia.entityValue),
) => {
let schema_title =
switch (schema.title) {
| Some(x) => x
| None => ""
};
let schema_items =
switch (schema.items) {
| ObjectType(t) => t
| _ => {links: [], properties: [], title: None}
};
let link_href =
switch (List.nth(schema_items.links, 0).href) {
| Some(x) => x
| None => "{id}"
};
<div>
<h1> (ReasonReact.string(schema_title)) </h1>
(
data
|> List.map((entity: Hypermedia.entityValue) => {
let obj = Hypermedia.as_object(entity);
let id = Hypermedia.as_string(Hypermedia.get(obj, "id"));
let title = Hypermedia.as_string(Hypermedia.get(obj, "title"));
<li>
<a
href=link_href
onClick=(
self.handle((event, self) => goto(event, self, link_href))
)>
(ReasonReact.string(title))
</a>
</li>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>;
};
\ No newline at end of file
......@@ -62,8 +62,19 @@ and entityValue =
| ValueArray of entityValue list
| ValueObject of entity
let get entity key = begin
(List.find (fun p -> p.name = key) entity.properties).value
end
let as_string entityValue =
match entityValue with
| ValuePrimitive x -> x
| _ -> ""
let as_object entityValue =
match entityValue with
| ValueObject x -> x
| _ -> {properties= [];}
module Decode = struct
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment