aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/Update.elm
blob: b43ebb7469bc82a0fbc45c1b245ed5023745a1a0 (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
50
51
52
module LoggedIn.Home.Update
  ( update
  ) where

import Effects exposing (Effects)

import LoggedData exposing (LoggedData)

import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel

import LoggedIn.Home.Account.Action as AccountAction
import LoggedIn.Home.Account.Update as AccountUpdate

import LoggedIn.Home.AddPayment.Update as AddPaymentUpdate

update : LoggedData -> HomeAction.Action -> HomeModel.Model -> (HomeModel.Model, Effects HomeAction.Action)
update loggedData action homeModel =
  case action of

    HomeAction.NoOp -> (homeModel, Effects.none)

    HomeAction.UpdateAdd addPaymentAction ->
      ( { homeModel | add = AddPaymentUpdate.update addPaymentAction homeModel.add }
      , Effects.none
      )

    HomeAction.UpdateAccount accountAction ->
      let (newAccount, accountEffects) = AccountUpdate.update loggedData accountAction homeModel.account
      in  ( { homeModel | account = newAccount }
          , Effects.map HomeAction.UpdateAccount accountEffects
          )

    HomeAction.ToggleEdit id ->
      ( { homeModel | paymentEdition = if homeModel.paymentEdition == Just id then Nothing else Just id }
      , Effects.none
      )

    HomeAction.UpdatePage page ->
      ( { homeModel | currentPage = page }
      , Effects.none
      )

    HomeAction.ShowMonthlyDetail ->
      ( { homeModel | monthlyDetail = True }
      , Effects.none
      )

    HomeAction.ToggleMonthlyDetail ->
      ( { homeModel | monthlyDetail = not homeModel.monthlyDetail }
      , Effects.none
      )