diff options
author | Joris Guyonvarch | 2015-07-21 23:25:58 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-07-21 23:25:58 +0200 |
commit | 2a53fe50c62d4b7aec0f422998c743f68aa523c1 (patch) | |
tree | ad32464c99668b477c4006146ec218c947bc9c8f /src/client/Main.elm | |
parent | a271d6034bc4cc631a64476d25d21c83a701fa39 (diff) |
Adding the payment without reloading the page
Diffstat (limited to 'src/client/Main.elm')
-rw-r--r-- | src/client/Main.elm | 35 |
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 = |