Update styles and some part7 stuff
This commit is contained in:
@@ -37,7 +37,7 @@ responseDecoder =
|
||||
searchResultDecoder : Decoder SearchResult
|
||||
searchResultDecoder =
|
||||
decode SearchResult
|
||||
|> required "id" Json.Decode.int
|
||||
|> required "idaa" Json.Decode.int
|
||||
|> required "full_name" Json.Decode.string
|
||||
|> required "stargazers_count" Json.Decode.int
|
||||
|
||||
@@ -56,7 +56,7 @@ performAction successToAction errorToAction task =
|
||||
type alias Model =
|
||||
{ query : String
|
||||
, results : List SearchResult
|
||||
, errorMessage : String
|
||||
, errorMessage : Maybe String
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ initialModel : Model
|
||||
initialModel =
|
||||
{ query = "tutorial"
|
||||
, results = []
|
||||
, errorMessage = ""
|
||||
, errorMessage = Nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -90,12 +90,23 @@ view address model =
|
||||
]
|
||||
, input [ class "search-query", onInput address SetQuery, defaultValue model.query ] []
|
||||
, button [ class "search-button", onClick address Search ] [ text "Search" ]
|
||||
, viewErrorMessage model.errorMessage
|
||||
, ul
|
||||
[ class "results" ]
|
||||
(List.map (viewSearchResult address) model.results)
|
||||
]
|
||||
|
||||
|
||||
viewErrorMessage : Maybe String -> Html
|
||||
viewErrorMessage errorMessage =
|
||||
case errorMessage of
|
||||
Just message ->
|
||||
div [ class "error" ] [ text message ]
|
||||
|
||||
Nothing ->
|
||||
text ""
|
||||
|
||||
|
||||
onInput address wrap =
|
||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
||||
|
||||
@@ -132,16 +143,20 @@ update action model =
|
||||
Search ->
|
||||
( model, Effects.task (searchFeed model.query) )
|
||||
|
||||
HandleSearchResponse response ->
|
||||
-- TODO update the model to incorporate these search results.
|
||||
-- Hint: where would you look to find out the type of `response` here?
|
||||
( model, Effects.none )
|
||||
HandleSearchResponse results ->
|
||||
( { model | results = results }, Effects.none )
|
||||
|
||||
HandleSearchError error ->
|
||||
-- TODO if decoding failed, store the message in model.errorMessage
|
||||
-- Hint: look for "decode" in the documentation for this union type:
|
||||
-- http://package.elm-lang.org/packages/evancz/elm-http/3.0.0/Http#Error
|
||||
( model, Effects.none )
|
||||
let
|
||||
errorMessage =
|
||||
case error of
|
||||
Http.UnexpectedPayload message ->
|
||||
Just message
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
in
|
||||
( { model | errorMessage = errorMessage }, Effects.none )
|
||||
|
||||
SetQuery query ->
|
||||
( { model | query = query }, Effects.none )
|
||||
|
||||
@@ -16,9 +16,15 @@ to fail; in that case, just run `elm package install` again.)
|
||||
elm live Main.elm --open -- --output=elm.js
|
||||
```
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
cd test
|
||||
elm package install
|
||||
elm test TestRunner.elm
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
* [HTTP Tasks tutorial](http://elm-lang.org/guide/reactivity#http-tasks)
|
||||
* [HTTP Error documentation](http://package.elm-lang.org/packages/evancz/elm-http/3.0.0/Http#Error)
|
||||
* [Modules syntax reference](http://elm-lang.org/docs/syntax#modules)
|
||||
* [Syntax reference for **case-expressions** and **if-expressions**](http://elm-lang.org/docs/syntax#conditionals)
|
||||
* [elm-test documentation](http://package.elm-lang.org/packages/deadfoxygrandpa/elm-test/3.1.1/)
|
||||
* [`(<|)` documentation](http://package.elm-lang.org/packages/elm-lang/core/3.0.0/Basics#<|)
|
||||
|
||||
@@ -90,3 +90,12 @@ a:hover {
|
||||
button:focus, input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color: #FF9632;
|
||||
padding: 20px;
|
||||
box-sizing: border-box;
|
||||
overflow-x: auto;
|
||||
font-family: monospace;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user