diff options
Diffstat (limited to 'src/client/elm/Model/View/LoggedIn')
-rw-r--r-- | src/client/elm/Model/View/LoggedIn/Account.elm | 31 |
1 files changed, 12 insertions, 19 deletions
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 |