Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Created July 15, 2017 16:11
Show Gist options
  • Save johnwesonga/0dcfbadcdf56faad58a6dfadf6e8c2a7 to your computer and use it in GitHub Desktop.
Save johnwesonga/0dcfbadcdf56faad58a6dfadf6e8c2a7 to your computer and use it in GitHub Desktop.
module Main exposing (..)
import Html exposing (Html, div, fieldset, input, label, text)
import Html.Attributes exposing (name, style, type_)
import Html.Events exposing (onClick)
-- MODEL
type alias Model =
{ question : String
, choiceOne : Int
, choiceTwo : Int
}
type Party
= Jubilee
| NASA
| Wareva
type Msg
= NoOp
| Vote Party
initModel : Model
initModel =
{ question = ""
, choiceOne = 0
, choiceTwo = 0
}
-- UPDATE
update : Msg -> Model -> Model
update msg model =
case msg of
NoOp ->
model
Vote party ->
let
partyName =
toString party
in
if partyName == "Jubilee" then
{ model | choiceOne = model.choiceOne + 1 }
else if partyName == "NASA" then
{ model | choiceTwo = model.choiceTwo + 1 }
else
model
-- VIEW
view : Model -> Html Msg
view model =
div []
[ fieldset []
[ radio "Jubilee" (Vote Jubilee)
, radio "NASA" (Vote NASA)
, radio "Wareva!!" (Vote Wareva)
]
]
radio : String -> msg -> Html msg
radio value msg =
label
[ style [ ( "padding", "20px" ) ] ]
[ input [ type_ "radio", name "font-size", onClick msg ] []
, text value
]
main =
Html.beginnerProgram { model = initModel, view = view, update = update }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment