blob: fd0cec7546560d3e79af7d1193891796fb99c204 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
module Main
( main
) where
{-| @docs main -}
import Graphics.Element exposing (..)
import Html exposing (Html)
import Http
import Task exposing (..)
import Time exposing (..)
import Model exposing (Model, initialModel)
import Model.Payment exposing (Payments, paymentsDecoder)
import Model.Message exposing (messageDecoder)
import Update exposing (Action(..), actions, updateModel)
import Update.SignIn exposing (..)
import View.Page exposing (renderPage)
import ServerCommunication exposing (serverCommunications, sendRequest)
{-| main -}
main : Signal Html
main = Signal.map renderPage model
model : Signal Model
model = Signal.foldp updateModel (initialModel initialTime) update
update : Signal Action
update = Signal.mergeMany
[ Signal.map UpdateTime (Time.every 30)
, actions.signal
]
---------------------------------------
port signInError : Maybe String
---------------------------------------
port initialTime : Time
---------------------------------------
port initView : Task Http.Error ()
port initView =
case signInError of
Just msg ->
Signal.send actions.address (SignInError msg)
Nothing ->
Task.map2 GoPaymentView getUserName getPayments
|> 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"
---------------------------------------
port serverCommunicationsPort : Signal (Task Http.RawError ())
port serverCommunicationsPort =
Signal.map
(\comm -> sendRequest comm `Task.andThen` (Signal.send actions.address))
serverCommunications.signal
|