Update examples

This commit is contained in:
Tom Nunn 2022-11-23 15:59:46 +00:00
parent 71d65b8886
commit 144527ed0c
3 changed files with 5 additions and 4 deletions

View File

@ -63,7 +63,7 @@ update : Msg -> Model -> ( Model, MyEffect )
update msg model =
case msg of
SelectMsg subMsg ->
Select.Effect.updateWithRequest (Select.Effect.request FetchCocktails) SelectMsg subMsg model.select
Select.Effect.updateWith [ Select.Effect.request FetchCocktails ] SelectMsg subMsg model.select
|> Tuple.mapBoth (\select -> { model | select = select }) SelectEffect

View File

@ -8,6 +8,7 @@ import Html exposing (Html)
import Resources.ClearButton
import Select exposing (Select)
main : Program () Model Msg
main =
Browser.element

View File

@ -62,16 +62,16 @@ update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SelectMsg subMsg ->
Select.updateWithRequest (Select.request fetchCocktails) SelectMsg subMsg model.select
Select.updateWith [ Select.request fetchCocktails ] SelectMsg subMsg model.select
|> Tuple.mapFirst (\select -> { model | select = select })
fetchCocktails : String -> Cmd (Select.Msg Cocktail)
fetchCocktails : String -> Cmd Msg
fetchCocktails query =
Http.get
{ url = "https://thecocktaildb.com/api/json/v1/1/search.php?s=" ++ String.replace " " "+" query
, expect =
Http.expectJson (Select.gotRequestResponse query)
Http.expectJson (Select.gotRequestResponse query >> SelectMsg)
(Decode.field "drinks"
(Decode.oneOf
[ Decode.list cocktailDecoder