1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00
Files
go-inbucket/ui/src/Page/Home.elm
2018-12-12 22:12:35 -08:00

67 lines
1.4 KiB
Elm

module Page.Home exposing (Model, Msg, init, update, view)
import Data.Session as Session exposing (Session)
import Html exposing (..)
import Html.Attributes exposing (..)
import Http
import HttpUtil
import Json.Encode as Encode
import Ports
-- MODEL --
type alias Model =
{ greeting : String }
init : ( Model, Cmd Msg, Session.Msg )
init =
let
cmdGreeting =
Http.get
{ url = "/serve/greeting"
, expect = Http.expectString GreetingLoaded
}
in
( Model "", cmdGreeting, Session.none )
-- UPDATE --
type Msg
= GreetingLoaded (Result Http.Error String)
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
update session msg model =
case msg of
GreetingLoaded (Ok greeting) ->
( Model greeting, Cmd.none, Session.none )
GreetingLoaded (Err err) ->
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
-- VIEW --
view : Session -> Model -> { title : String, modal : Maybe (Html msg), content : Html Msg }
view session model =
{ title = "Inbucket"
, modal = Nothing
, content =
div [ class "page" ]
[ Html.node "rendered-html"
[ class "greeting"
, property "content" (Encode.string model.greeting)
]
[]
]
}