aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Update/LoggedIn/Monthly.elm
blob: 275b3e8eb75065ace32824aab529631bd610bbd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Update.LoggedIn.Monthly
  ( MonthlyAction(..)
  , updateMonthly
  ) where

import Model.Payment exposing (Payment, PaymentId)
import Model.View.LoggedIn.Monthly exposing (..)

type MonthlyAction =
  ToggleDetail
  | AddPayment Payment
  | DeletePayment PaymentId

updateMonthly : MonthlyAction -> Monthly -> Monthly
updateMonthly action monthly =
  case action of
    ToggleDetail ->
      { monthly | visibleDetail = not monthly.visibleDetail }
    AddPayment payment ->
      { monthly
      | payments = payment :: monthly.payments
      , visibleDetail = True
      }
    DeletePayment id ->
      { monthly
      | payments = List.filter (\payment -> payment.id /= id) monthly.payments
      }