aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Update')
-rw-r--r--src/client/Update/LoggedView.elm29
-rw-r--r--src/client/Update/LoggedView/Monthly.elm16
2 files changed, 27 insertions, 18 deletions
diff --git a/src/client/Update/LoggedView.elm b/src/client/Update/LoggedView.elm
index 4a53ac4..cf6bcb2 100644
--- a/src/client/Update/LoggedView.elm
+++ b/src/client/Update/LoggedView.elm
@@ -14,16 +14,17 @@ import Model.View.LoggedView exposing (..)
import Model.View.Payment.Add exposing (..)
import Update.LoggedView.Add exposing (..)
-import Update.LoggedView.Monthly exposing (..)
+import Update.LoggedView.Monthly as UM
type LoggedAction =
UpdateAdd AddPaymentAction
| UpdatePayments Payments
- | AddPayment UserId PaymentId String Int Frequency Payments
+ | AddPayment UserId String Int Payments
+ | AddMonthlyPayment PaymentId String Int
| ToggleEdit PaymentId
- | Remove UserId Int Payments
+ | DeletePayment UserId Int Payments
| UpdatePage Int Payments
- | UpdateMonthly MonthlyAction
+ | UpdateMonthly UM.MonthlyAction
updateLoggedView : Model -> LoggedAction -> LoggedView -> LoggedView
updateLoggedView model action loggedView =
@@ -32,24 +33,24 @@ updateLoggedView model action loggedView =
{ loggedView | add <- updateAddPayment addPaymentAction loggedView.add }
UpdatePayments payments ->
{ loggedView | payments <- payments }
- AddPayment userId paymentId name cost frequency payments ->
+ AddPayment userId name cost payments ->
{ loggedView
| payments <- payments
, currentPage <- 1
- , add <- initAddPayment loggedView.add.frequency
+ , add <- initAddPayment Punctual
, payers <- updatePayers loggedView.payers userId cost
, paymentsCount <- loggedView.paymentsCount + 1
+ }
+ AddMonthlyPayment id name cost ->
+ { loggedView
+ | add <- initAddPayment Monthly
, 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
+ let payment = Payment id (Date.fromTime model.currentTime) name cost loggedView.me
+ in UM.updateMonthly (UM.AddPayment payment) loggedView.monthly
}
ToggleEdit id ->
{ loggedView | paymentEdition <- if loggedView.paymentEdition == Just id then Nothing else Just id }
- Remove userId cost payments ->
+ DeletePayment userId cost payments ->
{ loggedView
| payments <- payments
, payers <- updatePayers loggedView.payers userId -cost
@@ -61,4 +62,4 @@ updateLoggedView model action loggedView =
, payments <- payments
}
UpdateMonthly monthlyAction ->
- { loggedView | monthly <- updateMonthly monthlyAction loggedView.monthly }
+ { loggedView | monthly <- UM.updateMonthly monthlyAction loggedView.monthly }
diff --git a/src/client/Update/LoggedView/Monthly.elm b/src/client/Update/LoggedView/Monthly.elm
index 8d02c5e..567025f 100644
--- a/src/client/Update/LoggedView/Monthly.elm
+++ b/src/client/Update/LoggedView/Monthly.elm
@@ -3,17 +3,25 @@ module Update.LoggedView.Monthly
, updateMonthly
) where
-import Model.Payment exposing (Payment)
+import Model.Payment exposing (Payment, PaymentId)
import Model.View.Payment.Monthly exposing (..)
type MonthlyAction =
ToggleDetail
- | AddMonthlyPayment Payment
+ | AddPayment Payment
+ | DeletePayment PaymentId
updateMonthly : MonthlyAction -> Monthly -> Monthly
updateMonthly action monthly =
case action of
ToggleDetail ->
{ monthly | visibleDetail <- not monthly.visibleDetail }
- AddMonthlyPayment payment ->
- { monthly | payments <- payment :: monthly.payments }
+ AddPayment payment ->
+ { monthly
+ | payments <- payment :: monthly.payments
+ , visibleDetail <- True
+ }
+ DeletePayment id ->
+ { monthly
+ | payments <- List.filter (\payment -> payment.id /= id) monthly.payments
+ }