blob: 59f1402ed8c10a2eeee5f4f5d965a68cc09df0fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
module LoggedIn.Home.Account.Update
( update
) where
import Maybe
import Effects exposing (Effects)
import LoggedData exposing (LoggedData)
import LoggedIn.Home.Account.Action as AccountAction
import LoggedIn.Home.Account.Model as AccountModel
import Utils.Maybe exposing (isJust)
update : LoggedData -> AccountAction.Action -> AccountModel.Model -> (AccountModel.Model, Effects AccountAction.Action)
update loggedData 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 loggedData.incomes loggedData.me account)))
}
, Effects.none
)
AccountAction.UpdateIncomeEdition income ->
( case account.incomeEdition of
Nothing -> account
Just incomeEdition -> { account | incomeEdition = Just { incomeEdition | income = income } }
, Effects.none
)
AccountAction.UpdateEditionError error ->
( case account.incomeEdition of
Nothing -> account
Just incomeEdition -> { account | incomeEdition = Just { incomeEdition | error = Just error } }
, Effects.none
)
|