Commit 60288963 authored by André Espaze's avatar André Espaze
Browse files

Load initial series catalog

parent d9b02a42f7c2
{
"type": "application",
"source-directories": [
"elm"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"rtfeldman/elm-css": "16.0.1"
},
"indirect": {
"Skinney/murmur3": "2.0.8",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"rtfeldman/elm-hex": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
\ No newline at end of file
module Main exposing (main)
import Browser
import Dict
import Html.Styled exposing (..)
import Http
import Json.Decode as Decode
type alias Model =
{ series : List String
, status : Maybe String
}
type alias SeriesCatalog =
Dict.Dict String String
type Msg
= CatalogReceived (Result Http.Error SeriesCatalog)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
let
newModel x =
( x, Cmd.none )
in
case msg of
CatalogReceived (Ok x) ->
newModel { model | series = Dict.keys x }
CatalogReceived (Err _) ->
newModel { model | status = Just "Error on CatalogReceived" }
view : Model -> Html Msg
view model =
ul [] <| List.map (\x -> li [] [ text x ]) model.series
main : Program () Model Msg
main =
let
initialGet =
Http.get
{ expect = Http.expectJson CatalogReceived (Decode.dict Decode.string)
, url = "http://tshistory.test.pythonian.fr/series/catalog"
}
init _ =
( Model [] Nothing, initialGet )
in
Browser.element
{ init = init
, view = view >> toUnstyled
, update = update
, subscriptions = \_ -> Sub.none
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<!-- Minimal entry as provided by Elm in Action -->
<div id="app"></div>
<script src="elm.js"></script>
<script>
var app = Elm.Main.init({node: document.getElementById("app")});
</script>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment