Created
June 26, 2016 07:12
-
-
Save martimatix/8f91db81f6643bcf69040910fcff866b to your computer and use it in GitHub Desktop.
movie_poster_finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (..) | |
import Html.App as Html | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
-- MODEL | |
type alias Model = | |
{ searchString : String | |
, title: String | |
, posterUrl : String | |
} | |
init : (Model, Cmd Msg) | |
init = | |
( Model "Frozen" "" "waiting.gif" | |
, Cmd.none | |
) | |
-- UPDATE | |
type Msg | |
= ChangeMovieTitle String | |
update : Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
ChangeMovieTitle newSearchString -> | |
{ model | title = newSearchString } ! [] | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ input [ placeholder "enter a movie title" | |
, autofocus True | |
, onInput ChangeMovieTitle | |
] [] | |
, button [] [ text "Get poster!" ] | |
, br [] [] | |
, h1 [] [ text model.title ] | |
, img [src model.posterUrl] [] | |
] | |
-- SUBSCRIPTIONS | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment