module Update ( update ) where import Task import Effects exposing (Effects) import ServerCommunication exposing (sendRequest) import Model exposing (Model) import Model.Action exposing (..) import Model.View as V import Model.View.SignInView exposing (..) import Model.View.LoggedInView exposing (..) import Model.Communication exposing (Communication) import Update.LoggedIn exposing (updateLoggedIn) import Update.SignIn exposing (updateSignIn) update : Action -> Model -> (Model, Effects Action) update action model = case action of NoOp -> (model, Effects.none) ServerCommunication communication -> ( model , sendRequest communication |> flip Task.onError (always <| Task.succeed NoOp) |> Effects.task ) UpdateTime time -> ({ model | currentTime = time }, Effects.none) GoSignInView -> ({ model | view = V.SignInView initSignInView }, Effects.none) GoLoggedInView users me monthlyPayments payments paymentsCount payers -> ( { model | view = V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) } , Effects.none ) UpdateSignIn signInAction -> case model.view of V.SignInView signInView -> ( { model | view = V.SignInView (updateSignIn signInAction signInView) } , Effects.none ) _ -> (model, Effects.none) UpdateLoggedIn loggedAction -> case model.view of V.LoggedInView loggedInView -> ( { model | view = V.LoggedInView (updateLoggedIn model loggedAction loggedInView) } , Effects.none ) _ -> (model, Effects.none)