Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created April 21, 2016 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/c4dcad94473cfc5f5000c2492eebb815 to your computer and use it in GitHub Desktop.
Save chuck0523/c4dcad94473cfc5f5000c2492eebb815 to your computer and use it in GitHub Desktop.
-- view
view : Signal.Address Action -> Model -> Html
view address model =
let
todos = List.map (viewTodos address) model.todos
addButton = getAddButton address model.addText
in
div [ todosStyle ]
[ input
[ placeholder "enter todo"
, value model.addText
, on "input" targetValue ( Signal.message address << InputText)
]
[]
, addButton
, div
[] (todos)
]
viewTodos : Signal.Address Action -> (ID, Todo.Model) -> Html
viewTodos address (id, model) =
Todo.view (Signal.forwardTo address (Modify id)) model
getAddButton : Signal.Address Action -> String -> Html
getAddButton address addText =
if addText == ""
then
button
[ isDisbledButton ]
[ text "Add" ]
else
button
[ onClick address Add ]
[ text "Add" ]
todosStyle : Attribute
todosStyle =
style
[ ("margin", "10px")
]
textareaStyle : Attribute
textareaStyle =
style
[ ("margin-right", "5px")
, ("height", "20px")
]
isDisbledButton : Attribute
isDisbledButton =
style
[ ("color", "#999")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment