diff options
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r-- | src/client/ServerCommunication.elm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index e29b084..d581f82 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -8,8 +8,10 @@ import Signal import Task import Task exposing (Task) import Http +import Json.Decode exposing (..) import Update as U +import Update.SignIn exposing (..) type Communication = NoCommunication @@ -55,9 +57,29 @@ communicationToAction communication response = case communication of NoCommunication -> U.NoOp - SignIn _ -> - U.NoOp + SignIn login -> + U.UpdateSignIn (ValidLogin login) SignOut -> U.SignIn else + decodeResponse + response + (\error -> + case communication of + SignIn _ -> + U.UpdateSignIn (ErrorLogin error) + _ -> + U.NoOp + ) + +decodeResponse : Http.Response -> (String -> U.Action) -> U.Action +decodeResponse response responseToAction = + case response.value of + Http.Text text -> + case decodeString ("message" := string) text of + Ok x -> + responseToAction x + Err _ -> + U.NoOp + Http.Blob _ -> U.NoOp |