blob: 4a53ac423b47bcb1abd8b383c6a9b7ecf6fcf777 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
module Update.LoggedView
( LoggedAction(..)
, updateLoggedView
) where
import Date
import Dict
import Model exposing (Model)
import Model.User exposing (UserId)
import Model.Payment exposing (..)
import Model.Payers exposing (..)
import Model.View.LoggedView exposing (..)
import Model.View.Payment.Add exposing (..)
import Update.LoggedView.Add exposing (..)
import Update.LoggedView.Monthly exposing (..)
type LoggedAction =
UpdateAdd AddPaymentAction
| UpdatePayments Payments
| AddPayment UserId PaymentId String Int Frequency Payments
| ToggleEdit PaymentId
| Remove UserId Int Payments
| UpdatePage Int Payments
| UpdateMonthly MonthlyAction
updateLoggedView : Model -> LoggedAction -> LoggedView -> LoggedView
updateLoggedView model action loggedView =
case action of
UpdateAdd addPaymentAction ->
{ loggedView | add <- updateAddPayment addPaymentAction loggedView.add }
UpdatePayments payments ->
{ loggedView | payments <- payments }
AddPayment userId paymentId name cost frequency payments ->
{ loggedView
| payments <- payments
, currentPage <- 1
, add <- initAddPayment loggedView.add.frequency
, payers <- updatePayers loggedView.payers userId cost
, paymentsCount <- loggedView.paymentsCount + 1
, monthly <-
if frequency == Monthly
then
let payment = Payment paymentId (Date.fromTime model.currentTime) name cost userId
in updateMonthly (AddMonthlyPayment payment) loggedView.monthly
else
loggedView.monthly
}
ToggleEdit id ->
{ loggedView | paymentEdition <- if loggedView.paymentEdition == Just id then Nothing else Just id }
Remove userId cost payments ->
{ loggedView
| payments <- payments
, payers <- updatePayers loggedView.payers userId -cost
, paymentsCount <- loggedView.paymentsCount - 1
}
UpdatePage page payments ->
{ loggedView
| currentPage <- page
, payments <- payments
}
UpdateMonthly monthlyAction ->
{ loggedView | monthly <- updateMonthly monthlyAction loggedView.monthly }
|