Model some download buttons

This commit is contained in:
Emi Simpson 2022-02-02 19:51:31 -05:00
parent 07b0b9ea29
commit 04af1baf4e
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847
4 changed files with 117 additions and 14 deletions

View file

@ -8,10 +8,12 @@
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/file": "1.0.5",
"elm/html": "1.0.0",
"rtfeldman/elm-sorter-experiment": "2.1.1"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",

View file

@ -96,11 +96,12 @@ header {
}
}
#elm-area {
#modules {
display: grid;
grid-template-columns: 50% 50%;
gap: 50px;
margin: 0 -180px;
margin-bottom: 50px;
.module-button > div {
box-sizing: border-box;
@ -134,6 +135,12 @@ header {
}
}
#downloads {
display: grid;
grid-template-columns: auto auto auto;
width: 100%;
}
.cooler-checkbox {
height: 40px;
width: 40px;

View file

@ -2,20 +2,31 @@ 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 exposing (Html, div, input, label, p, section, text, h3)
import Html.Events exposing (onCheck, onClick)
import Html.Attributes exposing (class, type_, id)
import Modules exposing
( Module
, all_modules
, download_license
, DownloadType(..)
, module_property
, module_desc
, module_sorter
)
import Html.Attributes exposing (attribute)
main: Program () Model Msg
main =
Browser.sandbox { init = init, update = update, view = view }
Browser.element
{ init = init
, update = update
, view = view
, subscriptions = subscriptions
}
subscriptions : Model -> Sub Msg
subscriptions _ = Sub.none
-- INIT + Model
@ -24,15 +35,17 @@ type alias Model =
{ enabled_modules : Set Module
}
init : Model
init =
{ enabled_modules = Sort.Set.empty module_sorter
}
init : () -> (Model, Cmd Msg)
init () =
( { enabled_modules = Sort.Set.empty module_sorter }
, Cmd.none
)
-- UPDATE
type Msg
= ToggleModule Module Bool
| Download DownloadType
add_or_remove : Bool -> (a -> Set a -> Set a)
add_or_remove active =
@ -41,11 +54,15 @@ add_or_remove active =
else
Sort.Set.remove
update : Msg -> Model -> Model
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
ToggleModule mod enabled ->
{ model | enabled_modules = add_or_remove enabled mod model.enabled_modules }
( { model | enabled_modules = add_or_remove enabled mod model.enabled_modules }
, Cmd.none
)
Download dtype ->
( model , download_license dtype (Sort.Set.toList model.enabled_modules) )
-- VIEW
@ -67,9 +84,50 @@ view_module_button enabled mod =
]
]
view_modules : Set Module -> Html Msg
view_modules modules =
section [id "modules"] (
all_modules
|> List.map (view_module_button modules)
)
view_cooler_button : String -> msg -> Html msg
view_cooler_button name message =
div
[ class "cool-button"
, onClick message
]
[ div
[ class "bevel"
, class "tr"
, attribute "aria-hidden" "true"
] []
, div [] [ text name ]
, div
[ class "bevel"
, class "bl"
, attribute "aria-hidden" "true"
] []
]
view_download_button : (String, DownloadType) -> Html Msg
view_download_button (name, dtype) =
view_cooler_button name (Download dtype)
downloads : Html Msg
downloads =
section [id "downloads"]
( List.map view_download_button
[ ("Markdown", Markdown)
, ("Plaintext", Plain)
, ("HTML", Html)
]
)
view : Model -> Html Msg
view model =
div [id "elm-area"] (
all_modules
|> List.map (view_module_button model.enabled_modules)
)
div [id "elm-area"]
[ view_modules model.enabled_modules
, downloads
]

View file

@ -1,6 +1,9 @@
module Modules exposing
( Module
, all_modules
, build_license
, download_license
, DownloadType(..)
, ModuleInfo
, module_info
, module_property
@ -11,6 +14,7 @@ module Modules exposing
import Html exposing (Html, text, a)
import Html.Attributes exposing (href)
import Sort exposing (Sorter)
import File.Download as Download
type Module
= CarbonUnderground
@ -245,3 +249,35 @@ module_desc mod =
module_sorter : Sorter Module
module_sorter = Sort.by (module_property .index) Sort.increasing
-- License Building
type DownloadType
= Plain
| Markdown
| Html
download_mime : DownloadType -> String
download_mime dtype =
case dtype of
Plain -> "text/plain"
Markdown -> "text/markdown"
Html -> "text/html"
download_ext : DownloadType -> String
download_ext dtype =
case dtype of
Plain -> "txt"
Markdown -> "md"
Html -> "html"
build_license : DownloadType -> List Module -> String
build_license dtype modules =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!"
download_license : DownloadType -> List Module -> Cmd msg
download_license dtype modules =
Download.string
("LICENSE." ++ (download_ext dtype))
(download_mime dtype)
(build_license dtype modules)