aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update.elm
blob: f88a3a2314fe36eb12a82a7d36426575286c7f83 (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
module Update
  ( Action(..)
  , actions
  , updateModel
  ) where

import Model exposing (Model)
import Model.Payment exposing (Payments)
import Model.View as V
import Model.View.SignInView exposing (..)
import Model.View.PaymentView exposing (..)

import Update.SignIn exposing (..)
import Update.Payment exposing (..)

type Action =
  NoOp
  | GoSignInView
  | SignInError String
  | UpdateSignIn SignInAction
  | GoPaymentView Payments
  | UpdatePayment PaymentAction

actions : Signal.Mailbox Action
actions = Signal.mailbox NoOp

updateModel : Action -> Model -> Model
updateModel action model =
  case action of
    NoOp ->
      model
    GoSignInView ->
      { model | view <- V.SignInView initSignInView }
    GoPaymentView payments ->
      { model | view <- V.PaymentView (initPaymentView payments) }
    SignInError msg ->
      let signInView = { initSignInView | result <- Just (Err msg) }
      in  { model | view <- V.SignInView signInView }
    UpdateSignIn signInAction ->
      case model.view of
        V.SignInView signInView ->
          { model | view <- V.SignInView (updateSignIn signInAction signInView) }
        _ ->
          model
    UpdatePayment paymentAction ->
      case model.view of
        V.PaymentView paymentView ->
          { model | view <- V.PaymentView (updatePayment paymentAction paymentView) }
        _ ->
          model