aboutsummaryrefslogtreecommitdiff
path: root/src/client/Main.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Main.elm')
-rw-r--r--src/client/Main.elm35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/client/Main.elm b/src/client/Main.elm
index 678d20e..fd0cec7 100644
--- a/src/client/Main.elm
+++ b/src/client/Main.elm
@@ -10,9 +10,11 @@ import Html exposing (Html)
import Http
import Task exposing (..)
+import Time exposing (..)
import Model exposing (Model, initialModel)
import Model.Payment exposing (Payments, paymentsDecoder)
+import Model.Message exposing (messageDecoder)
import Update exposing (Action(..), actions, updateModel)
import Update.SignIn exposing (..)
@@ -27,34 +29,41 @@ main : Signal Html
main = Signal.map renderPage model
model : Signal Model
-model = Signal.foldp updateModel initialModel actions.signal
+model = Signal.foldp updateModel (initialModel initialTime) update
--------------------------
+update : Signal Action
+update = Signal.mergeMany
+ [ Signal.map UpdateTime (Time.every 30)
+ , actions.signal
+ ]
+
+---------------------------------------
port signInError : Maybe String
---------------------------------------
-port fetchPayments : Task Http.Error ()
-port fetchPayments =
+port initialTime : Time
+
+---------------------------------------
+
+port initView : Task Http.Error ()
+port initView =
case signInError of
Just msg ->
Signal.send actions.address (SignInError msg)
Nothing ->
- getPayments
- |> flip Task.andThen reportSuccess
- |> flip Task.onError reportError
-
-reportSuccess : Payments -> Task x ()
-reportSuccess payments = Signal.send actions.address (GoPaymentView payments)
+ Task.map2 GoPaymentView getUserName getPayments
+ |> flip Task.andThen (Signal.send actions.address)
+ |> flip Task.onError (\_ -> Signal.send actions.address GoSignInView)
-reportError : Http.Error -> Task x ()
-reportError error = Signal.send actions.address GoSignInView
+getUserName : Task Http.Error String
+getUserName = Http.get messageDecoder "/userName"
getPayments : Task Http.Error Payments
getPayments = Http.get paymentsDecoder "/payments"
----------------------------------------------------
+---------------------------------------
port serverCommunicationsPort : Signal (Task Http.RawError ())
port serverCommunicationsPort =