module Main ( main ) where import Graphics.Element exposing (..) import Html exposing (Html) import Http import Task exposing (..) import Time exposing (..) import Json.Decode as Json exposing ((:=)) import Model exposing (Model, initialModel) import Model.Payment exposing (Payments, paymentsDecoder, perPage) import Model.Payers exposing (Payers, payersDecoder) import Model.Message exposing (messageDecoder) import Model.Translations exposing (..) import Update exposing (Action(..), actions, updateModel) import Update.SignIn exposing (..) import View.Page exposing (renderPage) import ServerCommunication exposing (serverCommunications, sendRequest) main : Signal Html main = Signal.map renderPage model model : Signal Model model = Signal.foldp updateModel (initialModel initialTime translations) update update : Signal Action update = Signal.mergeMany [ Signal.map UpdateTime (Time.every 30) , actions.signal ] --------------------------------------- port signInError : Maybe String --------------------------------------- port initialTime : Time --------------------------------------- port translations : String --------------------------------------- port initView : Task Http.Error () port initView = case signInError of Just msg -> Signal.send actions.address (SignInError msg) Nothing -> Task.map4 GoPaymentView getUserName getPayments getPaymentsCount getPayers |> flip Task.andThen (Signal.send actions.address) |> flip Task.onError (\_ -> 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?page=1&perPage=" ++ toString perPage) getPaymentsCount : Task Http.Error Int getPaymentsCount = Http.get ("number" := Json.int) "/payments/count" getPayers : Task Http.Error Payers getPayers = Http.get payersDecoder "/payments/total" --------------------------------------- port serverCommunicationsPort : Signal (Task Http.RawError ()) port serverCommunicationsPort = Signal.map (\comm -> sendRequest comm `Task.andThen` (Signal.send actions.address)) serverCommunications.signal