ELOS-License-Builder/src/Main.elm

70 lines
1.4 KiB
Elm
Raw Normal View History

2022-02-01 22:33:58 +00:00
module Main exposing (main)
import Browser
import Sort.Set exposing (Set)
import Html exposing (Html, div, input, label, p, text, h3)
import Html.Events exposing (onCheck)
2022-02-02 19:31:07 +00:00
import Html.Attributes exposing (class, type_, id)
2022-02-01 22:33:58 +00:00
import Modules exposing
( Module
, all_modules
, module_property
, module_desc
, module_sorter
)
main: Program () Model Msg
main =
Browser.sandbox { init = init, update = update, view = view }
-- INIT + Model
type alias Model =
{ enabled_modules : Set Module
}
init : Model
init =
{ enabled_modules = Sort.Set.empty module_sorter
}
-- UPDATE
type Msg
= ToggleModule Module Bool
add_or_remove : Bool -> (a -> Set a -> Set a)
add_or_remove active =
if active then
Sort.Set.insert
else
Sort.Set.remove
update : Msg -> Model -> Model
update msg model =
case msg of
ToggleModule mod enabled ->
{ model | enabled_modules = add_or_remove enabled mod model.enabled_modules }
-- VIEW
view_module_button : Set Module -> Module -> Html Msg
view_module_button enabled mod =
label
(if Sort.Set.memberOf enabled mod then [class "active"] else [])
[ input
[ type_ "checkbox"
, onCheck (ToggleModule mod)
] []
, h3 [] [ text (module_property .name mod) ]
, p [] (module_desc mod)
]
view : Model -> Html Msg
view model =
2022-02-02 19:31:07 +00:00
div [id "elm-area"] (
2022-02-01 22:33:58 +00:00
all_modules
|> List.map (view_module_button model.enabled_modules)
)