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/LoggedIn/Action.elm | 0 src/client/elm/LoggedIn/Model.elm | 0 src/client/elm/LoggedIn/Update.elm | 0 src/client/elm/LoggedIn/View.elm | 0 src/client/elm/Model.elm | 5 ++- src/client/elm/Model/Action.elm | 5 ++- src/client/elm/Model/Action/SignInAction.elm | 9 ---- src/client/elm/Model/View.elm | 5 ++- src/client/elm/Model/View/SignInView.elm | 17 -------- 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 ++++++++++++++++++++++++++++ src/client/elm/Update.elm | 13 +++--- src/client/elm/Update/SignIn.elm | 30 -------------- src/client/elm/View.elm | 5 ++- src/client/elm/View/SignIn.elm | 62 ---------------------------- 17 files changed, 138 insertions(+), 132 deletions(-) create mode 100644 src/client/elm/LoggedIn/Action.elm create mode 100644 src/client/elm/LoggedIn/Model.elm create mode 100644 src/client/elm/LoggedIn/Update.elm create mode 100644 src/client/elm/LoggedIn/View.elm delete mode 100644 src/client/elm/Model/Action/SignInAction.elm delete mode 100644 src/client/elm/Model/View/SignInView.elm 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 delete mode 100644 src/client/elm/Update/SignIn.elm delete mode 100644 src/client/elm/View/SignIn.elm diff --git a/src/client/elm/LoggedIn/Action.elm b/src/client/elm/LoggedIn/Action.elm new file mode 100644 index 0000000..e69de29 diff --git a/src/client/elm/LoggedIn/Model.elm b/src/client/elm/LoggedIn/Model.elm new file mode 100644 index 0000000..e69de29 diff --git a/src/client/elm/LoggedIn/Update.elm b/src/client/elm/LoggedIn/Update.elm new file mode 100644 index 0000000..e69de29 diff --git a/src/client/elm/LoggedIn/View.elm b/src/client/elm/LoggedIn/View.elm new file mode 100644 index 0000000..e69de29 diff --git a/src/client/elm/Model.elm b/src/client/elm/Model.elm index 7852c9a..3d2eb2b 100644 --- a/src/client/elm/Model.elm +++ b/src/client/elm/Model.elm @@ -7,10 +7,11 @@ import Time exposing (Time) import Json.Decode as Json import Model.View exposing (..) -import Model.View.SignInView exposing (initSignInView) import Model.Translations exposing (..) import Model.Conf exposing (..) +import SignIn.Model as SignInModel + import Utils.Maybe exposing (isJust) type alias Model = @@ -24,7 +25,7 @@ initialModel : Time -> String -> String -> Maybe String -> Model initialModel initialTime translations conf mbSignInError = { view = if isJust mbSignInError - then SignInView (initSignInView mbSignInError) + then SignInView (SignInModel.init mbSignInError) else LoadingView , currentTime = initialTime , translations = diff --git a/src/client/elm/Model/Action.elm b/src/client/elm/Model/Action.elm index 60c1aca..3d06521 100644 --- a/src/client/elm/Model/Action.elm +++ b/src/client/elm/Model/Action.elm @@ -5,16 +5,17 @@ module Model.Action import Time exposing (Time) import Signal exposing (Address) -import Model.Action.SignInAction exposing (SignInAction) import Model.Action.LoggedInAction exposing (LoggedInAction) import Model.Init exposing (Init) +import SignIn.Action as SignInAction + type Action = NoOp | SignIn String | UpdateTime Time | GoLoggedInView Init - | UpdateSignIn SignInAction + | UpdateSignIn SignInAction.Action | UpdateLoggedIn LoggedInAction | GoSignInView | SignOut diff --git a/src/client/elm/Model/Action/SignInAction.elm b/src/client/elm/Model/Action/SignInAction.elm deleted file mode 100644 index bead018..0000000 --- a/src/client/elm/Model/Action/SignInAction.elm +++ /dev/null @@ -1,9 +0,0 @@ -module Model.Action.SignInAction - ( SignInAction(..) - ) where - -type SignInAction = - UpdateLogin String - | WaitingServer - | ValidLogin - | ErrorLogin String diff --git a/src/client/elm/Model/View.elm b/src/client/elm/Model/View.elm index 90c0e53..7fc42af 100644 --- a/src/client/elm/Model/View.elm +++ b/src/client/elm/Model/View.elm @@ -3,10 +3,11 @@ module Model.View ) where import Model.Payment exposing (Payments) -import Model.View.SignInView exposing (..) import Model.View.LoggedInView exposing (..) +import SignIn.Model as SignInModel + type View = LoadingView - | SignInView SignInView + | SignInView SignInModel.Model | LoggedInView LoggedInView diff --git a/src/client/elm/Model/View/SignInView.elm b/src/client/elm/Model/View/SignInView.elm deleted file mode 100644 index f72d05a..0000000 --- a/src/client/elm/Model/View/SignInView.elm +++ /dev/null @@ -1,17 +0,0 @@ -module Model.View.SignInView - ( SignInView - , initSignInView - ) where - -type alias SignInView = - { login : String - , waitingServer : Bool - , result : Maybe (Result String String) - } - -initSignInView : Maybe String -> SignInView -initSignInView mbSignInError = - { login = "" - , waitingServer = False - , result = Maybe.map Err mbSignInError - } 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 "" diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm index 1625167..8b443a0 100644 --- a/src/client/elm/Update.elm +++ b/src/client/elm/Update.elm @@ -11,14 +11,15 @@ import Server import Model exposing (Model) import Model.Translations exposing (getMessage) import Model.Action exposing (..) -import Model.Action.SignInAction as SignInAction exposing (SignInAction) import Model.Action.LoggedInAction exposing (LoggedInAction) import Model.View as V -import Model.View.SignInView exposing (..) import Model.View.LoggedInView exposing (..) +import SignIn.Model as SignInModel +import SignIn.Action as SignInAction +import SignIn.Update as SignInUpdate + import Update.LoggedIn exposing (updateLoggedIn) -import Update.SignIn exposing (updateSignIn) import Utils.Http exposing (errorKey) @@ -48,7 +49,7 @@ update action model = ({ model | currentTime = time }, Effects.none) GoSignInView -> - ({ model | view = V.SignInView (initSignInView Nothing) }, Effects.none) + ({ model | view = V.SignInView (SignInModel.init Nothing) }, Effects.none) UpdateSignIn signInAction -> (applySignIn model signInAction, Effects.none) @@ -64,11 +65,11 @@ update action model = |> Effects.task ) -applySignIn : Model -> SignInAction -> Model +applySignIn : Model -> SignInAction.Action -> Model applySignIn model signInAction = case model.view of V.SignInView signInView -> - { model | view = V.SignInView (updateSignIn model.translations signInAction signInView) } + { model | view = V.SignInView (SignInUpdate.update model.translations signInAction signInView) } _ -> model diff --git a/src/client/elm/Update/SignIn.elm b/src/client/elm/Update/SignIn.elm deleted file mode 100644 index ade5761..0000000 --- a/src/client/elm/Update/SignIn.elm +++ /dev/null @@ -1,30 +0,0 @@ -module Update.SignIn - ( updateSignIn - ) where - -import Model.View.SignInView exposing (..) -import Model.Action.SignInAction exposing (..) -import Model.Translations exposing (getMessage, Translations) - -updateSignIn : Translations -> SignInAction -> SignInView -> SignInView -updateSignIn 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/View.elm b/src/client/elm/View.elm index 473caae..d29f814 100644 --- a/src/client/elm/View.elm +++ b/src/client/elm/View.elm @@ -11,9 +11,10 @@ import Model.View exposing (..) import View.Header exposing (renderHeader) import View.Loading exposing (renderLoading) -import View.SignIn exposing (renderSignIn) import View.LoggedIn exposing (renderLoggedIn) +import SignIn.View as SignInView + view : Address Action -> Model -> Html view address model = div @@ -28,6 +29,6 @@ renderMain address model = LoadingView -> renderLoading address SignInView signInView -> - renderSignIn address model signInView + SignInView.view address model signInView LoggedInView loggedInView -> renderLoggedIn address model loggedInView diff --git a/src/client/elm/View/SignIn.elm b/src/client/elm/View/SignIn.elm deleted file mode 100644 index acff960..0000000 --- a/src/client/elm/View/SignIn.elm +++ /dev/null @@ -1,62 +0,0 @@ -module View.SignIn - ( renderSignIn - ) where - -import Html as H exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Signal exposing (Address) -import Json.Decode as Json - -import Update exposing (..) -import Update.SignIn exposing (..) - -import Model exposing (Model) -import Model.Action exposing (..) -import Model.Action.SignInAction exposing (..) -import Model.View.SignInView exposing (..) -import Model.Translations exposing (getMessage) - -import View.Events exposing (onSubmitPrevDefault) -import View.Icon exposing (renderSpinIcon) - -renderSignIn : Address Action -> Model -> SignInView -> Html -renderSignIn address model signInView = - div - [ class "signIn" ] - [ H.form - [ onSubmitPrevDefault address (SignIn signInView.login) ] - [ input - [ value signInView.login - , on "input" targetValue (Signal.message address << UpdateSignIn << UpdateLogin) - , type' "text" - , autocomplete True - ] - [] - , button - [] - [ if signInView.waitingServer - then renderSpinIcon - else text (getMessage "SignIn" model.translations) - ] - ] - , div - [ class "result" ] - [ 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 (getMessage error model.translations) ] - Nothing -> - text "" -- cgit v1.2.3