aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Update.elm')
-rw-r--r--src/client/Update.elm182
1 files changed, 0 insertions, 182 deletions
diff --git a/src/client/Update.elm b/src/client/Update.elm
deleted file mode 100644
index 4284b65..0000000
--- a/src/client/Update.elm
+++ /dev/null
@@ -1,182 +0,0 @@
-module Update exposing
- ( update
- )
-
-import Navigation exposing (Location)
-import Platform.Cmd exposing (Cmd)
-import Task
-
-import Dialog
-import Dialog.Update as DialogUpdate
-import LoggedIn.Model as LoggedIn
-import LoggedIn.Msg as LoggedIn
-import LoggedIn.Stat.Msg as Stat
-import LoggedIn.Update as LoggedIn
-import Model exposing (Model)
-import Model.Translations exposing (getMessage)
-import Model.View as V
-import Msg exposing (..)
-import Page exposing (Page(..))
-import Server
-import SignIn.Model as SignInModel
-import SignIn.Msg as SignInMsg
-import SignIn.Update as SignInUpdate
-import Tooltip
-import Utils.Cmd exposing ((:>))
-import Utils.Http exposing (errorKey)
-
-update : Msg -> Model -> (Model, Cmd Msg)
-update msg model =
- case msg of
-
- NoOp ->
- (model, Cmd.none)
-
- UpdatePage page ->
- ( { model | page = page }
- , if page == Statistics
- then
- let msg = UpdateLoggedIn <| LoggedIn.StatMsg <| Stat.UpdateChart
- in Task.perform (\_ -> msg) (Task.succeed ())
- else
- Cmd.none
- )
-
- SignIn email ->
- ( applySignIn model (SignInMsg.WaitingServer)
- , Server.signIn email (\result -> case result of
- Ok _ -> UpdateSignIn SignInMsg.ValidLogin
- Err error -> UpdateSignIn (SignInMsg.ErrorLogin (errorKey error))
- )
- )
-
- GoLoggedInView init ->
- ( { model | view = V.LoggedInView (LoggedIn.init model.currentTime init) }
- , Cmd.none
- )
-
- UpdateTime time ->
- ({ model | currentTime = time }, Cmd.none)
-
- GoSignInView ->
- ({ model | view = V.SignInView (SignInModel.init Nothing) }, Cmd.none)
-
- UpdateSignIn signInMsg ->
- (applySignIn model signInMsg, Cmd.none)
-
- UpdateLoggedIn loggedInMsg ->
- applyLoggedIn model loggedInMsg
-
- SignOut ->
- ( model
- , Server.signOut (\result -> case result of
- Ok _ -> GoSignInView
- Err _ -> Error "SignOutError"
- )
- )
-
- Error error ->
- ({ model | errors = model.errors ++ [ error ] }, Cmd.none)
-
- Dialog dialogMsg ->
- Dialog.update DialogUpdate.update dialogMsg model.dialog.model model.dialog
- |> Tuple.mapFirst (\dialog -> { model | dialog = dialog })
- :> update (Tooltip Tooltip.HideMessage)
-
- Tooltip tooltipMsg ->
- let (newTooltip, command) = Tooltip.update tooltipMsg model.tooltip
- in ( { model | tooltip = newTooltip }
- , Cmd.map Tooltip command
- )
-
- CreatePayment name cost date category frequency ->
- ( model
- , Server.createPayment name cost date category frequency (\result -> case result of
- Ok paymentId -> UpdateLoggedIn <| LoggedIn.ValidateCreatePayment paymentId name cost date category frequency
- Err _ -> Error "CreatePaymentError"
- )
- )
-
- EditPayment paymentId name cost date category frequency ->
- ( model
- , Server.editPayment paymentId name cost date category frequency (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateEditPayment paymentId name cost date category frequency
- Err _ -> Error "EditPaymentError"
- )
- )
-
- DeletePayment paymentId ->
- ( model
- , Server.deletePayment paymentId (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateDeletePayment paymentId
- Err _ -> Error "DeletePaymentError"
- )
- )
-
- CreateIncome amount date ->
- ( model
- , Server.createIncome amount date (\result -> case result of
- Ok incomeId -> UpdateLoggedIn <| LoggedIn.ValidateCreateIncome incomeId amount date
- Err _ -> Error "CreateIncomeError"
- )
- )
-
- EditIncome incomeId amount date ->
- ( model
- , Server.editIncome incomeId amount date (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateEditIncome incomeId amount date
- Err _ -> Error "EditIncomeError"
- )
- )
-
- DeleteIncome incomeId ->
- ( model
- , Server.deleteIncome incomeId (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateDeleteIncome incomeId
- Err _ -> Error "DeleteIncomeError"
- )
- )
-
- CreateCategory name color ->
- ( model
- , Server.createCategory name color (\result -> case result of
- Ok categoryId -> UpdateLoggedIn <| LoggedIn.ValidateCreateCategory categoryId name color
- Err _ -> Error "CreateCategoryError"
- )
- )
-
- EditCategory categoryId name color ->
- ( model
- , Server.editCategory categoryId name color (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateEditCategory categoryId name color
- Err _ -> Error "EditCategoryError"
- )
- )
-
- DeleteCategory categoryId ->
- ( model
- , Server.deleteCategory categoryId (\result -> case result of
- Ok _ -> UpdateLoggedIn <| LoggedIn.ValidateDeleteCategory categoryId
- Err _ -> Error "DeleteCategoryError"
- )
- )
-
-
-applySignIn : Model -> SignInMsg.Msg -> Model
-applySignIn model signInMsg =
- case model.view of
- V.SignInView signInView ->
- { model | view = V.SignInView (SignInUpdate.update model.translations signInMsg signInView) }
- _ ->
- model
-
-applyLoggedIn : Model -> LoggedIn.Msg -> (Model, Cmd Msg)
-applyLoggedIn model loggedInMsg =
- case model.view of
- V.LoggedInView loggedInView ->
- let (view, cmd) = LoggedIn.update model loggedInMsg loggedInView
- in ( { model | view = V.LoggedInView view }
- , Cmd.map UpdateLoggedIn cmd
- )
- _ ->
- (model, Cmd.none)