aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Update.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Update.elm')
-rw-r--r--src/client/elm/Update.elm57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm
new file mode 100644
index 0000000..3c4614a
--- /dev/null
+++ b/src/client/elm/Update.elm
@@ -0,0 +1,57 @@
+module Update
+ ( Action(..)
+ , actions
+ , updateModel
+ ) where
+
+import Time exposing (Time)
+
+import Model exposing (Model)
+import Model.User exposing (Users, UserId)
+import Model.Payment exposing (Payments)
+import Model.Payer exposing (Payers)
+import Model.View as V
+import Model.View.SignInView exposing (..)
+import Model.View.LoggedInView exposing (..)
+
+import Update.SignIn exposing (..)
+import Update.LoggedIn exposing (..)
+
+type Action =
+ NoOp
+ | UpdateTime Time
+ | GoSignInView
+ | SignInError String
+ | UpdateSignIn SignInAction
+ | GoLoggedInView Users UserId Payments Payments Int Payers
+ | UpdateLoggedIn LoggedAction
+
+actions : Signal.Mailbox Action
+actions = Signal.mailbox NoOp
+
+updateModel : Action -> Model -> Model
+updateModel action model =
+ case action of
+ NoOp ->
+ model
+ UpdateTime time ->
+ { model | currentTime <- time }
+ GoSignInView ->
+ { model | view <- V.SignInView initSignInView }
+ GoLoggedInView users me monthlyPayments payments paymentsCount payers ->
+ { model | view <- V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) }
+ 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
+ UpdateLoggedIn loggedAction ->
+ case model.view of
+ V.LoggedInView loggedInView ->
+ { model | view <- V.LoggedInView (updateLoggedIn model loggedAction loggedInView) }
+ _ ->
+ model