🎨 elm-format

This commit is contained in:
Richard Feldman
2018-02-22 17:00:38 -05:00
parent 40c66a8a10
commit c8c89adc63
60 changed files with 4253 additions and 124 deletions

View File

@@ -1,9 +1,9 @@
port module ElmHub exposing (..)
import Html exposing (..)
import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value)
import Html.Events exposing (..)
import Auth
import Html exposing (..)
import Html.Attributes exposing (checked, class, defaultValue, href, placeholder, target, type_, value)
import Html.Events exposing (..)
import Json.Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (..)
import String
@@ -120,7 +120,7 @@ update msg model =
newModel =
{ model | results = newResults }
in
( newModel, Cmd.none )
( newModel, Cmd.none )
-- TODO add a new branch for SetTableState
-- which records the new tableState in the Model.
@@ -139,7 +139,7 @@ tableConfig =
{ toId = .id >> toString
, toMsg =
-- TODO have the table use SetTableState for its toMsg instead of:
(\tableState -> DoNothing)
\tableState -> DoNothing
, columns = [ starsColumn, nameColumn ]
}
@@ -191,22 +191,23 @@ view model =
-- TODO have this use the actual current table state
Table.initialSort "Stars"
in
div [ class "content" ]
[ header []
[ h1 [] [ text "ElmHub" ]
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
]
, div [ class "search" ]
[ Html.map Options (viewOptions model.options)
, div [ class "search-input" ]
[ input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
, button [ class "search-button", onClick Search ] [ text "Search" ]
]
]
, viewErrorMessage model.errorMessage
-- TODO have this use model.results instead of []
, Table.view tableConfig currentTableState []
div [ class "content" ]
[ header []
[ h1 [] [ text "ElmHub" ]
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ]
]
, div [ class "search" ]
[ Html.map Options (viewOptions model.options)
, div [ class "search-input" ]
[ input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
, button [ class "search-button", onClick Search ] [ text "Search" ]
]
]
, viewErrorMessage model.errorMessage
-- TODO have this use model.results instead of []
, Table.view tableConfig currentTableState []
]
viewErrorMessage : Maybe String -> Html msg
@@ -317,16 +318,17 @@ getQueryString : Model -> String
Try identifying patterns and writing helper functions which are responsible for
handling those patterns. Then have this function call them. Things to consider:
* There's pattern of adding "+foo:bar" - could we write a helper function for this?
* In one case, if the "bar" in "+foo:bar" is empty, we want to return "" instead
of "+foo:" - is this always true? Should our helper function always do that?
* We also join query parameters together with "=" and "&" a lot. Can we give
that pattern a similar treatment? Should we also take "?" into account?
- There's pattern of adding "+foo:bar" - could we write a helper function for this?
- In one case, if the "bar" in "+foo:bar" is empty, we want to return "" instead
of "+foo:" - is this always true? Should our helper function always do that?
- We also join query parameters together with "=" and "&" a lot. Can we give
that pattern a similar treatment? Should we also take "?" into account?
If you have time, give this refactor a shot and see how it turns out!
Writing something out the long way like this, and then refactoring to something
nicer, is generally the preferred way to go about building things in Elm.
-}
getQueryString : Model -> String
getQueryString model =
@@ -338,7 +340,7 @@ getQueryString model =
++ "+in:"
++ model.options.searchIn
++ "+stars:>="
++ (toString model.options.minStars)
++ toString model.options.minStars
++ "+language:elm"
++ (if String.isEmpty model.options.userFilter then
""