From bb316286b0859b5648c61f44c88399f4c1aad9cd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 19:07:19 +0100 Subject: Use start-app for elm --- src/client/elm/Update/LoggedIn.elm | 37 ++++++++++----------------- src/client/elm/Update/LoggedIn/Account.elm | 16 +++--------- src/client/elm/Update/LoggedIn/Add.elm | 29 --------------------- src/client/elm/Update/LoggedIn/AddPayment.elm | 23 +++++++++++++++++ src/client/elm/Update/LoggedIn/Monthly.elm | 10 ++------ src/client/elm/Update/SignIn.elm | 7 ++--- 6 files changed, 44 insertions(+), 78 deletions(-) delete mode 100644 src/client/elm/Update/LoggedIn/Add.elm create mode 100644 src/client/elm/Update/LoggedIn/AddPayment.elm (limited to 'src/client/elm/Update') diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index 38901b2..1553141 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -1,6 +1,5 @@ module Update.LoggedIn - ( LoggedAction(..) - , updateLoggedIn + ( updateLoggedIn ) where import Date @@ -9,25 +8,17 @@ import Dict import Model exposing (Model) import Model.User exposing (UserId) import Model.Payment exposing (..) +import Model.Action.LoggedInAction exposing (..) +import Model.Action.AccountAction exposing (..) +import Model.Action.MonthlyAction as Monthly import Model.View.LoggedInView exposing (..) -import Model.View.LoggedIn.Add exposing (..) +import Model.View.LoggedIn.AddPayment exposing (..) -import Update.LoggedIn.Add exposing (..) -import Update.LoggedIn.Monthly as UM -import Update.LoggedIn.Account as UA +import Update.LoggedIn.AddPayment exposing (updateAddPayment) +import Update.LoggedIn.Monthly exposing (updateMonthly) +import Update.LoggedIn.Account exposing (updateAccount) -type LoggedAction = - UpdateAdd AddPaymentAction - | UpdatePayments Payments - | AddPayment PaymentId String Int - | AddMonthlyPayment PaymentId String Int - | ToggleEdit PaymentId - | DeletePayment Payment - | UpdatePage Int - | UpdateMonthly UM.MonthlyAction - | UpdateAccount UA.AccountAction - -updateLoggedIn : Model -> LoggedAction -> LoggedInView -> LoggedInView +updateLoggedIn : Model -> LoggedInAction -> LoggedInView -> LoggedInView updateLoggedIn model action loggedInView = case action of UpdateAdd addPaymentAction -> @@ -39,7 +30,7 @@ updateLoggedIn model action loggedInView = in { loggedInView | currentPage = 1 , add = initAddPayment Punctual - , account = UA.updateAccount (UA.UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account + , account = updateAccount (UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account , payments = newPayment :: loggedInView.payments , paymentsCount = loggedInView.paymentsCount + 1 } @@ -48,13 +39,13 @@ updateLoggedIn model action loggedInView = | add = initAddPayment Monthly , monthly = let payment = Payment id (Date.fromTime model.currentTime) name cost loggedInView.account.me - in UM.updateMonthly (UM.AddPayment payment) loggedInView.monthly + in updateMonthly (Monthly.AddPayment payment) loggedInView.monthly } ToggleEdit id -> { loggedInView | paymentEdition = if loggedInView.paymentEdition == Just id then Nothing else Just id } DeletePayment payment -> { loggedInView - | account = UA.updateAccount (UA.UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account + | account = updateAccount (UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account , payments = deletePayment payment.id loggedInView.payments , paymentsCount = loggedInView.paymentsCount - 1 } @@ -63,6 +54,6 @@ updateLoggedIn model action loggedInView = | currentPage = page } UpdateMonthly monthlyAction -> - { loggedInView | monthly = UM.updateMonthly monthlyAction loggedInView.monthly } + { loggedInView | monthly = updateMonthly monthlyAction loggedInView.monthly } UpdateAccount accountAction -> - { loggedInView | account = UA.updateAccount accountAction loggedInView.account } + { loggedInView | account = updateAccount accountAction loggedInView.account } diff --git a/src/client/elm/Update/LoggedIn/Account.elm b/src/client/elm/Update/LoggedIn/Account.elm index c7a66dd..496fab1 100644 --- a/src/client/elm/Update/LoggedIn/Account.elm +++ b/src/client/elm/Update/LoggedIn/Account.elm @@ -1,26 +1,16 @@ module Update.LoggedIn.Account - ( AccountAction(..) - , updateAccount + ( updateAccount ) where import Maybe -import Time exposing (Time) import Dict -import Model.User exposing (UserId) -import Model.Payer exposing (..) +import Model.Payer exposing (updatePayers) +import Model.Action.AccountAction exposing (..) import Model.View.LoggedIn.Account exposing (..) import Utils.Maybe exposing (isJust) -type AccountAction = - ToggleDetail - | UpdatePayer UserId Time Int - | ToggleIncomeEdition - | UpdateIncomeEdition String - | UpdateEditionError String - | UpdateIncome Time Int - updateAccount : AccountAction -> Account -> Account updateAccount action account = case action of diff --git a/src/client/elm/Update/LoggedIn/Add.elm b/src/client/elm/Update/LoggedIn/Add.elm deleted file mode 100644 index 92bdb7e..0000000 --- a/src/client/elm/Update/LoggedIn/Add.elm +++ /dev/null @@ -1,29 +0,0 @@ -module Update.LoggedIn.Add - ( AddPaymentAction(..) - , updateAddPayment - ) where - -import Model.View.LoggedIn.Add exposing (..) - -type AddPaymentAction = - UpdateName String - | UpdateCost String - | AddError (Maybe String) (Maybe String) - | ToggleFrequency - -updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment -updateAddPayment action addPayment = - case action of - UpdateName name -> - { addPayment | name = name } - UpdateCost cost -> - { addPayment | cost = cost } - AddError nameError costError -> - { addPayment - | nameError = nameError - , costError = costError - } - ToggleFrequency -> - { addPayment - | frequency = if addPayment.frequency == Punctual then Monthly else Punctual - } diff --git a/src/client/elm/Update/LoggedIn/AddPayment.elm b/src/client/elm/Update/LoggedIn/AddPayment.elm new file mode 100644 index 0000000..62eda85 --- /dev/null +++ b/src/client/elm/Update/LoggedIn/AddPayment.elm @@ -0,0 +1,23 @@ +module Update.LoggedIn.AddPayment + ( updateAddPayment + ) where + +import Model.Action.AddPaymentAction exposing (..) +import Model.View.LoggedIn.AddPayment exposing (..) + +updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment +updateAddPayment action addPayment = + case action of + UpdateName name -> + { addPayment | name = name } + UpdateCost cost -> + { addPayment | cost = cost } + AddError nameError costError -> + { addPayment + | nameError = nameError + , costError = costError + } + ToggleFrequency -> + { addPayment + | frequency = if addPayment.frequency == Punctual then Monthly else Punctual + } diff --git a/src/client/elm/Update/LoggedIn/Monthly.elm b/src/client/elm/Update/LoggedIn/Monthly.elm index 275b3e8..2505091 100644 --- a/src/client/elm/Update/LoggedIn/Monthly.elm +++ b/src/client/elm/Update/LoggedIn/Monthly.elm @@ -1,16 +1,10 @@ module Update.LoggedIn.Monthly - ( MonthlyAction(..) - , updateMonthly + ( updateMonthly ) where -import Model.Payment exposing (Payment, PaymentId) +import Model.Action.MonthlyAction exposing (..) import Model.View.LoggedIn.Monthly exposing (..) -type MonthlyAction = - ToggleDetail - | AddPayment Payment - | DeletePayment PaymentId - updateMonthly : MonthlyAction -> Monthly -> Monthly updateMonthly action monthly = case action of diff --git a/src/client/elm/Update/SignIn.elm b/src/client/elm/Update/SignIn.elm index 961fb16..c0aaf33 100644 --- a/src/client/elm/Update/SignIn.elm +++ b/src/client/elm/Update/SignIn.elm @@ -1,13 +1,10 @@ module Update.SignIn - ( SignInAction(..) - , updateSignIn + ( updateSignIn ) where +import Model.Action.SignInAction exposing (..) import Model.View.SignInView exposing (..) -type SignInAction = - ErrorLogin String - updateSignIn : SignInAction -> SignInView -> SignInView updateSignIn action signInView = case action of -- cgit v1.2.3