This repository has been archived by the owner on Nov 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Landing.elm
112 lines (86 loc) · 2.2 KB
/
Landing.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
module Landing exposing (view)
-- IMPORTS
import Browser
import Html exposing (Html)
import Html.Attributes
import Util.View
-- MODEL
type alias Game =
{ color : String
, emoji : String
, slug : String
, state : State
, title : String
}
type State
= Available
| Unavailable
allGames : List Game
allGames =
[ { color = "yellow"
, emoji = "🏓"
, slug = "pong"
, state = Available
, title = "Pong"
}
, { color = "blue"
, emoji = "🛸"
, slug = "breakout"
, state = Available
, title = "Breakout"
}
, { color = "gray"
, emoji = "⚔️"
, slug = "adventure"
, state = Unavailable
, title = "Adventure"
}
, { color = "red"
, emoji = "🍄"
, slug = "mario"
, state = Unavailable
, title = "Mario"
}
]
-- VIEW
view : Browser.Document msg
view =
{ title = "🕹 Games"
, body =
[ Html.main_ [ Html.Attributes.class "flex flex-col min-h-screen" ]
[ viewGames allGames
, Util.View.footer
]
]
}
viewGames : List Game -> Html msg
viewGames games =
Html.section [ Html.Attributes.class "flex-grow" ]
[ games
|> List.filter isAvailable
|> List.map viewGame
|> Html.ul [ Html.Attributes.class "px-16 py-8" ]
]
viewGame : Game -> Html msg
viewGame { color, emoji, slug, title } =
Html.a [ Html.Attributes.href slug ]
[ Html.li
[ Html.Attributes.class <| colorToBorderClass color
, Html.Attributes.class <| colorToColorClass color
, Html.Attributes.class "hover:shadow-lg max-w-sm my-4 px-6 py-3 rounded-md shadow"
]
[ Html.span [ Html.Attributes.class "mr-2" ]
[ Html.text emoji ]
, Html.strong []
[ Html.text title ]
]
]
colorToBorderClass : String -> String
colorToBorderClass color =
"border-b-2 border-solid border-" ++ color ++ "-700"
colorToColorClass : String -> String
colorToColorClass color =
"bg-" ++ color ++ "-200"
isAvailable : Game -> Bool
isAvailable { state } =
state == Available