70 lines
1.4 KiB
Elm
70 lines
1.4 KiB
Elm
|
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)
|
||
|
import Html.Attributes exposing (class, type_)
|
||
|
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 =
|
||
|
div [] (
|
||
|
all_modules
|
||
|
|> List.map (view_module_button model.enabled_modules)
|
||
|
)
|