From b8a95ca88df5b7544edbbfa2b128b6e745804c70 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 18 May 2022 15:31:25 -0700 Subject: [PATCH] Update pokdedex example. --- examples/pokedex/app/Effect.elm | 29 +++++------------------------ src/Form.elm | 8 ++------ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/examples/pokedex/app/Effect.elm b/examples/pokedex/app/Effect.elm index 2bd298ba..6383d1cb 100644 --- a/examples/pokedex/app/Effect.elm +++ b/examples/pokedex/app/Effect.elm @@ -16,14 +16,11 @@ type Effect msg | Batch (List (Effect msg)) | GetStargazers (Result Http.Error Int -> msg) | FetchRouteData - { body : Maybe { contentType : String, body : String } - , path : Maybe String + { data : Maybe FormDecoder.FormData , toMsg : Result Http.Error Url -> msg } | Submit { values : FormDecoder.FormData - , path : Maybe (List String) - , method : Maybe String , toMsg : Result Http.Error Url -> msg } | SubmitFetcher (Pages.Fetcher.Fetcher msg) @@ -67,16 +64,13 @@ map fn effect = FetchRouteData fetchInfo -> FetchRouteData - { body = fetchInfo.body - , path = fetchInfo.path + { data = fetchInfo.data , toMsg = fetchInfo.toMsg >> fn } Submit fetchInfo -> Submit { values = fetchInfo.values - , path = fetchInfo.path - , method = fetchInfo.method , toMsg = fetchInfo.toMsg >> fn } @@ -88,16 +82,12 @@ map fn effect = perform : { fetchRouteData : - { body : Maybe { contentType : String, body : String } - , path : Maybe String + { data : Maybe FormDecoder.FormData , toMsg : Result Http.Error Url -> pageMsg } -> Cmd msg , submit : { values : FormDecoder.FormData - , encType : Maybe String - , method : Maybe String - , path : Maybe String , toMsg : Result Http.Error Url -> pageMsg } -> Cmd msg @@ -129,19 +119,10 @@ perform ({ fromPageMsg, key } as helpers) effect = FetchRouteData fetchInfo -> helpers.fetchRouteData - { body = fetchInfo.body - , path = fetchInfo.path - , toMsg = fetchInfo.toMsg - } + fetchInfo Submit record -> - helpers.submit - { values = record.values - , path = Nothing --fetchInfo.path - , method = record.method - , encType = Nothing -- TODO - , toMsg = record.toMsg - } + helpers.submit record SubmitFetcher record -> helpers.runFetcher record diff --git a/src/Form.elm b/src/Form.elm index 5064c54f..3da94fac 100644 --- a/src/Form.elm +++ b/src/Form.elm @@ -412,7 +412,7 @@ isAtLeast atLeastStatus currentStatus = {-| -} update : - ({ values : FormDecoder.FormData, path : Maybe (List String), method : Maybe String, toMsg : Result Http.Error Url -> msg } -> effect) + ({ values : FormDecoder.FormData, toMsg : Result Http.Error Url -> msg } -> effect) -> effect -> (Msg -> msg) -> Form msg String value view @@ -516,11 +516,7 @@ update submitEffect noEffect toMsg ((Form _ _ _ modelToValue config) as form) ms else ( { model | isSubmitting = Submitting } , submitEffect - { values = values -- TODO should this use FormDecoder.FormData directly to get the method and action url? - - -- TODO what to do if it's an external URL? - , path = config.url |> Maybe.map Path.fromString |> Maybe.map Path.toSegments - , method = config.method + { values = values , toMsg = GotFormResponse >> toMsg } )