From 35493d8ec353f90a6ca67e2aedb702684e0abafa Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 20:49:24 +0100 Subject: Moving initViewAction to serverCommunication module --- src/client/elm/ServerCommunication.elm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/client/elm/ServerCommunication.elm') diff --git a/src/client/elm/ServerCommunication.elm b/src/client/elm/ServerCommunication.elm index ff0937e..bc8d59f 100644 --- a/src/client/elm/ServerCommunication.elm +++ b/src/client/elm/ServerCommunication.elm @@ -1,11 +1,12 @@ module ServerCommunication ( sendRequest + , initViewAction ) where import Signal import Task as Task exposing (Task) import Http -import Json.Decode exposing (..) +import Json.Decode as Json exposing ((:=)) import Date import Time exposing (Time) import Debug @@ -13,24 +14,21 @@ import Debug import SimpleHTTP exposing (..) import Model.Communication exposing (..) -import Model.Action as U +import Model.Action as U exposing (Action) import Model.Action.LoggedInAction as UL import Model.Action.MonthlyAction as UM import Model.Action.AccountAction as UA import Model.View.LoggedIn.AddPayment exposing (Frequency(..)) -import Model.Payment exposing (..) +import Model.Payment exposing (PaymentId, paymentIdDecoder, Payments, paymentsDecoder) +import Model.Payer exposing (Payers, payersDecoder) +import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder) import Update.SignIn exposing (updateSignIn) -import InitViewAction exposing (initViewAction) - sendRequest : Communication -> Task Http.Error U.Action sendRequest communication = case communication of - NoCommunication -> - Task.succeed U.NoOp - SignIn assertion -> post ("/signIn?assertion=" ++ assertion) |> flip Task.andThen (always initViewAction) @@ -68,3 +66,14 @@ addPaymentURL name cost frequency = deletePaymentURL : PaymentId -> String deletePaymentURL id = "payment/delete?id=" ++ (toString id) + +initViewAction = Task.onError loggedInView (always <| Task.succeed U.GoSignInView) + +loggedInView : Task Http.Error Action +loggedInView = + Task.map U.GoLoggedInView (Http.get usersDecoder "/users") + `Task.andMap` (Http.get ("id" := userIdDecoder) "/whoAmI") + `Task.andMap` (Http.get paymentsDecoder "/monthlyPayments") + `Task.andMap` (Http.get paymentsDecoder "/payments") + `Task.andMap` (Http.get ("number" := Json.int) "/payments/count") + `Task.andMap` (Http.get payersDecoder "/payers") -- cgit v1.2.3