From 2a53fe50c62d4b7aec0f422998c743f68aa523c1 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Tue, 21 Jul 2015 23:25:58 +0200 Subject: Adding the payment without reloading the page --- src/client/Main.elm | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/client/Main.elm') 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 = -- cgit v1.2.3