From 5f6c66e4c3cf02e5b1c0a1fac6036b86be06a992 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 27 Mar 2016 19:44:40 +0200 Subject: Regroup signIn modules --- src/client/elm/SignIn/Action.elm | 9 ++++++ src/client/elm/SignIn/Model.elm | 17 +++++++++++ src/client/elm/SignIn/Update.elm | 31 ++++++++++++++++++++ src/client/elm/SignIn/View.elm | 62 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 src/client/elm/SignIn/Action.elm create mode 100644 src/client/elm/SignIn/Model.elm create mode 100644 src/client/elm/SignIn/Update.elm create mode 100644 src/client/elm/SignIn/View.elm (limited to 'src/client/elm/SignIn') diff --git a/src/client/elm/SignIn/Action.elm b/src/client/elm/SignIn/Action.elm new file mode 100644 index 0000000..1f93f4e --- /dev/null +++ b/src/client/elm/SignIn/Action.elm @@ -0,0 +1,9 @@ +module SignIn.Action + ( Action(..) + ) where + +type Action = + UpdateLogin String + | WaitingServer + | ValidLogin + | ErrorLogin String diff --git a/src/client/elm/SignIn/Model.elm b/src/client/elm/SignIn/Model.elm new file mode 100644 index 0000000..e01de12 --- /dev/null +++ b/src/client/elm/SignIn/Model.elm @@ -0,0 +1,17 @@ +module SignIn.Model + ( Model + , init + ) where + +type alias Model = + { login : String + , waitingServer : Bool + , result : Maybe (Result String String) + } + +init : Maybe String -> Model +init mbSignInError = + { login = "" + , waitingServer = False + , result = Maybe.map Err mbSignInError + } diff --git a/src/client/elm/SignIn/Update.elm b/src/client/elm/SignIn/Update.elm new file mode 100644 index 0000000..f4152a6 --- /dev/null +++ b/src/client/elm/SignIn/Update.elm @@ -0,0 +1,31 @@ +module SignIn.Update + ( update + ) where + +import SignIn.Model exposing (..) +import SignIn.Action exposing (..) + +import Model.Translations exposing (getMessage, Translations) + +update : Translations -> Action -> Model -> Model +update translations action signInView = + case action of + UpdateLogin login -> + { signInView | + login = login + } + WaitingServer -> + { signInView + | waitingServer = True + } + ValidLogin -> + { signInView + | login = "" + , result = Just (Ok (getMessage "SignInEmailSent" translations)) + , waitingServer = False + } + ErrorLogin message -> + { signInView + | result = Just (Err message) + , waitingServer = False + } diff --git a/src/client/elm/SignIn/View.elm b/src/client/elm/SignIn/View.elm new file mode 100644 index 0000000..2f63651 --- /dev/null +++ b/src/client/elm/SignIn/View.elm @@ -0,0 +1,62 @@ +module SignIn.View + ( view + ) where + +import Html as H exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) +import Signal exposing (Address) +import Json.Decode as Json + +import SignIn.Action as SignInAction +import SignIn.Model as SignInModel + +import Update exposing (..) + +import Model exposing (Model) +import Model.Action exposing (..) +import Model.Translations exposing (getMessage) + +import View.Events exposing (onSubmitPrevDefault) +import View.Icon exposing (renderSpinIcon) + +view : Address Action -> Model -> SignInModel.Model -> Html +view address model signInModel = + div + [ class "signIn" ] + [ H.form + [ onSubmitPrevDefault address (SignIn signInModel.login) ] + [ input + [ value signInModel.login + , on "input" targetValue (Signal.message address << UpdateSignIn << SignInAction.UpdateLogin) + , type' "text" + , autocomplete True + ] + [] + , button + [] + [ if signInModel.waitingServer + then renderSpinIcon + else text (getMessage "SignIn" model.translations) + ] + ] + , div + [ class "result" ] + [ signInResult model signInModel ] + ] + +signInResult : Model -> SignInModel.Model -> Html +signInResult model signInModel = + case signInModel.result of + Just result -> + case result of + Ok login -> + div + [ class "success" ] + [ text (getMessage "SignInEmailSent" model.translations) ] + Err error -> + div + [ class "error" ] + [ text (getMessage error model.translations) ] + Nothing -> + text "" -- cgit v1.2.3