Add text search
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Closes #10
This commit is contained in:
parent
ff91ecb74e
commit
41e0fe9581
|
@ -1,7 +1,7 @@
|
|||
module Pages.Top exposing (Model, Msg, Params, page)
|
||||
|
||||
import Enum exposing (Enum)
|
||||
import Html exposing (Html, a, button, div, h2, h5, i, img, li, p, span, text, ul, form, label, select, option)
|
||||
import Html exposing (Html, a, button, div, h2, h5, i, img, li, p, span, text, ul, form, label, select, option, input)
|
||||
import Html.Attributes exposing (alt, class, href, src, style, id, for, value)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
|
@ -50,6 +50,7 @@ type alias App =
|
|||
type alias Model =
|
||||
{ filter_score : Maybe Int
|
||||
, filter_category : Maybe Category
|
||||
, filter_text : Maybe String
|
||||
, status : Status
|
||||
, apps : (List App)
|
||||
, results : (List App)
|
||||
|
@ -91,7 +92,8 @@ default_image =
|
|||
|
||||
default_model : Model
|
||||
default_model =
|
||||
{ filter_score = Nothing, filter_category = Nothing, status = Loading, apps = [], results = [] }
|
||||
{ filter_score = Nothing, filter_category = Nothing, filter_text = Nothing,
|
||||
status = Loading, apps = [], results = [] }
|
||||
|
||||
|
||||
-- UPDATE
|
||||
|
@ -101,6 +103,7 @@ type Msg
|
|||
= MorePlease
|
||||
| FilterScore String
|
||||
| FilterCategory String
|
||||
| FilterText String
|
||||
| GotApps (Result Http.Error (List App))
|
||||
|
||||
|
||||
|
@ -124,6 +127,22 @@ filterAppsCategory apps category =
|
|||
Nothing ->
|
||||
apps
|
||||
|
||||
filterAppsText : List App -> Maybe String -> List App
|
||||
filterAppsText apps text =
|
||||
case text of
|
||||
Just "" ->
|
||||
apps
|
||||
Just t ->
|
||||
List.filter (\app ->
|
||||
String.contains (String.toLower t) (
|
||||
String.toLower app.name ++ String.toLower (
|
||||
Maybe.withDefault "" app.description
|
||||
)
|
||||
)
|
||||
) apps
|
||||
Nothing ->
|
||||
apps
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
|
@ -137,7 +156,9 @@ update msg model =
|
|||
( { model
|
||||
| filter_score = filter_score
|
||||
, results = filterAppsScore (
|
||||
filterAppsCategory model.apps model.filter_category
|
||||
filterAppsCategory (
|
||||
filterAppsText model.apps model.filter_text
|
||||
) model.filter_category
|
||||
) (String.toInt filter)
|
||||
}, Cmd.none )
|
||||
|
||||
|
@ -148,10 +169,22 @@ update msg model =
|
|||
( { model
|
||||
| filter_category = category
|
||||
, results = filterAppsCategory (
|
||||
filterAppsScore model.apps model.filter_score
|
||||
filterAppsScore (
|
||||
filterAppsText model.apps model.filter_text
|
||||
)model.filter_score
|
||||
) category
|
||||
}, Cmd.none )
|
||||
|
||||
FilterText filter ->
|
||||
( { model
|
||||
| filter_text = Just filter
|
||||
, results = filterAppsText (
|
||||
filterAppsScore (
|
||||
filterAppsCategory model.apps model.filter_category
|
||||
) model.filter_score
|
||||
) (Just filter)
|
||||
}, Cmd.none )
|
||||
|
||||
GotApps result ->
|
||||
case result of
|
||||
Ok apps ->
|
||||
|
@ -320,10 +353,12 @@ viewApps model =
|
|||
, option [ value "4" ] [ text "4 (pre-alpha)" ]
|
||||
]
|
||||
, label [ for "category" ] [ text "Category" ]
|
||||
, select [ class "ml-2 form-control", id "category", onInput FilterCategory ] (
|
||||
, select [ class "ml-2 mr-4 form-control", id "category", onInput FilterCategory ] (
|
||||
option [ ] [ text "any" ]
|
||||
:: (List.map viewCategoryOption categories.list)
|
||||
)
|
||||
, label [ for "text" ] [ text "Search" ]
|
||||
, input [ class "ml-2 form-control", id "text", onInput FilterText ] []
|
||||
, div [ class "ml-auto badge badge-secondary" ] [
|
||||
text (String.fromInt (List.length model.results) ++ " recipes")
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue