diff options
Diffstat (limited to 'src/client/Main.elm')
-rw-r--r-- | src/client/Main.elm | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/src/client/Main.elm b/src/client/Main.elm index dd87b8c..18a4aba 100644 --- a/src/client/Main.elm +++ b/src/client/Main.elm @@ -7,37 +7,26 @@ import Graphics.Element exposing (..) import Html exposing (Html) import Http -import Json.Decode as Json exposing ((:=)) import Task exposing (..) -import Date exposing (..) -import View.Page exposing (renderPage) +import Model exposing (Model, initialModel) +import Model.Payment exposing (Payments, paymentsDecoder) -main : Html -main = renderPage +import Update exposing (Action(..), actions, updateModel) -getPayments : Task Http.Error (List Payment) -getPayments = Http.get paymentsDecoder "/payments" +import View.Page exposing (renderPage) -type alias Payments = List Payment +main : Signal Html +main = Signal.map renderPage model -type alias Payment = - { creation : Date - , name : String - , cost : Int - , userName : String - } +model : Signal Model +model = Signal.foldp updateModel initialModel actions.signal -paymentsDecoder : Json.Decoder Payments -paymentsDecoder = Json.list paymentDecoder +port fetchPayments : Task Http.Error () +port fetchPayments = getPayments `Task.andThen` report -paymentDecoder : Json.Decoder Payment -paymentDecoder = - Json.object4 Payment - ("creation" := dateDecoder) - ("name" := Json.string) - ("cost" := Json.int) - ("userName" := Json.string) +report : Payments -> Task x () +report payments = Signal.send actions.address (UpdatePayments payments) -dateDecoder : Json.Decoder Date -dateDecoder = Json.customDecoder Json.string Date.fromString +getPayments : Task Http.Error Payments +getPayments = Http.get paymentsDecoder "/payments" |