aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/elm/Main.elm3
-rw-r--r--src/client/elm/Model/Action.elm1
-rw-r--r--src/client/elm/Model/Action/SignInAction.elm3
-rw-r--r--src/client/elm/Model/View/SignInView.elm8
-rw-r--r--src/client/elm/Update.elm16
-rw-r--r--src/client/elm/Update/SignIn.elm7
-rw-r--r--src/client/elm/View/Icon.elm7
-rw-r--r--src/client/elm/View/SignIn.elm26
8 files changed, 46 insertions, 25 deletions
diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm
index 2f4acb6..684cd1b 100644
--- a/src/client/elm/Main.elm
+++ b/src/client/elm/Main.elm
@@ -13,7 +13,6 @@ import Time exposing (..)
import Model exposing (Model, initialModel)
import Model.Action exposing (..)
-import Model.Communication exposing (Communication(SignIn))
import Update exposing (update)
@@ -36,7 +35,7 @@ app = StartApp.start
, update = update
, inputs =
[ Signal.map UpdateTime (Time.every 1000)
- , Signal.map (ServerCommunication << SignIn) validateSignIn
+ , Signal.map SignIn validateSignIn
]
}
diff --git a/src/client/elm/Model/Action.elm b/src/client/elm/Model/Action.elm
index 9d5d125..d0fe597 100644
--- a/src/client/elm/Model/Action.elm
+++ b/src/client/elm/Model/Action.elm
@@ -15,6 +15,7 @@ import Model.Communication exposing (Communication)
type Action =
NoOp
| ServerCommunication Communication
+ | SignIn String
| UpdateTime Time
| GoSignInView
| GoLoggedInView Users UserId Payments Payments Int Payers
diff --git a/src/client/elm/Model/Action/SignInAction.elm b/src/client/elm/Model/Action/SignInAction.elm
index 6673c11..ed64c1d 100644
--- a/src/client/elm/Model/Action/SignInAction.elm
+++ b/src/client/elm/Model/Action/SignInAction.elm
@@ -3,4 +3,5 @@ module Model.Action.SignInAction
) where
type SignInAction =
- ErrorLogin String
+ Connecting
+ | ErrorLogin String
diff --git a/src/client/elm/Model/View/SignInView.elm b/src/client/elm/Model/View/SignInView.elm
index 0fbce39..cf7e6b2 100644
--- a/src/client/elm/Model/View/SignInView.elm
+++ b/src/client/elm/Model/View/SignInView.elm
@@ -4,12 +4,12 @@ module Model.View.SignInView
) where
type alias SignInView =
- { login : String
- , result : Maybe (Result String String)
+ { connecting : Bool
+ , error : Maybe String
}
initSignInView : SignInView
initSignInView =
- { login = ""
- , result = Nothing
+ { connecting = False
+ , error = Nothing
}
diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm
index c955f8c..c61e2f5 100644
--- a/src/client/elm/Update.elm
+++ b/src/client/elm/Update.elm
@@ -9,15 +9,20 @@ import Effects exposing (Effects)
import ServerCommunication exposing (sendRequest)
import Model exposing (Model)
+import Model.Translations exposing (getMessage)
import Model.Action exposing (..)
+import Model.Action.SignInAction as SignInAction
import Model.View as V
import Model.View.SignInView exposing (..)
import Model.View.LoggedInView exposing (..)
-import Model.Communication exposing (Communication)
+import Model.Communication as Communication exposing (Communication)
import Update.LoggedIn exposing (updateLoggedIn)
import Update.SignIn exposing (updateSignIn)
+import SimpleHTTP exposing (post)
+import InitViewAction exposing (initViewAction)
+
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
@@ -25,6 +30,15 @@ update action model =
NoOp ->
(model, Effects.none)
+ SignIn assertion ->
+ ( case model.view of
+ V.SignInView signInView -> { model | view = V.SignInView (updateSignIn SignInAction.Connecting signInView) }
+ _ -> model
+ , sendRequest (Communication.SignIn assertion)
+ |> flip Task.onError (always <| Task.succeed (UpdateSignIn (SignInAction.ErrorLogin (getMessage "ErrorSignIn" model.translations))))
+ |> Effects.task
+ )
+
ServerCommunication communication ->
( model
, sendRequest communication
diff --git a/src/client/elm/Update/SignIn.elm b/src/client/elm/Update/SignIn.elm
index c0aaf33..5e8a9bb 100644
--- a/src/client/elm/Update/SignIn.elm
+++ b/src/client/elm/Update/SignIn.elm
@@ -8,5 +8,10 @@ import Model.View.SignInView exposing (..)
updateSignIn : SignInAction -> SignInView -> SignInView
updateSignIn action signInView =
case action of
+ Connecting ->
+ { signInView | connecting = True }
ErrorLogin message ->
- { signInView | result = Just (Err message) }
+ { signInView
+ | error = Just message
+ , connecting = False
+ }
diff --git a/src/client/elm/View/Icon.elm b/src/client/elm/View/Icon.elm
index f22c1a2..9fa5f8a 100644
--- a/src/client/elm/View/Icon.elm
+++ b/src/client/elm/View/Icon.elm
@@ -1,5 +1,6 @@
module View.Icon
( renderIcon
+ , renderSpinIcon
) where
import Html exposing (..)
@@ -10,3 +11,9 @@ renderIcon iconClass =
i
[ class <| "fa fa-fw fa-" ++ iconClass ]
[]
+
+renderSpinIcon : String -> Html
+renderSpinIcon iconClass =
+ i
+ [ class <| "fa fa-fw fa-spin fa-" ++ iconClass ]
+ []
diff --git a/src/client/elm/View/SignIn.elm b/src/client/elm/View/SignIn.elm
index 6d253e7..f662a97 100644
--- a/src/client/elm/View/SignIn.elm
+++ b/src/client/elm/View/SignIn.elm
@@ -16,7 +16,7 @@ import Model.View.SignInView exposing (..)
import Model.Translations exposing (getMessage)
import View.Events exposing (onSubmitPrevDefault)
-import View.Icon exposing (renderIcon)
+import View.Icon exposing (..)
import Persona exposing (operations)
@@ -27,25 +27,19 @@ renderSignIn address model signInView =
[ button
[ onClick operations.address Persona.SignIn ]
[ span [] [ text (getMessage "SignIn" model.translations) ]
- , renderIcon "plug"
+ , if signInView.connecting
+ then renderSpinIcon "refresh"
+ else renderIcon "power-off"
]
- , div
- [ class "result" ]
- [ signInResult model signInView ]
+ , signInResult model signInView
]
signInResult : Model -> SignInView -> Html
signInResult model signInView =
- case signInView.result of
- Just result ->
- case result of
- Ok login ->
- div
- [ class "success" ]
- [ text (getMessage "SignInEmailSent" model.translations) ]
- Err error ->
- div
- [ class "error" ]
- [ text error ]
+ case signInView.error of
+ Just error ->
+ div
+ [ class "error" ]
+ [ text error ]
Nothing ->
text ""