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)
|
module Pages.Top exposing (Model, Msg, Params, page)
|
||||||
|
|
||||||
import Enum exposing (Enum)
|
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.Attributes exposing (alt, class, href, src, style, id, for, value)
|
||||||
import Html.Events exposing (onClick, onInput)
|
import Html.Events exposing (onClick, onInput)
|
||||||
import Http
|
import Http
|
||||||
|
@ -50,6 +50,7 @@ type alias App =
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ filter_score : Maybe Int
|
{ filter_score : Maybe Int
|
||||||
, filter_category : Maybe Category
|
, filter_category : Maybe Category
|
||||||
|
, filter_text : Maybe String
|
||||||
, status : Status
|
, status : Status
|
||||||
, apps : (List App)
|
, apps : (List App)
|
||||||
, results : (List App)
|
, results : (List App)
|
||||||
|
@ -91,7 +92,8 @@ default_image =
|
||||||
|
|
||||||
default_model : Model
|
default_model : Model
|
||||||
default_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
|
-- UPDATE
|
||||||
|
@ -101,6 +103,7 @@ type Msg
|
||||||
= MorePlease
|
= MorePlease
|
||||||
| FilterScore String
|
| FilterScore String
|
||||||
| FilterCategory String
|
| FilterCategory String
|
||||||
|
| FilterText String
|
||||||
| GotApps (Result Http.Error (List App))
|
| GotApps (Result Http.Error (List App))
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,6 +127,22 @@ filterAppsCategory apps category =
|
||||||
Nothing ->
|
Nothing ->
|
||||||
apps
|
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 -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
|
@ -137,7 +156,9 @@ update msg model =
|
||||||
( { model
|
( { model
|
||||||
| filter_score = filter_score
|
| filter_score = filter_score
|
||||||
, results = filterAppsScore (
|
, results = filterAppsScore (
|
||||||
filterAppsCategory model.apps model.filter_category
|
filterAppsCategory (
|
||||||
|
filterAppsText model.apps model.filter_text
|
||||||
|
) model.filter_category
|
||||||
) (String.toInt filter)
|
) (String.toInt filter)
|
||||||
}, Cmd.none )
|
}, Cmd.none )
|
||||||
|
|
||||||
|
@ -148,10 +169,22 @@ update msg model =
|
||||||
( { model
|
( { model
|
||||||
| filter_category = category
|
| filter_category = category
|
||||||
, results = filterAppsCategory (
|
, results = filterAppsCategory (
|
||||||
filterAppsScore model.apps model.filter_score
|
filterAppsScore (
|
||||||
|
filterAppsText model.apps model.filter_text
|
||||||
|
)model.filter_score
|
||||||
) category
|
) category
|
||||||
}, Cmd.none )
|
}, 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 ->
|
GotApps result ->
|
||||||
case result of
|
case result of
|
||||||
Ok apps ->
|
Ok apps ->
|
||||||
|
@ -320,10 +353,12 @@ viewApps model =
|
||||||
, option [ value "4" ] [ text "4 (pre-alpha)" ]
|
, option [ value "4" ] [ text "4 (pre-alpha)" ]
|
||||||
]
|
]
|
||||||
, label [ for "category" ] [ text "Category" ]
|
, 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" ]
|
option [ ] [ text "any" ]
|
||||||
:: (List.map viewCategoryOption categories.list)
|
:: (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" ] [
|
, div [ class "ml-auto badge badge-secondary" ] [
|
||||||
text (String.fromInt (List.length model.results) ++ " recipes")
|
text (String.fromInt (List.length model.results) ++ " recipes")
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue