-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlbionRecipes.elm
140 lines (107 loc) · 3.01 KB
/
AlbionRecipes.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module AlbionRecipes exposing (..)
import Http
import Html exposing (..)
import Html.Attributes exposing (class)
import Html.Events exposing (onClick, on)
import Recipes exposing (..)
type alias Model =
{ selectedRecipe : Maybe Product
, loadingError : Maybe Http.Error
}
initialModel : Model
initialModel =
{ selectedRecipe = Nothing
, loadingError = Nothing
}
type Msg
= NoRecipe
| SelectRecipe Product
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SelectRecipe product ->
( { model | selectedRecipe = Just product }, Cmd.none )
NoRecipe ->
( { model | selectedRecipe = Nothing }, Cmd.none )
main : Program Never Model Msg
main =
Html.program
{ init = ( initialModel, Cmd.none )
, view = view
, update = update
, subscriptions = (\_ -> Sub.none)
}
view : Model -> Html Msg
view model =
let
selectedRecipe =
case model.selectedRecipe of
Nothing ->
text ""
Just product ->
product |> toRecipe |> printRecipe
in
div [ class "content" ]
[ h1 [] [ text "Albion Recipes" ]
, div []
[ printAllProducts
, selectedRecipe
]
]
toRecipe : Product -> Recipe
toRecipe product =
case product of
BeanSalad ->
beanSaladRecipe
printRecipe : Recipe -> Html Msg
printRecipe recipe =
div [ class "column" ]
[ div []
[ printProduct recipe.product
, printIngredient recipe.ingredient1
, printIngredient recipe.ingredient2
, printIngredient recipe.ingredient3
, printIngredient recipe.ingredient4
]
]
printProduct : Product -> Html Msg
printProduct product =
h4 [ onClick (SelectRecipe product) ] [ product |> productTypeToString |> text ]
productTypeToString : Product -> String
productTypeToString product =
case product of
BeanSalad ->
"Bean Salad"
printIngredient : Maybe Ingredient -> Html Msg
printIngredient ingredient =
let
processedIngredient =
ingredient |> Maybe.withDefault noIngredient
in
div []
[ processedIngredient
|> .ingredientType
|> ingredientTypeToString
|> text
, processedIngredient
|> .amountNeeded
|> toString
|> (++) " -- "
|> text
]
ingredientTypeToString : IngredientType -> String
ingredientTypeToString ingredientType =
case ingredientType of
NoIngredient ->
"none"
Carrots ->
"Carrots"
Beans ->
"Beans"
Bread ->
"Bread"
Sheeps_Butter ->
"Sheep's Butter"
printAllProducts : Html Msg
printAllProducts =
List.map printProduct allProducts |> div [ class "column" ]