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/ServerCommunication.elm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/client/ServerCommunication.elm') diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index d763e29..ccf63f2 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -5,18 +5,21 @@ module ServerCommunication ) where import Signal -import Task -import Task exposing (Task) +import Task as Task exposing (Task) import Http import Json.Decode exposing (..) +import Date + +import Model.Message exposing (messageDecoder) import Update as U import Update.SignIn exposing (..) +import Update.Payment as UP type Communication = NoCommunication | SignIn String - | AddPayment String String + | AddPayment String Int | SignOut serverCommunications : Signal.Mailbox Communication @@ -47,7 +50,7 @@ getRequest communication = Just { verb = "post" , headers = [] - , url = "/payment/add?name=" ++ name ++ "&cost=" ++ cost + , url = "/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost) , body = Http.empty } SignOut -> @@ -67,8 +70,8 @@ communicationToAction communication response = U.NoOp SignIn login -> U.UpdateSignIn (ValidLogin login) - AddPayment _ _ -> - U.NoOp + AddPayment name cost -> + U.UpdatePayment (UP.AddPayment name cost) SignOut -> U.GoSignInView else @@ -86,7 +89,7 @@ decodeResponse : Http.Response -> (String -> U.Action) -> U.Action decodeResponse response responseToAction = case response.value of Http.Text text -> - case decodeString ("message" := string) text of + case decodeString messageDecoder text of Ok x -> responseToAction x Err _ -> -- cgit v1.2.3