Web UI: Enable clicking login button to move to rest of the app. Next step submit to server
This commit is contained in:
1 parent
2e4dbd4431
commit
03e317f1c5
2 files changed
+15
-6
No files matched your search
@@ -3,6 +3,7 @@ module Login
|
||||
open Fable.Core.JsInterop
|
||||
open Fable.Helpers.React
|
||||
open Fable.Helpers.React.Props
|
||||
open Elmish
|
||||
|
||||
//
|
||||
// Types
|
||||
@@ -12,27 +13,31 @@ type Message =
|
||||
| Password of string
|
||||
| Submit
|
||||
| Help
|
||||
| LoginFailure of string
|
||||
| LoginSuccess
|
||||
|
||||
//
|
||||
// Model
|
||||
type Model = {
|
||||
user : string
|
||||
password : string
|
||||
error : string
|
||||
}
|
||||
let init() =
|
||||
{ user = ""; password = "" }, []
|
||||
{ user = ""; password = ""; error = "" }, []
|
||||
|
||||
let update msg model =
|
||||
match msg with
|
||||
| Username u -> { model with user = u }, []
|
||||
| Password p -> { model with password = p }, []
|
||||
| Username u -> { model with user = u; error = "" }, Cmd.Empty
|
||||
| Password p -> { model with password = p; error = "" }, Cmd.Empty
|
||||
| Help ->
|
||||
printfn "No help for you"
|
||||
model, []
|
||||
model, Cmd.Empty
|
||||
| Submit ->
|
||||
printfn "Login with %s %s" model.user model.password
|
||||
model, []
|
||||
if (model.user = "bts") then
|
||||
model, Elmish.Cmd.ofMsg LoginSuccess
|
||||
else
|
||||
{ model with error = "Please use username 'bts'" }, Cmd.Empty
|
||||
|
||||
//
|
||||
// View
|
||||
@@ -65,6 +70,7 @@ let root model dispatch =
|
||||
Type "password"
|
||||
OnChange (handler Password)
|
||||
Placeholder "Password" ] ] ]
|
||||
div [] [str model.error]
|
||||
button [OnClick (fun _ -> dispatch Submit)
|
||||
Class "button is-block is-info is-large is-fullwidth" ] [
|
||||
str "Login" ] ] ]
|
||||
|
||||
@@ -29,6 +29,9 @@ let update msg model =
|
||||
| HomeMsg msg, HomeModel m ->
|
||||
let (home, homeCmd) = Home.State.update msg m
|
||||
{ model with pageModel = HomeModel home }, Cmd.map HomeMsg homeCmd
|
||||
| LoginMsg Login.LoginSuccess, _ ->
|
||||
let (home, homeCmd) = Home.State.init()
|
||||
{ model with pageModel = HomeModel home }, Cmd.map HomeMsg homeCmd
|
||||
| LoginMsg msg, LoginModel l ->
|
||||
let (lmodel, lcmd) = Login.update msg l
|
||||
{ model with pageModel = LoginModel lmodel }, Cmd.map LoginMsg lcmd
|
||||
|
||||
Reference in new issue
Block a user