aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Update
diff options
context:
space:
mode:
authorJoris2016-03-27 20:20:10 +0200
committerJoris2016-03-27 20:20:10 +0200
commit702d60cbcdf85216a1b18416f4480afb77384e8a (patch)
tree400c004181373255ff0ad40ed32c69674e62ae59 /src/client/elm/Update
parent5f6c66e4c3cf02e5b1c0a1fac6036b86be06a992 (diff)
Regroup loggedIn modules
Diffstat (limited to 'src/client/elm/Update')
-rw-r--r--src/client/elm/Update/LoggedIn.elm135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm
deleted file mode 100644
index 300c63a..0000000
--- a/src/client/elm/Update/LoggedIn.elm
+++ /dev/null
@@ -1,135 +0,0 @@
-module Update.LoggedIn
- ( updateLoggedIn
- ) where
-
-import Date
-import Dict
-import Debug
-import Task
-import String
-
-import Effects exposing (Effects)
-import Http exposing (Error(..))
-
-import Server
-
-import Model exposing (Model)
-import Model.User exposing (UserId)
-import Model.Payment exposing (..)
-import Model.Action.LoggedInAction exposing (..)
-import Model.Action.AccountAction as Account
-import Model.Action.MonthlyAction as Monthly
-import Model.Action.AddPaymentAction as AddPayment
-import Model.View.LoggedInView exposing (..)
-import Model.View.LoggedIn.AddPayment exposing (..)
-import Model.Translations exposing (Translations, getMessage)
-
-import Update.LoggedIn.AddPayment exposing (updateAddPayment, addPaymentError)
-import Update.LoggedIn.Monthly exposing (updateMonthly)
-import Update.LoggedIn.Account exposing (updateAccount)
-
-updateLoggedIn : Model -> LoggedInAction -> LoggedInView -> (LoggedInView, Effects LoggedInAction)
-updateLoggedIn model action loggedInView =
- case action of
-
- NoOp -> (loggedInView, Effects.none)
-
- UpdateAdd addPaymentAction ->
- ( { loggedInView | add = updateAddPayment addPaymentAction loggedInView.add }
- , Effects.none
- )
-
- UpdatePayments payments ->
- ( { loggedInView | payments = payments }
- , Effects.none
- )
-
- AddPayment name cost frequency ->
- ( { loggedInView | add = updateAddPayment AddPayment.WaitingServer loggedInView.add }
- , Server.addPayment name cost frequency
- |> Task.map (\paymentId ->
- case String.toInt cost of
- Err _ ->
- UpdateAdd (AddPayment.AddError Nothing (Just (getMessage "CostRequired" model.translations)))
- Ok costNumber ->
- ValidateAddPayment paymentId name costNumber frequency
- )
- |> flip Task.onError (\err ->
- case err of
- BadResponse 400 jsonErr ->
- case addPaymentError model.translations jsonErr of
- Just addPaymentAction -> Task.succeed (UpdateAdd addPaymentAction)
- Nothing -> Task.succeed NoOp
- _ ->
- Task.succeed NoOp
- )
- |> Effects.task
- )
-
- ValidateAddPayment paymentId name cost frequency ->
- let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedInView.account.me
- newAdd = initAddPayment frequency
- in case frequency of
- Punctual ->
- ( { loggedInView
- | currentPage = 1
- , add = newAdd
- , account = loggedInView.account
- , payments = newPayment :: loggedInView.payments
- , paymentsCount = loggedInView.paymentsCount + 1
- }
- , Effects.none
- )
- Monthly ->
- ( { loggedInView
- | add = newAdd
- , monthly = updateMonthly (Monthly.AddPayment newPayment) loggedInView.monthly
- }
- , Effects.none
- )
-
- ToggleEdit id ->
- ( { loggedInView | paymentEdition = if loggedInView.paymentEdition == Just id then Nothing else Just id }
- , Effects.none
- )
-
- DeletePayment payment frequency ->
- ( loggedInView
- , Server.deletePayment payment frequency
- |> Task.map (always (ValidateDeletePayment payment frequency))
- |> flip Task.onError (always <| Task.succeed NoOp)
- |> Effects.task
- )
-
- ValidateDeletePayment payment frequency ->
- case frequency of
- Monthly ->
- ( { loggedInView
- | monthly = updateMonthly (Monthly.DeletePayment payment) loggedInView.monthly
- }
- , Effects.none
- )
- Punctual ->
- ( { loggedInView
- | account = loggedInView.account
- , payments = deletePayment payment.id loggedInView.payments
- , paymentsCount = loggedInView.paymentsCount - 1
- }
- , Effects.none
- )
-
- UpdatePage page ->
- ( { loggedInView | currentPage = page }
- , Effects.none
- )
-
- UpdateMonthly monthlyAction ->
- ( { loggedInView | monthly = updateMonthly monthlyAction loggedInView.monthly }
- , Effects.none
- )
-
- UpdateAccount accountAction ->
- let (newAccount, accountEffects) = updateAccount accountAction loggedInView.account
- in ( { loggedInView | account = newAccount }
- , Effects.map UpdateAccount accountEffects
- )