From 08fcd53f09a1755e8d0c3889c5be068735fe58e0 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Wed, 24 May 2023 08:37:02 -0700 Subject: [PATCH] Rename fields. --- codegen/GenerateMain.elm | 32 +++++++++---------- examples/end-to-end/app/Route/Fetcher.elm | 4 +-- examples/pokedex/app/Route/TailwindForm.elm | 2 +- examples/smoothies/app/Route/Index.elm | 4 +-- examples/smoothies/app/Route/Profile.elm | 2 +- .../smoothies/app/Route/SmoothieId_/Edit.elm | 2 +- examples/todos/app/Route/Visibility__.elm | 6 ++-- generator/src/RouteBuilder.elm | 4 +-- src/Pages/Form.elm | 23 ++++++------- 9 files changed, 37 insertions(+), 42 deletions(-) diff --git a/codegen/GenerateMain.elm b/codegen/GenerateMain.elm index 3176ac08..8e06ba66 100644 --- a/codegen/GenerateMain.elm +++ b/codegen/GenerateMain.elm @@ -237,12 +237,12 @@ otherFile routes phaseString = view = Elm.Declare.function "view" [ ( "pageFormState", Type.named [ "Form" ] "Model" |> Just ) - , ( "fetchers" + , ( "concurrentSubmissions" , Gen.Dict.annotation_.dict Type.string (Gen.Pages.Transition.annotation_.fetcherState (Type.named [] "ActionData")) |> Just ) - , ( "transition", Type.named [ "Pages", "Transition" ] "Transition" |> Type.maybe |> Just ) + , ( "navigation", Type.named [ "Pages", "Transition" ] "Transition" |> Type.maybe |> Just ) , ( "page" , Type.record [ ( "path", Type.named [ "UrlPath" ] "UrlPath" ) @@ -257,7 +257,7 @@ otherFile routes phaseString = ] (\args -> case args of - [ pageFormState, fetchers, transition, page, maybePageUrl, globalData, pageData, actionData ] -> + [ pageFormState, concurrentSubmissions, navigation, page, maybePageUrl, globalData, pageData, actionData ] -> Elm.Case.custom (Elm.tuple (page |> Elm.get "route") pageData) Type.unit ([ Elm.Pattern.tuple Elm.Pattern.ignore (Elm.Pattern.variant1 "DataErrorPage____" (Elm.Pattern.var "data")) @@ -375,9 +375,9 @@ otherFile routes phaseString = "fetcherArg" (Gen.Pages.Fetcher.call_.submit (decodeRouteType ActionData route)) ) - , ( "transition", transition ) - , ( "fetchers" - , fetchers + , ( "navigation", navigation ) + , ( "concurrentSubmissions" + , concurrentSubmissions |> Gen.Dict.map (\_ fetcherState -> fetcherState @@ -416,8 +416,8 @@ otherFile routes phaseString = , ( "path", page |> Elm.get "path" ) , ( "url", Elm.nothing ) , ( "submit", Elm.functionReduced "value" (Gen.Pages.Fetcher.call_.submit (decodeRouteType ActionData route)) ) - , ( "transition", Elm.nothing ) - , ( "fetchers", Gen.Dict.empty ) + , ( "navigation", Elm.nothing ) + , ( "concurrentSubmissions", Gen.Dict.empty ) , ( "pageFormState", Gen.Dict.empty ) ] ] @@ -855,8 +855,8 @@ otherFile routes phaseString = [ route |> decodeRouteType ActionData ] ) - , ( "transition", Elm.nothing ) - , ( "fetchers", Gen.Dict.empty ) + , ( "navigation", Elm.nothing ) + , ( "concurrentSubmissions", Gen.Dict.empty ) , ( "pageFormState", Gen.Dict.empty ) ] ] @@ -914,13 +914,13 @@ otherFile routes phaseString = update = Elm.Declare.function "update" [ ( "pageFormState", Type.named [ "Form" ] "Model" |> Just ) - , ( "fetchers" + , ( "concurrentSubmissions" , Gen.Dict.annotation_.dict Type.string (Gen.Pages.Transition.annotation_.fetcherState (Type.named [] "ActionData")) |> Just ) - , ( "transition", Type.named [ "Pages", "Transition" ] "Transition" |> Type.maybe |> Just ) + , ( "navigation", Type.named [ "Pages", "Transition" ] "Transition" |> Type.maybe |> Just ) , ( "sharedData", Type.named [ "Shared" ] "Data" |> Just ) , ( "pageData", Type.named [] "PageData" |> Just ) , ( "navigationKey", Type.named [ "Browser", "Navigation" ] "Key" |> Type.maybe |> Just ) @@ -929,7 +929,7 @@ otherFile routes phaseString = ] (\args -> case args of - [ pageFormState, fetchers, transition, sharedData, pageData, navigationKey, msg, model ] -> + [ pageFormState, concurrentSubmissions, navigation, sharedData, pageData, navigationKey, msg, model ] -> Elm.Case.custom msg Type.unit ([ Elm.Pattern.variant1 "MsgErrorPage____" (Elm.Pattern.var "msg_") @@ -1183,9 +1183,9 @@ otherFile routes phaseString = , ( "path", justPage |> Elm.get "path" ) , ( "url", Elm.just pageUrl ) , ( "submit", Elm.fn ( "options", Nothing ) (Gen.Pages.Fetcher.call_.submit (decodeRouteType ActionData route)) ) - , ( "transition", transition ) - , ( "fetchers" - , fetchers + , ( "navigation", navigation ) + , ( "concurrentSubmissions" + , concurrentSubmissions |> Gen.Dict.map (\_ fetcherState -> fetcherState diff --git a/examples/end-to-end/app/Route/Fetcher.elm b/examples/end-to-end/app/Route/Fetcher.elm index 81dfa68e..3d4a1719 100644 --- a/examples/end-to-end/app/Route/Fetcher.elm +++ b/examples/end-to-end/app/Route/Fetcher.elm @@ -200,7 +200,7 @@ view app sharedModel model = let inFlight : List Action inFlight = - app.fetchers + app.concurrentSubmissions |> Dict.values |> List.filterMap (\{ status, payload } -> @@ -271,7 +271,7 @@ view app sharedModel model = else Html.text "Ready" ] - , app.fetchers + , app.concurrentSubmissions |> Dict.toList |> List.map (\( key, item ) -> diff --git a/examples/pokedex/app/Route/TailwindForm.elm b/examples/pokedex/app/Route/TailwindForm.elm index 7075f294..c998ce57 100644 --- a/examples/pokedex/app/Route/TailwindForm.elm +++ b/examples/pokedex/app/Route/TailwindForm.elm @@ -679,7 +679,7 @@ view app model sharedModel = |> Maybe.withDefault (Html.p [] []) , Html.p [] [ -- TODO should this be calling a function in Form and passing in the form, like `Form.isSubmitting form`? - if app.transition /= Nothing then + if app.navigation /= Nothing then Html.text "Submitting..." else diff --git a/examples/smoothies/app/Route/Index.elm b/examples/smoothies/app/Route/Index.elm index 34e4152b..34f4d2ee 100644 --- a/examples/smoothies/app/Route/Index.elm +++ b/examples/smoothies/app/Route/Index.elm @@ -231,7 +231,7 @@ view maybeUrl sharedModel model app = let pendingItems : Dict String Int pendingItems = - app.fetchers + app.concurrentSubmissions |> Dict.values |> List.filterMap (\pending -> @@ -268,7 +268,7 @@ view maybeUrl sharedModel model app = { totalItems = 0, totalPrice = 0 } in [ Html.pre [] - [ app.fetchers + [ app.concurrentSubmissions |> Debug.toString |> Html.text ] diff --git a/examples/smoothies/app/Route/Profile.elm b/examples/smoothies/app/Route/Profile.elm index cef00067..da84de78 100644 --- a/examples/smoothies/app/Route/Profile.elm +++ b/examples/smoothies/app/Route/Profile.elm @@ -165,7 +165,7 @@ view maybeUrl sharedModel model app = [ Html.text <| "Edit" ] - , nameFormView app.data.user app.transition + , nameFormView app.data.user app.navigation , Html.pre [] [ app.action |> Debug.toString diff --git a/examples/smoothies/app/Route/SmoothieId_/Edit.elm b/examples/smoothies/app/Route/SmoothieId_/Edit.elm index 853022fa..3f2228d9 100644 --- a/examples/smoothies/app/Route/SmoothieId_/Edit.elm +++ b/examples/smoothies/app/Route/SmoothieId_/Edit.elm @@ -317,7 +317,7 @@ view maybeUrl sharedModel model app = let pendingCreation : Maybe NewItem pendingCreation = - app.transition + app.navigation |> Maybe.andThen getTransitionFields |> Maybe.andThen (\transitionFields -> diff --git a/examples/todos/app/Route/Visibility__.elm b/examples/todos/app/Route/Visibility__.elm index d39bc46e..91162280 100644 --- a/examples/todos/app/Route/Visibility__.elm +++ b/examples/todos/app/Route/Visibility__.elm @@ -330,7 +330,7 @@ view app shared model = let pendingFetchers : List Action pendingFetchers = - app.fetchers + app.concurrentSubmissions |> Dict.values |> List.filterMap (\{ status, payload } -> @@ -450,7 +450,7 @@ view app shared model = optimisticVisibility : Visibility optimisticVisibility = - case app.transition of + case app.navigation of Just (Pages.Transition.Loading path _) -> case path of [ "active" ] -> @@ -467,7 +467,7 @@ view app shared model = failedAddItemActions : List ( String, String ) failedAddItemActions = - app.fetchers + app.concurrentSubmissions |> Dict.toList |> List.filterMap (\( key, { status, payload } ) -> diff --git a/generator/src/RouteBuilder.elm b/generator/src/RouteBuilder.elm index 7365d04b..f53a2cac 100644 --- a/generator/src/RouteBuilder.elm +++ b/generator/src/RouteBuilder.elm @@ -145,8 +145,8 @@ type alias App data action routeParams = , submit : { fields : List ( String, String ), headers : List ( String, String ) } -> Pages.Fetcher.Fetcher (Result Http.Error action) - , transition : Maybe Pages.Transition.Transition - , fetchers : Dict String (Pages.Transition.FetcherState (Maybe action)) + , navigation : Maybe Pages.Transition.Transition + , concurrentSubmissions : Dict String (Pages.Transition.FetcherState (Maybe action)) , pageFormState : Form.Model } diff --git a/src/Pages/Form.elm b/src/Pages/Form.elm index 7208225c..9812027d 100644 --- a/src/Pages/Form.elm +++ b/src/Pages/Form.elm @@ -48,6 +48,7 @@ type alias Handler error combined = Form.Handler.Handler error (BackendTask FatalError (Validation error combined Never Never)) +{-| -} type alias Options error parsed input msg = Form.Options error parsed input msg { concurrent : Bool } @@ -81,12 +82,6 @@ withConcurrent options_ = -- form -{-| -} -type Strategy - = Parallel - | Serial - - {-| -} renderHtml : List (Html.Attribute (PagesMsg userMsg)) @@ -97,8 +92,8 @@ renderHtml : --, action : Maybe action app | pageFormState : Form.Model - , transition : Maybe Pages.Transition.Transition - , fetchers : Dict String (Pages.Transition.FetcherState (Maybe action)) + , navigation : Maybe Pages.Transition.Transition + , concurrentSubmissions : Dict String (Pages.Transition.FetcherState (Maybe action)) } -> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Html (PagesMsg userMsg)) } parsed input -> Html.Html (PagesMsg userMsg) @@ -112,7 +107,7 @@ renderHtml attrs options_ app form_ = |> Form.renderHtml { state = app.pageFormState , submitting = - (case app.fetchers |> Dict.get options_.id of + (case app.concurrentSubmissions |> Dict.get options_.id of Just { status } -> case status of Pages.Transition.FetcherComplete _ -> @@ -127,7 +122,7 @@ renderHtml attrs options_ app form_ = Nothing -> False ) - || (case app.transition of + || (case app.navigation of Just (Pages.Transition.Submitting formData) -> formData.id == Just options_.id @@ -191,8 +186,8 @@ renderStyledHtml : --, action : Maybe action app | pageFormState : Form.Model - , transition : Maybe Pages.Transition.Transition - , fetchers : Dict String (Pages.Transition.FetcherState (Maybe action)) + , navigation : Maybe Pages.Transition.Transition + , concurrentSubmissions : Dict String (Pages.Transition.FetcherState (Maybe action)) } -> Form.Form error { combine : Validation error parsed named constraints, view : Form.Context error input -> List (Html.Styled.Html (PagesMsg userMsg)) } parsed input -> Html.Styled.Html (PagesMsg userMsg) @@ -207,7 +202,7 @@ renderStyledHtml attrs options_ app form_ = { state = app.pageFormState , toMsg = Pages.Internal.Msg.FormMsg , submitting = - (case app.fetchers |> Dict.get options_.id of + (case app.concurrentSubmissions |> Dict.get options_.id of Just { status } -> case status of Pages.Transition.FetcherComplete _ -> @@ -222,7 +217,7 @@ renderStyledHtml attrs options_ app form_ = Nothing -> False ) - || (case app.transition of + || (case app.navigation of Just (Pages.Transition.Submitting formData) -> formData.id == Just options_.id