From 869bab77e93e2a6c776a4b1fc35ef0fd5df22f5f Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 27 Mar 2016 17:36:33 +0200 Subject: Compute payers client side rather than server side --- src/client/elm/Model/View/LoggedIn/Account.elm | 31 ++++++++++---------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src/client/elm/Model/View/LoggedIn') diff --git a/src/client/elm/Model/View/LoggedIn/Account.elm b/src/client/elm/Model/View/LoggedIn/Account.elm index d03d84f..ec75397 100644 --- a/src/client/elm/Model/View/LoggedIn/Account.elm +++ b/src/client/elm/Model/View/LoggedIn/Account.elm @@ -14,40 +14,33 @@ import String import Utils.Dict exposing (mapValues) import Model.Translations exposing (..) -import Model.Payer exposing (..) +import Model.Income exposing (..) import Model.User exposing (UserId) type alias Account = { me : UserId - , payers : Payers + , incomes : Incomes , visibleDetail : Bool , incomeEdition : Maybe IncomeEdition } -initAccount : UserId -> Payers -> Account -initAccount me payers = +initAccount : UserId -> Incomes -> Account +initAccount me incomes = { me = me - , payers = - payers - |> mapValues - (\payer -> - { payer | incomes = List.sortBy .creation payer.incomes } - ) + , incomes = incomes , visibleDetail = False , incomeEdition = Nothing } getCurrentIncome : Account -> Maybe Int getCurrentIncome account = - case Dict.get account.me account.payers of - Just payer -> - payer.incomes - |> List.sortBy .creation - |> List.reverse - |> List.head - |> Maybe.map .amount - Nothing -> - Nothing + account.incomes + |> Dict.filter (\_ income -> income.userId == account.me) + |> Dict.values + |> List.sortBy .creation + |> List.reverse + |> List.head + |> Maybe.map .amount type alias IncomeEdition = { income : String -- cgit v1.2.3