diff options
author | Joris | 2016-03-27 17:36:33 +0200 |
---|---|---|
committer | Joris | 2016-03-27 17:59:32 +0200 |
commit | 869bab77e93e2a6c776a4b1fc35ef0fd5df22f5f (patch) | |
tree | 917a9e871eff1c487da63ea2407234d7e3829dda /src/client/elm/Update | |
parent | a8882071da12cbb5b0bf2f003322e42e181b0c82 (diff) |
Compute payers client side rather than server side
Diffstat (limited to 'src/client/elm/Update')
-rw-r--r-- | src/client/elm/Update/LoggedIn.elm | 36 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn/Account.elm | 23 |
2 files changed, 19 insertions, 40 deletions
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index dfc2a1b..300c63a 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -71,17 +71,15 @@ updateLoggedIn model action loggedInView = newAdd = initAddPayment frequency in case frequency of Punctual -> - let (newAccount, accountEffects) = - updateAccount (Account.UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account - in ( { loggedInView - | currentPage = 1 - , add = newAdd - , account = newAccount - , payments = newPayment :: loggedInView.payments - , paymentsCount = loggedInView.paymentsCount + 1 - } - , Effects.map UpdateAccount accountEffects - ) + ( { loggedInView + | currentPage = 1 + , add = newAdd + , account = loggedInView.account + , payments = newPayment :: loggedInView.payments + , paymentsCount = loggedInView.paymentsCount + 1 + } + , Effects.none + ) Monthly -> ( { loggedInView | add = newAdd @@ -112,15 +110,13 @@ updateLoggedIn model action loggedInView = , Effects.none ) Punctual -> - let (newAccount, accountEffects) = - updateAccount (Account.UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account - in ( { loggedInView - | account = newAccount - , payments = deletePayment payment.id loggedInView.payments - , paymentsCount = loggedInView.paymentsCount - 1 - } - , Effects.map UpdateAccount accountEffects - ) + ( { loggedInView + | account = loggedInView.account + , payments = deletePayment payment.id loggedInView.payments + , paymentsCount = loggedInView.paymentsCount - 1 + } + , Effects.none + ) UpdatePage page -> ( { loggedInView | currentPage = page } diff --git a/src/client/elm/Update/LoggedIn/Account.elm b/src/client/elm/Update/LoggedIn/Account.elm index 1773b9a..233efa9 100644 --- a/src/client/elm/Update/LoggedIn/Account.elm +++ b/src/client/elm/Update/LoggedIn/Account.elm @@ -10,7 +10,6 @@ import Effects exposing (Effects) import Server -import Model.Payer exposing (updatePayers) import Model.Action.AccountAction exposing (..) import Model.View.LoggedIn.Account exposing (..) @@ -28,11 +27,6 @@ updateAccount action account = , Effects.none ) - UpdatePayer userId creation amountDiff -> - ( { account | payers = updatePayers account.payers userId creation amountDiff } - , Effects.none - ) - ToggleIncomeEdition -> ( { account | incomeEdition = if isJust account.incomeEdition @@ -67,25 +61,14 @@ updateAccount action account = UpdateIncome currentTime amount -> ( account , Server.setIncome currentTime amount - |> Task.map (always (ValidateUpdateIncome currentTime amount)) + |> Task.map (\incomeId -> (ValidateUpdateIncome incomeId currentTime amount)) |> flip Task.onError (always <| Task.succeed NoOp) |> Effects.task ) - ValidateUpdateIncome currentTime amount -> + ValidateUpdateIncome incomeId currentTime amount -> ( { account - | payers = - account.payers - |> Dict.update account.me (\mbPayer -> - case mbPayer of - Just payer -> - Just - { payer - | incomes = payer.incomes ++ [{ creation = currentTime, amount = amount }] - } - Nothing -> - Nothing - ) + | incomes = Dict.insert incomeId { userId = account.me, creation = currentTime, amount = amount } account.incomes , incomeEdition = Nothing } , Effects.none |