blob: 39155483c6e662924420b870222d7d9695ed72fe (
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
73
74
|
module Dialog.Update exposing
( update
)
import Dom exposing (Id)
import Form exposing (Form)
import Form.Field as Field
import Task
import Dialog.AddCategory.Model as AddCategory
import Dialog.AddIncome.Model as AddIncome
import Dialog.AddPayment.Model as AddPayment
import Dialog.Model as Dialog
import Dialog.Msg as Dialog
import Model.Category exposing (Categories)
import Model.PaymentCategory as PaymentCategory exposing (PaymentCategories)
update : Dialog.Msg -> Dialog.Model -> (Dialog.Model, Cmd Dialog.Msg)
update msg model =
case msg of
Dialog.NoOp ->
( model
, Cmd.none
)
Dialog.Init inputId dialogMsg ->
update dialogMsg model
|> Tuple.mapSecond (\cmd -> Cmd.batch [cmd, inputFocus inputId])
Dialog.AddPaymentMsg categories paymentCategories formMsg ->
( { model
| addPayment =
Form.update (AddPayment.validation categories) formMsg model.addPayment
|> updateCategory categories paymentCategories formMsg
}
, Cmd.none
)
Dialog.AddIncomeMsg formMsg ->
( { model
| addIncome = Form.update AddIncome.validation formMsg model.addIncome
}
, Cmd.none
)
Dialog.AddCategoryMsg formMsg ->
( { model
| addCategory = Form.update AddCategory.validation formMsg model.addCategory
}
, Cmd.none
)
inputFocus : Id -> Cmd Dialog.Msg
inputFocus id =
Dom.focus id
|> Task.map (always Dialog.NoOp)
|> Task.onError (\_ -> Task.succeed Dialog.NoOp)
|> Task.perform (always Dialog.NoOp)
updateCategory : Categories -> PaymentCategories -> Form.Msg -> (Form String AddPayment.Model -> Form String AddPayment.Model)
updateCategory categories paymentCategories formMsg =
case formMsg of
Form.Input "name" Form.Text (Field.String paymentName) ->
case PaymentCategory.search paymentName paymentCategories of
Just category ->
Form.update
(AddPayment.validation categories)
(Form.Input "category" Form.Text (Field.String <| toString category))
Nothing ->
identity
_ ->
identity
|