From 0cba27cba2b44756389d50bc113f23a2be87e978 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 3 Jan 2016 00:19:55 +0100 Subject: Prevent to send multiple payments if the server is not answering --- src/client/elm/View/LoggedIn/AddPayment.elm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/client/elm/View/LoggedIn') diff --git a/src/client/elm/View/LoggedIn/AddPayment.elm b/src/client/elm/View/LoggedIn/AddPayment.elm index 5739a95..283d392 100644 --- a/src/client/elm/View/LoggedIn/AddPayment.elm +++ b/src/client/elm/View/LoggedIn/AddPayment.elm @@ -14,7 +14,7 @@ import Model exposing (Model) import Model.Payment exposing (PaymentFrequency(..)) import Model.Translations exposing (getMessage) import Model.Action exposing (..) -import Model.Action.LoggedInAction exposing (..) +import Model.Action.LoggedInAction as LoggedInAction exposing (..) import Model.Action.AddPaymentAction exposing (..) import Model.Communication as Communication @@ -22,7 +22,7 @@ import Model.View.LoggedIn.AddPayment exposing (..) import Model.View.LoggedInView exposing (LoggedInView) import View.Events exposing (onSubmitPrevDefault) -import View.Icon exposing (renderIcon) +import View.Icon exposing (..) import Utils.Maybe exposing (isJust) import Utils.Either exposing (toMaybeError) @@ -30,11 +30,16 @@ import Utils.Either exposing (toMaybeError) addPayment : Address Action -> Model -> LoggedInView -> Html addPayment address model loggedInView = H.form - [ case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of - (Ok name, Ok cost) -> - onSubmitPrevDefault address (ServerCommunication (Communication.AddPayment name cost loggedInView.add.frequency)) - (resName, resCost) -> - onSubmitPrevDefault address (UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)) + [ let update = + if loggedInView.add.waitingServer + then NoOp + else + case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of + (Ok name, Ok cost) -> + UpdateLoggedIn <| LoggedInAction.AddPayment name cost loggedInView.add.frequency + (resName, resCost) -> + UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost) + in onSubmitPrevDefault address update , class "addPayment" ] [ addPaymentName address loggedInView.add @@ -42,8 +47,14 @@ addPayment address model loggedInView = , paymentFrequency address model loggedInView.add , button [ type' "submit" - , class "add" ] - [ text (getMessage "Add" model.translations)] + , classList + [ ("add", True) + , ("waitingServer", loggedInView.add.waitingServer) + ] + ] + [ text (getMessage "Add" model.translations) + , if loggedInView.add.waitingServer then renderSpinIcon else text "" + ] ] addPaymentName : Address Action -> AddPayment -> Html -- cgit v1.2.3