-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.elm
119 lines (91 loc) · 2.52 KB
/
Main.elm
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module Main (..) where
import Model exposing (Model)
import Layout exposing (Layout)
import Http
import Task exposing (Task)
import Layout.StartApp
import Effects exposing (Effects, Never)
import Dict exposing (Dict)
import Amount exposing (Amount)
import Number.Format
import Color
type State
= InitialLoad
| Active Model
type Action
= Init
| Load (Result Http.Error String)
| Debug String String Int
placeholderList : List a -> Layout
placeholderList list =
list
|> List.map Layout.placeholder
|> Layout.list 50
view : Signal.Address Action -> State -> Layout
view address m =
let
amount a =
case a.currency of
Amount.USD_Cents ->
toFloat a.value
|> flip (/) 100
|> Number.Format.pretty 2 ','
|> (++) "$"
|> Layout.text { size = 24, color = Color.black }
account a =
amount a.balance
|> Layout.left 150 (Layout.placeholder a.name)
debugAction title action =
Layout.placeholder title
|> Layout.onClick (Signal.message address action)
debugActions =
Layout.flow
( 100, 50 )
[ debugAction "Income $100" (Debug "income" "checking" 100)
, debugAction "Spend $12" (Debug "checking" "expenses" 12)
, debugAction "Spend $25" (Debug "checking" "expenses" 25)
]
in
case m of
InitialLoad ->
Layout.placeholder m
Active model ->
Dict.values model.accounts
|> List.map account
|> Layout.list 50
|> Layout.bottom 150 debugActions
update : Action -> State -> ( State, Effects Action )
update action m =
case ( action, m ) of
( Init, model ) ->
( model, Effects.none )
( Load _, InitialLoad ) ->
( Active Model.init, Effects.none )
( Load _, _ ) ->
( m, Effects.none )
( Debug from to dollars, Active model ) ->
case
model
|> Model.update (Model.Transaction (Amount (dollars * 100) Amount.USD_Cents) (Model.AccountId from) (Model.AccountId to))
of
Ok model' ->
( Active model', Effects.none )
Err message ->
( m, Effects.none )
( Debug _ _ _, _ ) ->
( m, Effects.none )
actions : Signal.Mailbox Action
actions =
Signal.mailbox Init
app =
Layout.StartApp.start
{ init = ( InitialLoad, Effects.task <| Task.map Load <| Task.toResult <| Http.getString "/" )
, inputs = []
, update = update
, view = view
}
port runner : Signal (Task Never ())
port runner =
app.tasks
main =
app.html