From ea757d57a65efb615cf3466521d12982b2d5b9a6 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 12 Jan 2025 15:58:19 +0000 Subject: [PATCH] better layout --- samples/Mvu/GitHubClient/App.fs | 44 ++++++++++++--------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/samples/Mvu/GitHubClient/App.fs b/samples/Mvu/GitHubClient/App.fs index 14431fe2..80674ce3 100644 --- a/samples/Mvu/GitHubClient/App.fs +++ b/samples/Mvu/GitHubClient/App.fs @@ -1,9 +1,7 @@ namespace GitHubClient open System.Diagnostics -open System.IO open Avalonia.Markup.Xaml.Styling -open Avalonia.Themes.Fluent open Fabulous open Fabulous.Avalonia open System.Net @@ -15,11 +13,11 @@ open System.Text.Json open type Fabulous.Avalonia.View module Models = - type RemoteData<'e, 't> = + type RemoteData<'T> = | NotAsked | Loading - | Content of 't - | Failure of 'e + | Content of 'T + | Failure of string type User = { login: string @@ -41,8 +39,6 @@ module URlConstants = [] let githubBaseUrl = "https://api.github.com/users/" -type GitHubError = | Non200Response - module GitHubService = let private fetchWitHeader (urlString: string) = let client = new HttpClient() @@ -63,7 +59,7 @@ module GitHubService = return match response.StatusCode with | HttpStatusCode.OK -> Ok deserialized - | _ -> Error Non200Response + | _ -> Error "User not found!" } module App = @@ -71,12 +67,12 @@ module App = | UserNameChanged of string | SearchClicked | UserInfoLoaded of User - | UserInfoNotFound of GitHubError + | UserInfoNotFound of string | LoadingProgress of float type Model = { UserName: string - UserInfo: RemoteData } + UserInfo: RemoteData } let init () = { UserName = "" @@ -96,19 +92,13 @@ module App = match msg with | UserNameChanged userName -> { model with UserName = userName }, Cmd.none - | SearchClicked -> - { model with - UserInfo = RemoteData.Loading }, - Cmd.OfTask.msg(getUserInfo model.UserName) + | SearchClicked -> { model with UserInfo = Loading }, Cmd.OfTask.msg(getUserInfo model.UserName) - | UserInfoLoaded user -> - { model with - UserInfo = RemoteData.Content(user) }, - Cmd.none + | UserInfoLoaded user -> { model with UserInfo = Content(user) }, Cmd.none | UserInfoNotFound _ -> { model with - UserInfo = RemoteData.Failure("User not found!") }, + UserInfo = Failure("User not found!") }, Cmd.none | LoadingProgress _ -> model, Cmd.none @@ -130,13 +120,7 @@ module App = let! model = Context.Mvu program Grid() { - (VStack() { - Image("avares://GitHubClient/Assets/github-icon.png") - .size(100., 100.) - - TextBox(model.UserName, UserNameChanged) - Button("Search", SearchClicked) - + VStack() { match model.UserInfo with | NotAsked -> () | Loading -> ProgressBar(0., 1., 0.5, LoadingProgress) @@ -171,9 +155,13 @@ module App = }) .centerHorizontal() | Failure s -> TextBlock(s) - }) - .centerHorizontal() + + TextBox(model.UserName, UserNameChanged) + + Button("Search", SearchClicked).centerHorizontal() + } } + |> _.centerVertical() } let view () =