aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/Account/Update.elm
diff options
context:
space:
mode:
authorJoris2016-03-28 17:51:14 +0200
committerJoris2016-03-28 17:51:14 +0200
commit166cd04e4b28770ede854dafc9ae30eae64102fe (patch)
tree2245a31243a165acc6f7355534da44cfd17e6038 /src/client/elm/LoggedIn/Home/Account/Update.elm
parentb0d80a5458d7ba4546e5f01f5b6398ea6d23f981 (diff)
downloadbudget-166cd04e4b28770ede854dafc9ae30eae64102fe.tar.gz
budget-166cd04e4b28770ede854dafc9ae30eae64102fe.tar.bz2
budget-166cd04e4b28770ede854dafc9ae30eae64102fe.zip
Create an empty but reachable user page
Diffstat (limited to 'src/client/elm/LoggedIn/Home/Account/Update.elm')
-rw-r--r--src/client/elm/LoggedIn/Home/Account/Update.elm75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Home/Account/Update.elm b/src/client/elm/LoggedIn/Home/Account/Update.elm
new file mode 100644
index 0000000..8d002a3
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/Account/Update.elm
@@ -0,0 +1,75 @@
+module LoggedIn.Home.Account.Update
+ ( update
+ ) where
+
+import Maybe
+import Dict
+import Task
+
+import Effects exposing (Effects)
+
+import Server
+
+import LoggedIn.Home.Account.Action as AccountAction
+import LoggedIn.Home.Account.Model as AccountModel
+
+import Utils.Maybe exposing (isJust)
+
+update : AccountAction.Action -> AccountModel.Model -> (AccountModel.Model, Effects AccountAction.Action)
+update action account =
+ case action of
+
+ AccountAction.NoOp ->
+ (account, Effects.none)
+
+ AccountAction.ToggleDetail ->
+ ( { account | visibleDetail = not account.visibleDetail }
+ , Effects.none
+ )
+
+ AccountAction.ToggleIncomeEdition ->
+ ( { account | incomeEdition =
+ if isJust account.incomeEdition
+ then Nothing
+ else Just (AccountModel.initIncomeEdition (Maybe.withDefault 0 (AccountModel.getCurrentIncome account)))
+ }
+ , Effects.none
+ )
+
+ AccountAction.UpdateIncomeEdition income ->
+ case account.incomeEdition of
+ Just incomeEdition ->
+ ( { account | incomeEdition = Just { incomeEdition | income = income } }
+ , Effects.none
+ )
+ Nothing ->
+ ( account
+ , Effects.none
+ )
+
+ AccountAction.UpdateEditionError error ->
+ case account.incomeEdition of
+ Just incomeEdition ->
+ ( { account | incomeEdition = Just { incomeEdition | error = Just error } }
+ , Effects.none
+ )
+ Nothing ->
+ ( account
+ , Effects.none
+ )
+
+ AccountAction.UpdateIncome currentTime amount ->
+ ( account
+ , Server.setIncome currentTime amount
+ |> Task.map (\incomeId -> (AccountAction.ValidateUpdateIncome incomeId currentTime amount))
+ |> flip Task.onError (always <| Task.succeed AccountAction.NoOp)
+ |> Effects.task
+ )
+
+ AccountAction.ValidateUpdateIncome incomeId currentTime amount ->
+ ( { account
+ | incomes = Dict.insert incomeId { userId = account.me, creation = currentTime, amount = amount } account.incomes
+ , incomeEdition = Nothing
+ }
+ , Effects.none
+ )