Skip to content

Commit

Permalink
better layout
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Jan 12, 2025
1 parent 290b7e1 commit ea757d5
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions samples/Mvu/GitHubClient/App.fs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -41,8 +39,6 @@ module URlConstants =
[<Literal>]
let githubBaseUrl = "https://api.github.com/users/"

type GitHubError = | Non200Response

module GitHubService =
let private fetchWitHeader (urlString: string) =
let client = new HttpClient()
Expand All @@ -63,20 +59,20 @@ module GitHubService =
return
match response.StatusCode with
| HttpStatusCode.OK -> Ok deserialized
| _ -> Error Non200Response
| _ -> Error "User not found!"
}

module App =
type Msg =
| UserNameChanged of string
| SearchClicked
| UserInfoLoaded of User
| UserInfoNotFound of GitHubError
| UserInfoNotFound of string
| LoadingProgress of float

type Model =
{ UserName: string
UserInfo: RemoteData<string, User> }
UserInfo: RemoteData<User> }

let init () =
{ UserName = ""
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -171,9 +155,13 @@ module App =
})
.centerHorizontal()
| Failure s -> TextBlock(s)
})
.centerHorizontal()

TextBox(model.UserName, UserNameChanged)

Button("Search", SearchClicked).centerHorizontal()
}
}
|> _.centerVertical()
}

let view () =
Expand Down

0 comments on commit ea757d5

Please sign in to comment.