diff options
Diffstat (limited to 'src/client/elm/Update')
-rw-r--r-- | src/client/elm/Update/LoggedIn.elm | 105 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn/AddPayment.elm | 2 | ||||
-rw-r--r-- | src/client/elm/Update/SignIn.elm | 6 |
3 files changed, 78 insertions, 35 deletions
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index 704dd7f..fe53af7 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -5,12 +5,20 @@ module Update.LoggedIn import Date import Dict +import Effects exposing (Effects) +import Task + +import ServerCommunication exposing (sendRequest) + import Model exposing (Model) import Model.User exposing (UserId) import Model.Payment exposing (..) +import Model.Action exposing (..) import Model.Action.LoggedInAction exposing (..) import Model.Action.AccountAction exposing (..) import Model.Action.MonthlyAction as Monthly +import Model.Action.AddPaymentAction as AddPayment +import Model.Communication as Communication exposing (Communication) import Model.View.LoggedInView exposing (..) import Model.View.LoggedIn.AddPayment exposing (..) @@ -18,49 +26,82 @@ import Update.LoggedIn.AddPayment exposing (updateAddPayment) import Update.LoggedIn.Monthly exposing (updateMonthly) import Update.LoggedIn.Account exposing (updateAccount) -updateLoggedIn : Model -> LoggedInAction -> LoggedInView -> LoggedInView +updateLoggedIn : Model -> LoggedInAction -> LoggedInView -> (LoggedInView, Effects Action) updateLoggedIn model action loggedInView = case action of + UpdateAdd addPaymentAction -> - { loggedInView | add = updateAddPayment addPaymentAction loggedInView.add } + ( { loggedInView | add = updateAddPayment addPaymentAction loggedInView.add } + , Effects.none + ) + UpdatePayments payments -> - { loggedInView | payments = payments } - AddPayment paymentId name cost frequency -> + ( { loggedInView | payments = payments } + , Effects.none + ) + + AddPayment name cost frequency -> + ( { loggedInView | add = updateAddPayment AddPayment.WaitingServer loggedInView.add } + , sendRequest (Communication.AddPayment name cost frequency) + |> flip Task.onError (always <| 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 if frequency == Punctual - then - { loggedInView - | currentPage = 1 - , add = newAdd - , account = updateAccount (UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account - , payments = newPayment :: loggedInView.payments - , paymentsCount = loggedInView.paymentsCount + 1 - } - else - { loggedInView - | add = newAdd - , monthly = updateMonthly (Monthly.AddPayment newPayment) loggedInView.monthly - } + in case frequency of + Punctual -> + ( { loggedInView + | currentPage = 1 + , add = newAdd + , account = updateAccount (UpdatePayer loggedInView.account.me model.currentTime cost) 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 } + ( { loggedInView | paymentEdition = if loggedInView.paymentEdition == Just id then Nothing else Just id } + , Effects.none + ) + DeletePayment payment frequency -> case frequency of Monthly -> - { loggedInView - | monthly = updateMonthly (Monthly.DeletePayment payment) loggedInView.monthly - } + ( { loggedInView + | monthly = updateMonthly (Monthly.DeletePayment payment) loggedInView.monthly + } + , Effects.none + ) Punctual -> - { loggedInView - | account = updateAccount (UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account - , payments = deletePayment payment.id loggedInView.payments - , paymentsCount = loggedInView.paymentsCount - 1 - } + ( { loggedInView + | account = updateAccount (UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account + , payments = deletePayment payment.id loggedInView.payments + , paymentsCount = loggedInView.paymentsCount - 1 + } + , Effects.none + ) + UpdatePage page -> - { loggedInView - | currentPage = page - } + ( { loggedInView | currentPage = page } + , Effects.none + ) + UpdateMonthly monthlyAction -> - { loggedInView | monthly = updateMonthly monthlyAction loggedInView.monthly } + ( { loggedInView | monthly = updateMonthly monthlyAction loggedInView.monthly } + , Effects.none + ) + UpdateAccount accountAction -> - { loggedInView | account = updateAccount accountAction loggedInView.account } + ( { loggedInView | account = updateAccount accountAction loggedInView.account } + , Effects.none + ) diff --git a/src/client/elm/Update/LoggedIn/AddPayment.elm b/src/client/elm/Update/LoggedIn/AddPayment.elm index 978980d..3eb2ea4 100644 --- a/src/client/elm/Update/LoggedIn/AddPayment.elm +++ b/src/client/elm/Update/LoggedIn/AddPayment.elm @@ -22,3 +22,5 @@ updateAddPayment action addPayment = { addPayment | frequency = if addPayment.frequency == Punctual then Monthly else Punctual } + WaitingServer -> + { addPayment | waitingServer = True } diff --git a/src/client/elm/Update/SignIn.elm b/src/client/elm/Update/SignIn.elm index 5e8a9bb..94963c8 100644 --- a/src/client/elm/Update/SignIn.elm +++ b/src/client/elm/Update/SignIn.elm @@ -8,10 +8,10 @@ import Model.View.SignInView exposing (..) updateSignIn : SignInAction -> SignInView -> SignInView updateSignIn action signInView = case action of - Connecting -> - { signInView | connecting = True } + WaitingServer -> + { signInView | waitingServer = True } ErrorLogin message -> { signInView | error = Just message - , connecting = False + , waitingServer = False } |