diff options
author | Joris | 2015-09-04 23:13:48 +0200 |
---|---|---|
committer | Joris | 2015-09-04 23:13:48 +0200 |
commit | c876fd8c2f1aac2c3fe10c2b7de734f3ef71b71f (patch) | |
tree | 23ff6a85ee81a0cc8419b7c1acbec0a33bd02fab /src/client/Update | |
parent | c1f44a5890fbb26faf6f17c676662ea1bd495f2e (diff) |
Paging model works with both payments addition and deletion
Diffstat (limited to 'src/client/Update')
-rw-r--r-- | src/client/Update/Payment.elm | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/client/Update/Payment.elm b/src/client/Update/Payment.elm index 798cdb4..b9b60dd 100644 --- a/src/client/Update/Payment.elm +++ b/src/client/Update/Payment.elm @@ -17,9 +17,9 @@ import Update.Payment.Add exposing (..) type PaymentAction = UpdateAdd AddPaymentAction | UpdatePayments Payments - | AddPayment PaymentId String Int + | AddPayment String Int Payments | ToggleEdit PaymentId - | Remove PaymentId + | Remove String Int Payments | UpdatePage Int Payments updatePayment : Model -> PaymentAction -> PaymentView -> PaymentView @@ -29,29 +29,22 @@ updatePayment model action paymentView = { paymentView | add <- updateAddPayment addPaymentAction paymentView.add } UpdatePayments payments -> { paymentView | payments <- payments } - AddPayment id name cost -> - let payment = - { creation = Date.fromTime model.currentTime - , name = name - , cost = cost - , userName = paymentView.userName - } - in { paymentView - | payments <- addPayment paymentView.payments (id, payment) - , add <- initAddPayment - , payers <- updatePayers paymentView.payers payment.userName payment.cost - } + AddPayment userName cost payments -> + { paymentView + | payments <- payments + , currentPage <- 1 + , add <- initAddPayment + , payers <- updatePayers paymentView.payers userName cost + , paymentsCount <- paymentView.paymentsCount + 1 + } ToggleEdit id -> { paymentView | edition <- if paymentView.edition == Just id then Nothing else Just id } - Remove id -> - case Dict.get id paymentView.payments of - Just payment -> - { paymentView - | payments <- removePayment paymentView.payments id - , payers <- updatePayers paymentView.payers payment.userName -payment.cost - } - Nothing -> - paymentView + Remove userName cost payments -> + { paymentView + | payments <- payments + , payers <- updatePayers paymentView.payers userName -cost + , paymentsCount <- paymentView.paymentsCount - 1 + } UpdatePage page payments -> { paymentView | currentPage <- page |