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 untrusted user: Emi
GPG Key ID: A12F2C2FFDC3D847
4 changed files with 117 additions and 14 deletions

View File

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

View File

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

View File

@ -2,20 +2,31 @@ module Main exposing (main)
import Browser import Browser
import Sort.Set exposing (Set) import Sort.Set exposing (Set)
import Html exposing (Html, div, input, label, p, text, h3) import Html exposing (Html, div, input, label, p, section, text, h3)
import Html.Events exposing (onCheck) import Html.Events exposing (onCheck, onClick)
import Html.Attributes exposing (class, type_, id) import Html.Attributes exposing (class, type_, id)
import Modules exposing import Modules exposing
( Module ( Module
, all_modules , all_modules
, download_license
, DownloadType(..)
, module_property , module_property
, module_desc , module_desc
, module_sorter , module_sorter
) )
import Html.Attributes exposing (attribute)
main: Program () Model Msg main: Program () Model Msg
main = 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 -- INIT + Model
@ -24,15 +35,17 @@ type alias Model =
{ enabled_modules : Set Module { enabled_modules : Set Module
} }
init : Model init : () -> (Model, Cmd Msg)
init = init () =
{ enabled_modules = Sort.Set.empty module_sorter ( { enabled_modules = Sort.Set.empty module_sorter }
} , Cmd.none
)
-- UPDATE -- UPDATE
type Msg type Msg
= ToggleModule Module Bool = ToggleModule Module Bool
| Download DownloadType
add_or_remove : Bool -> (a -> Set a -> Set a) add_or_remove : Bool -> (a -> Set a -> Set a)
add_or_remove active = add_or_remove active =
@ -41,11 +54,15 @@ add_or_remove active =
else else
Sort.Set.remove Sort.Set.remove
update : Msg -> Model -> Model update : Msg -> Model -> (Model, Cmd Msg)
update msg model = update msg model =
case msg of case msg of
ToggleModule mod enabled -> 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 -- 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 -> Html Msg
view model = view model =
div [id "elm-area"] ( div [id "elm-area"]
all_modules [ view_modules model.enabled_modules
|> List.map (view_module_button model.enabled_modules) , downloads
) ]

View File

@ -1,6 +1,9 @@
module Modules exposing module Modules exposing
( Module ( Module
, all_modules , all_modules
, build_license
, download_license
, DownloadType(..)
, ModuleInfo , ModuleInfo
, module_info , module_info
, module_property , module_property
@ -11,6 +14,7 @@ module Modules exposing
import Html exposing (Html, text, a) import Html exposing (Html, text, a)
import Html.Attributes exposing (href) import Html.Attributes exposing (href)
import Sort exposing (Sorter) import Sort exposing (Sorter)
import File.Download as Download
type Module type Module
= CarbonUnderground = CarbonUnderground
@ -245,3 +249,35 @@ module_desc mod =
module_sorter : Sorter Module module_sorter : Sorter Module
module_sorter = Sort.by (module_property .index) Sort.increasing 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)