Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. -- Read more about this program in the official Elm guide:
  2. -- https://guide.elm-lang.org/architecture/user_input/buttons.html
  3.  
  4. import Html exposing (beginnerProgram, div, button, text,input)
  5. import Html.Events exposing (onClick, onInput)
  6. import Html.Attributes exposing (style)
  7.  
  8. main =
  9. beginnerProgram { model = init , update = update, view = view} -- co sie stanie jak wyjebie stad model?
  10.  
  11. type alias Records = {
  12. name: String,
  13. date: String,
  14. priority: Int
  15. }
  16.  
  17. --fajnie by bylo jakby od razu sortowalo po priority
  18.  
  19. type alias Model = {
  20. input : String,
  21. tasks : List Records
  22. }
  23.  
  24. init : Model
  25. init = Model "" []
  26.  
  27. type Msg =
  28. Add
  29. | Del
  30. | DelCheckbox String
  31. | Input String
  32.  
  33. update msg model=
  34. case msg of
  35. Del ->
  36. (model.input (List.filter (\x-> x/=model.input) [model.tasks]))
  37. Add ->
  38. (model.input (List.append model.input [model.input]))
  39. -- Input str -> zero idea wat da fuck it is doing
  40. -- (model str model.tasks)
  41. DelCheckbox str -> --jak zmienic aby str bylo Records-em?
  42. (model.input (List.filter (\x-> x/= str) [model.tasks]))
  43.  
  44.  
  45.  
  46. view : Model -> Html.Html Msg
  47. view model =
  48. div []
  49. [ input [ onInput Input] []
  50. , button [onClick Add] [text "Add"]
  51. , button [onClick Del] [text "Delete"]
  52. , div [style [("padding", "50px")]] (List.map viewCheckbox model.tasks)
  53. ]
  54.  
  55. viewMessage : String -> Html.Html msg
  56. viewMessage msg =
  57. div [] [ text msg ]
  58.  
  59. viewCheckbox : Records -> Html.Html Msg
  60. viewCheckbox msg =
  61. div [] [ input [ Html.Attributes.type_ "checkbox", onClick (DelCheckbox msg)] []
  62. , text msg
  63. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement