From c542551ad043260e6a4a6569b4af5c748f7b6001 Mon Sep 17 00:00:00 2001
From: Joris
Date: Wed, 30 Mar 2016 14:17:59 +0200
Subject: Filter own monthly payments in view

---
 src/client/elm/LoggedIn/Home/View/Monthly.elm | 45 ++++++++++++++-------------
 1 file changed, 23 insertions(+), 22 deletions(-)

(limited to 'src/client/elm/LoggedIn/Home/View/Monthly.elm')

diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm
index c1f3b51..aa0e3a5 100644
--- a/src/client/elm/LoggedIn/Home/View/Monthly.elm
+++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm
@@ -15,7 +15,7 @@ import LoggedIn.Home.Model as HomeModel
 import LoggedIn.Home.View.Price exposing (price)
 import LoggedIn.Home.View.Expand exposing (..)
 
-import Model.Payment as Payment exposing (Payment, monthlyPayments)
+import Model.Payment as Payment exposing (Payments, Payment, monthly)
 import Model.Translations exposing (getMessage, getParamMessage)
 import LoggedData exposing (LoggedData)
 
@@ -26,26 +26,27 @@ import View.Icon exposing (renderIcon)
 
 view : LoggedData -> HomeModel.Model -> Html
 view loggedData homeModel =
-  if List.length (monthlyPayments loggedData.payments) == 0
-    then
-      text ""
-    else
-      div
-        [ classList
-            [ ("monthlyPayments", True)
-            , ("detail", homeModel.monthlyDetail)
+  let monthlyPayments = Payment.monthly loggedData.me loggedData.payments
+  in  if List.length monthlyPayments == 0
+        then
+          text ""
+        else
+          div
+            [ classList
+                [ ("monthlyPayments", True)
+                , ("detail", homeModel.monthlyDetail)
+                ]
+            ]
+            [ monthlyCount loggedData monthlyPayments homeModel
+            , if homeModel.monthlyDetail
+                then paymentsTable loggedData monthlyPayments homeModel
+                else text ""
             ]
-        ]
-        [ monthlyCount loggedData homeModel
-        , if homeModel.monthlyDetail
-            then paymentsTable loggedData homeModel
-            else text ""
-        ]
 
-monthlyCount : LoggedData -> HomeModel.Model -> Html
-monthlyCount loggedData homeModel =
-  let count = List.length (monthlyPayments loggedData.payments)
-      total = List.sum << List.map .cost <| (monthlyPayments loggedData.payments)
+monthlyCount : LoggedData -> Payments -> HomeModel.Model -> Html
+monthlyCount loggedData monthlyPayments homeModel =
+  let count = List.length monthlyPayments
+      total = List.sum << List.map .cost <| monthlyPayments
       key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount"
   in  button
         [ class "header"
@@ -55,11 +56,11 @@ monthlyCount loggedData homeModel =
         , expand ExpandDown homeModel.monthlyDetail
         ]
 
-paymentsTable : LoggedData -> HomeModel.Model -> Html
-paymentsTable loggedData homeModel =
+paymentsTable : LoggedData -> Payments -> HomeModel.Model -> Html
+paymentsTable loggedData monthlyPayments homeModel =
   div
     [ class "table" ]
-    ( (monthlyPayments loggedData.payments)
+    ( monthlyPayments
         |> List.sortBy (String.toLower << .name)
         |> List.map (paymentLine loggedData homeModel)
     )
-- 
cgit v1.2.3