Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Remote Image #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/components-macos/app/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ targets:
- Sources
settings:
HEADER_SEARCH_PATHS: '$(STDLIB_PATH)'
LIBRARY_SEARCH_PATHS: '$(STDLIB_PATH)'
OTHER_LDFLAGS: ' -framework Cocoa'
LIBRARY_SEARCH_PATHS: '$(STDLIB_PATH) /usr/local/lib/'
wokalski marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's depending on gmp?

Unless we want to tell users to install it separately, we'll need to depend on https://github.com/esy-packages/esy-gmp. I'll fix it to give us cflags/libs variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rauanmayemir zarith, a transitive dependency of httpkit.

OTHER_LDFLAGS: ' -framework Cocoa -lgmp'
configFiles:
Debug: Resources/env.xcconfig
Release: Resources/env.xcconfig
Expand Down
30 changes: 8 additions & 22 deletions renderer-macos/lib/components/Image.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,24 @@ let measure = (node, _, _, _, _) => {
{width, height};
};

let getUserDate = (id: int) => {
let https_url = "https://api.github.com/user/" ++ string_of_int(id);
/* Logs.app(m => m("Requesting: %s", https_url)); */

let getImage = (~url: string) => {
switch (
Httpkit_lwt.Client.(
Httpkit.Client.Request.create(
~headers=[("User-Agent", "Reason HttpKit")],
`GET,
https_url |> Uri.of_string,
Uri.of_string(url),
)
|> Https.send
>>= Response.body
|> Lwt_main.run
)
) {
| exception _e =>
/* Logs.err(m => m("%s", Printexc.to_string(e))); */
"asdasd"
| exception _e => "Error"
| Ok(body) =>
let json = Yojson.Basic.from_string(body);
open Yojson.Basic.Util;
let login = json |> member("login") |> to_string;
/* let id = to_int(member("id", json)); */

/* Logs.app(m => m("login: %s", login)); */
/* Logs.app(m => m("id: %d", id)); */

/* Logs.app(m => m("Response: %s", body)); */
login;
| Error(_) =>
Logs.err(m => m("Something went wrong!!!"));
"error";
/* get image instead of random string */
Yojson.Basic.(from_string(body) |> Util.member("login") |> to_string)
| Error(_) => "error"
};
};

Expand All @@ -60,7 +45,8 @@ let make = (~style=[], ~source, ~url, children) =>
make: () => {
let view = BriskImage.make(~source, ());

print_string(url);
/* TODO: handle user image */
print_string(getImage(~url));

{view, layoutNode: Layout.Node.make(~measure, ~style, view)};
},
Expand Down