Update part4 and part5
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
module Main (..) where
|
module Main exposing (..)
|
||||||
|
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
|
import Html.App
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
|
||||||
import Auth
|
|
||||||
import StartApp.Simple as StartApp
|
|
||||||
import Json.Encode
|
|
||||||
import Signal exposing (Address)
|
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
@@ -58,12 +54,10 @@ initialModel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
view : Address Action -> Model -> Html
|
view : Model -> Html Msg
|
||||||
view address model =
|
view model =
|
||||||
div
|
div [ class "content" ]
|
||||||
[ class "content" ]
|
[ header []
|
||||||
[ header
|
|
||||||
[]
|
|
||||||
[ h1 [] [ text "ElmHub" ]
|
[ h1 [] [ text "ElmHub" ]
|
||||||
, span [ class "tagline" ] [ text "“Like GitHub, but for Elm things.”" ]
|
, span [ class "tagline" ] [ text "“Like GitHub, but for Elm things.”" ]
|
||||||
]
|
]
|
||||||
@@ -74,28 +68,16 @@ view address model =
|
|||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
, button [ class "search-button" ] [ text "Search" ]
|
, button [ class "search-button" ] [ text "Search" ]
|
||||||
, ul
|
, ul [ class "results" ]
|
||||||
[ class "results" ]
|
(List.map viewSearchResult model.results)
|
||||||
(List.map (viewSearchResult address) model.results)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
onInput : Address Action -> (String -> Action) -> Attribute
|
viewSearchResult : SearchResult -> Html Msg
|
||||||
onInput address wrap =
|
viewSearchResult result =
|
||||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
li []
|
||||||
|
|
||||||
|
|
||||||
defaultValue str =
|
|
||||||
property "defaultValue" (Json.Encode.string str)
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResult : Address Action -> SearchResult -> Html
|
|
||||||
viewSearchResult address result =
|
|
||||||
li
|
|
||||||
[]
|
|
||||||
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
||||||
, a
|
, a [ href ("https://github.com/" ++ result.name), target "_blank" ]
|
||||||
[ href ("https://github.com/" ++ result.name), target "_blank" ]
|
|
||||||
[ text result.name ]
|
[ text result.name ]
|
||||||
, button
|
, button
|
||||||
-- TODO add an onClick handler that sends a DeleteById action
|
-- TODO add an onClick handler that sends a DeleteById action
|
||||||
@@ -104,20 +86,21 @@ viewSearchResult address result =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
type Action
|
type Msg
|
||||||
= SetQuery String
|
= SetQuery String
|
||||||
| DeleteById ResultId
|
| DeleteById ResultId
|
||||||
|
|
||||||
|
|
||||||
update : Action -> Model -> Model
|
update : Msg -> Model -> Model
|
||||||
update action model =
|
update msg model =
|
||||||
-- TODO if we get a SetQuery action, use it to set the model's query field,
|
-- TODO if we get a SetQuery action, use it to set the model's query field,
|
||||||
-- and if we get a DeleteById action, delete the appropriate result
|
-- and if we get a DeleteById action, delete the appropriate result
|
||||||
model
|
model
|
||||||
|
|
||||||
|
|
||||||
|
main : Program Never
|
||||||
main =
|
main =
|
||||||
StartApp.start
|
Html.App.beginnerProgram
|
||||||
{ view = view
|
{ view = view
|
||||||
, update = update
|
, update = update
|
||||||
, model = initialModel
|
, model = initialModel
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
],
|
],
|
||||||
"exposed-modules": [],
|
"exposed-modules": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"elm-lang/core": "3.0.0 <= v < 4.0.0",
|
"elm-lang/core": "4.0.1 <= v < 5.0.0",
|
||||||
"evancz/elm-html": "4.0.0 <= v < 5.0.0",
|
"elm-lang/html": "1.0.0 <= v < 2.0.0"
|
||||||
"evancz/start-app": "2.0.0 <= v < 3.0.0"
|
|
||||||
},
|
},
|
||||||
"elm-version": "0.16.0 <= v < 0.17.0"
|
"elm-version": "0.17.0 <= v < 0.18.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
module Main (..) where
|
module Main exposing (..)
|
||||||
|
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (class, target, href, property)
|
import Html.App
|
||||||
|
import Html.Attributes exposing (class, target, href, property, defaultValue)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
import Auth
|
import Json.Decode exposing (Decoder)
|
||||||
import StartApp.Simple as StartApp
|
|
||||||
import Http
|
|
||||||
import Task exposing (Task)
|
|
||||||
import Effects exposing (Effects)
|
|
||||||
import Json.Decode exposing (Decoder, (:=))
|
|
||||||
import Json.Decode.Pipeline exposing (..)
|
import Json.Decode.Pipeline exposing (..)
|
||||||
import Json.Encode
|
|
||||||
import Signal exposing (Address)
|
|
||||||
|
|
||||||
|
|
||||||
|
main : Program Never
|
||||||
main =
|
main =
|
||||||
StartApp.start
|
Html.App.beginnerProgram
|
||||||
{ view = view
|
{ view = view
|
||||||
, update = update
|
, update = update
|
||||||
, model = initialModel
|
, model = initialModel
|
||||||
@@ -68,7 +63,7 @@ sampleJson =
|
|||||||
|
|
||||||
responseDecoder : Decoder (List SearchResult)
|
responseDecoder : Decoder (List SearchResult)
|
||||||
responseDecoder =
|
responseDecoder =
|
||||||
"items" := Json.Decode.list searchResultDecoder
|
Json.Decode.at [ "items" ] (Json.Decode.list searchResultDecoder)
|
||||||
|
|
||||||
|
|
||||||
searchResultDecoder : Decoder SearchResult
|
searchResultDecoder : Decoder SearchResult
|
||||||
@@ -115,54 +110,40 @@ decodeResults json =
|
|||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
view : Address Action -> Model -> Html
|
view : Model -> Html Msg
|
||||||
view address model =
|
view model =
|
||||||
div
|
div [ class "content" ]
|
||||||
[ class "content" ]
|
[ header []
|
||||||
[ header
|
|
||||||
[]
|
|
||||||
[ h1 [] [ text "ElmHub" ]
|
[ h1 [] [ text "ElmHub" ]
|
||||||
, span [ class "tagline" ] [ text "“Like GitHub, but for Elm things.”" ]
|
, span [ class "tagline" ] [ text "“Like GitHub, but for Elm things.”" ]
|
||||||
]
|
]
|
||||||
, input [ class "search-query", onInput address SetQuery, defaultValue model.query ] []
|
, input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
|
||||||
, button [ class "search-button" ] [ text "Search" ]
|
, button [ class "search-button" ] [ text "Search" ]
|
||||||
, ul
|
, ul [ class "results" ]
|
||||||
[ class "results" ]
|
(List.map viewSearchResult model.results)
|
||||||
(List.map (viewSearchResult address) model.results)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
onInput address wrap =
|
viewSearchResult : SearchResult -> Html Msg
|
||||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
viewSearchResult result =
|
||||||
|
li []
|
||||||
|
|
||||||
defaultValue str =
|
|
||||||
property "defaultValue" (Json.Encode.string str)
|
|
||||||
|
|
||||||
|
|
||||||
viewSearchResult : Address Action -> SearchResult -> Html
|
|
||||||
viewSearchResult address result =
|
|
||||||
li
|
|
||||||
[]
|
|
||||||
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
||||||
, a
|
, a [ href ("https://github.com/" ++ result.name), target "_blank" ]
|
||||||
[ href ("https://github.com/" ++ result.name), target "_blank" ]
|
|
||||||
[ text result.name ]
|
[ text result.name ]
|
||||||
, button
|
, button [ class "hide-result", onClick (DeleteById result.id) ]
|
||||||
[ class "hide-result", onClick address (DeleteById result.id) ]
|
|
||||||
[ text "X" ]
|
[ text "X" ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
type Action
|
type Msg
|
||||||
= SetQuery String
|
= SetQuery String
|
||||||
| DeleteById ResultId
|
| DeleteById ResultId
|
||||||
| SetResults (List SearchResult)
|
| SetResults (List SearchResult)
|
||||||
|
|
||||||
|
|
||||||
update : Action -> Model -> Model
|
update : Msg -> Model -> Model
|
||||||
update action model =
|
update msg model =
|
||||||
case action of
|
case msg of
|
||||||
SetQuery query ->
|
SetQuery query ->
|
||||||
{ model | query = query }
|
{ model | query = query }
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,15 @@
|
|||||||
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"source-directories": [
|
"source-directories": [
|
||||||
".", ".."
|
".",
|
||||||
|
".."
|
||||||
],
|
],
|
||||||
"exposed-modules": [],
|
"exposed-modules": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NoRedInk/elm-decode-pipeline": "1.0.0 <= v < 2.0.0",
|
"NoRedInk/elm-decode-pipeline": "1.0.0 <= v < 2.0.0",
|
||||||
"elm-lang/core": "3.0.0 <= v < 4.0.0",
|
"elm-lang/core": "4.0.1 <= v < 5.0.0",
|
||||||
"evancz/elm-effects": "2.0.0 <= v < 3.0.0",
|
"elm-lang/html": "1.0.0 <= v < 2.0.0",
|
||||||
"evancz/elm-html": "4.0.0 <= v < 5.0.0",
|
"evancz/elm-http": "3.0.1 <= v < 4.0.0"
|
||||||
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
|
|
||||||
"evancz/start-app": "2.0.0 <= v < 3.0.0"
|
|
||||||
},
|
},
|
||||||
"elm-version": "0.16.0 <= v < 0.17.0"
|
"elm-version": "0.17.0 <= v < 0.18.0"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user