aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model/View/LoggedIn
diff options
context:
space:
mode:
authorJoris2016-03-27 17:36:33 +0200
committerJoris2016-03-27 17:59:32 +0200
commit869bab77e93e2a6c776a4b1fc35ef0fd5df22f5f (patch)
tree917a9e871eff1c487da63ea2407234d7e3829dda /src/client/elm/Model/View/LoggedIn
parenta8882071da12cbb5b0bf2f003322e42e181b0c82 (diff)
Compute payers client side rather than server side
Diffstat (limited to 'src/client/elm/Model/View/LoggedIn')
-rw-r--r--src/client/elm/Model/View/LoggedIn/Account.elm31
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