aboutsummaryrefslogtreecommitdiff
path: root/src/client/Main.elm
blob: bff5f238eb23a528a4533dd5d6ddffcc28b2f02e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Main
  ( main
  ) where

{-| @docs main -}

import Graphics.Element exposing (..)

import Html exposing (Html)

import Http
import Task exposing (..)

import Model exposing (Model, initialModel)
import Model.Payment exposing (Payments, paymentsDecoder)

import Update exposing (Action(..), actions, updateModel)

import View.Page exposing (renderPage)

{-| main -}

main : Signal Html
main = Signal.map renderPage model

model : Signal Model
model = Signal.foldp updateModel initialModel actions.signal

port fetchPayments : Task Http.Error ()
port fetchPayments =
  getPayments
    |> flip Task.andThen reportSuccess
    |> flip Task.onError reportError

reportSuccess : Payments -> Task x ()
reportSuccess payments = Signal.send actions.address (UpdatePayments payments)

reportError : Http.Error -> Task x ()
reportError error = Signal.send actions.address Forbidden

getPayments : Task Http.Error Payments
getPayments = Http.get paymentsDecoder "/payments"