From 76f8b85eb9f796d6df861a04f702ef5f48630795 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 29 Mar 2016 23:46:47 +0200 Subject: Move logged data to LoggedIn component --- src/client/elm/LoggedIn/Home/AddPayment/Action.elm | 3 ++ src/client/elm/LoggedIn/Home/AddPayment/Update.elm | 3 ++ src/client/elm/LoggedIn/Home/AddPayment/View.elm | 47 +++++++++++----------- 3 files changed, 30 insertions(+), 23 deletions(-) (limited to 'src/client/elm/LoggedIn/Home/AddPayment') diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Action.elm b/src/client/elm/LoggedIn/Home/AddPayment/Action.elm index 095863f..81c32e2 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/Action.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/Action.elm @@ -2,8 +2,11 @@ module LoggedIn.Home.AddPayment.Action ( Action(..) ) where +import Model.Payment exposing (PaymentFrequency) + type Action = NoOp + | Init PaymentFrequency | UpdateName String | UpdateCost String | AddError (Maybe String) (Maybe String) diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Update.elm b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm index b8020f1..473e998 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/Update.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm @@ -19,6 +19,9 @@ update action addPayment = AddPaymentAction.NoOp -> addPayment + AddPaymentAction.Init frequency -> + AddPaymentModel.init frequency + AddPaymentAction.UpdateName name -> { addPayment | name = name } diff --git a/src/client/elm/LoggedIn/Home/AddPayment/View.elm b/src/client/elm/LoggedIn/Home/AddPayment/View.elm index 09d5fbf..47dd6e8 100644 --- a/src/client/elm/LoggedIn/Home/AddPayment/View.elm +++ b/src/client/elm/LoggedIn/Home/AddPayment/View.elm @@ -3,7 +3,6 @@ module LoggedIn.Home.AddPayment.View ) where import Result exposing (..) -import Signal exposing (Address) import Html as H exposing (..) import Html.Attributes exposing (..) @@ -17,10 +16,12 @@ import LoggedIn.Home.Model as HomeModel import LoggedIn.Home.AddPayment.Action as AddPaymentAction import LoggedIn.Home.AddPayment.Model as AddPaymentModel -import Model exposing (Model) import Model.Payment exposing (PaymentFrequency(..)) import Model.Translations exposing (getMessage) -import Action as Action exposing (..) +import LoggedData exposing (LoggedData) + +import Action +import Mailbox import View.Events exposing (onSubmitPrevDefault) import View.Icon exposing (..) @@ -28,21 +29,21 @@ import View.Icon exposing (..) import Utils.Maybe exposing (isJust) import Utils.Either exposing (toMaybeError) -view : Address Action -> Model -> HomeModel.Model -> Html -view address model homeModel = +view : LoggedData -> HomeModel.Model -> Html +view loggedData homeModel = H.form [ let update = if homeModel.add.waitingServer then Action.NoOp else - UpdateLoggedIn << LoggedInAction.HomeAction <| HomeAction.AddPayment homeModel.add.name homeModel.add.cost homeModel.add.frequency - in onSubmitPrevDefault address update + Action.UpdateLoggedIn <| LoggedInAction.AddPayment homeModel.add.name homeModel.add.cost homeModel.add.frequency + in onSubmitPrevDefault Mailbox.address update , class "addPayment" ] - [ addPaymentName address homeModel.add - , addPaymentCost address model homeModel.add - , paymentFrequency address model homeModel.add + [ addPaymentName loggedData homeModel.add + , addPaymentCost loggedData homeModel.add + , paymentFrequency loggedData homeModel.add , button [ type' "submit" , classList @@ -50,13 +51,13 @@ view address model homeModel = , ("waitingServer", homeModel.add.waitingServer) ] ] - [ text (getMessage "Add" model.translations) + [ text (getMessage "Add" loggedData.translations) , if homeModel.add.waitingServer then renderSpinIcon else text "" ] ] -addPaymentName : Address Action -> AddPaymentModel.Model -> Html -addPaymentName address addPayment = +addPaymentName : LoggedData -> AddPaymentModel.Model -> Html +addPaymentName loggedData addPayment = div [ classList [ ("name", True) @@ -66,7 +67,7 @@ addPaymentName address addPayment = [ input [ id "nameInput" , value addPayment.name - , on "input" targetValue (Signal.message address << UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd << AddPaymentAction.UpdateName) + , on "input" targetValue (Signal.message Mailbox.address << Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd << AddPaymentAction.UpdateName) , maxlength 20 ] [] @@ -80,8 +81,8 @@ addPaymentName address addPayment = text "" ] -addPaymentCost : Address Action -> Model -> AddPaymentModel.Model -> Html -addPaymentCost address model addPayment = +addPaymentCost : LoggedData -> AddPaymentModel.Model -> Html +addPaymentCost loggedData addPayment = div [ classList [ ("cost", True) @@ -91,13 +92,13 @@ addPaymentCost address model addPayment = [ input [ id "costInput" , value addPayment.cost - , on "input" targetValue (Signal.message address << UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd << AddPaymentAction.UpdateCost) + , on "input" targetValue (Signal.message Mailbox.address << Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd << AddPaymentAction.UpdateCost) , maxlength 7 ] [] , label [ for "costInput" ] - [ text model.conf.currency ] + [ text loggedData.conf.currency ] , case addPayment.costError of Just error -> div [ class "errorMessage" ] [ text error ] @@ -105,12 +106,12 @@ addPaymentCost address model addPayment = text "" ] -paymentFrequency : Address Action -> Model -> AddPaymentModel.Model -> Html -paymentFrequency address model addPayment = +paymentFrequency : LoggedData -> AddPaymentModel.Model -> Html +paymentFrequency loggedData addPayment = button [ type' "button" , class "frequency" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd <| AddPaymentAction.ToggleFrequency) + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAdd <| AddPaymentAction.ToggleFrequency) ] [ div [ classList @@ -118,12 +119,12 @@ paymentFrequency address model addPayment = , ("selected", addPayment.frequency == Punctual) ] ] - [ text (getMessage "Punctual" model.translations) ] + [ text (getMessage "Punctual" loggedData.translations) ] , div [ classList [ ("monthly", True) , ("selected", addPayment.frequency == Monthly) ] ] - [ text (getMessage "Monthly" model.translations) ] + [ text (getMessage "Monthly" loggedData.translations) ] ] -- cgit v1.2.3