Update part1, part2, and part3

This commit is contained in:
Richard Feldman
2016-06-19 23:11:49 -07:00
parent 6418f537e7
commit 557cb6d4ce
6 changed files with 152 additions and 170 deletions

View File

@@ -1,103 +1,96 @@
module Main (..) where
module Main exposing (..)
import Html exposing (..)
import Html.App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Auth
import StartApp.Simple as StartApp
import Signal exposing (Address)
type alias Model =
{ query : String
, results : List SearchResult
}
{ query : String
, results : List SearchResult
}
type alias SearchResult =
{ id : ResultId
, name : String
, stars : Int
}
{ id : ResultId
, name : String
, stars : Int
}
type alias ResultId =
Int
Int
initialModel : Model
initialModel =
{ query = "tutorial"
, results =
[ { id = 1
, name = "TheSeamau5/elm-checkerboardgrid-tutorial"
, stars = 66
}
, { id = 2
, name = "grzegorzbalcerek/elm-by-example"
, stars = 41
}
, { id = 3
, name = "sporto/elm-tutorial-app"
, stars = 35
}
, { id = 4
, name = "jvoigtlaender/Elm-Tutorium"
, stars = 10
}
, { id = 5
, name = "sporto/elm-tutorial-assets"
, stars = 7
}
]
}
view : Address Action -> Model -> Html
view address model =
div
[ class "content" ]
[ header
[]
[ h1 [] [ text "ElmHub" ]
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
{ query = "tutorial"
, results =
[ { id = 1
, name = "TheSeamau5/elm-checkerboardgrid-tutorial"
, stars = 66
}
, { id = 2
, name = "grzegorzbalcerek/elm-by-example"
, stars = 41
}
, { id = 3
, name = "sporto/elm-tutorial-app"
, stars = 35
}
, { id = 4
, name = "jvoigtlaender/Elm-Tutorium"
, stars = 10
}
, { id = 5
, name = "sporto/elm-tutorial-assets"
, stars = 7
}
]
, ul
[ class "results" ]
(List.map (viewSearchResult address) model.results)
]
viewSearchResult : Address Action -> SearchResult -> Html
viewSearchResult address result =
li
[]
[ span [ class "star-count" ] [ text (toString result.stars) ]
, a
[ href ("https://github.com/" ++ result.name), target "_blank" ]
[ text result.name ]
, button
-- TODO add an onClick handler that sends a DELETE_BY_ID action
[ class "hide-result" ]
[ text "X" ]
]
type alias Action =
{ -- TODO implement this type alias
}
update : Action -> Model -> Model
update action model =
-- TODO if we receive a DELETE_BY_ID action,
-- build a new model without the given ID present anymore.
model
main =
StartApp.start
{ view = view
, update = update
, model = initialModel
}
view : Model -> Html Msg
view model =
div [ class "content" ]
[ header []
[ h1 [] [ text "ElmHub" ]
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
]
, ul [ class "results" ]
(List.map viewSearchResult model.results)
]
viewSearchResult : SearchResult -> Html Msg
viewSearchResult result =
li []
[ span [ class "star-count" ] [ text (toString result.stars) ]
, a [ href ("https://github.com/" ++ result.name), target "_blank" ]
[ text result.name ]
, button
-- TODO add an onClick handler that sends a DELETE_BY_ID action
[ class "hide-result" ]
[ text "X" ]
]
type alias Msg =
{ -- TODO implement this type alias
}
update : Msg -> Model -> Model
update msg model =
-- TODO if we receive a DELETE_BY_ID message,
-- build a new model without the given ID present anymore.
model
main : Program Never
main =
Html.App.beginnerProgram
{ view = view
, update = update
, model = initialModel
}