Make transition strategy the default and move formId argument to rendering.

This commit is contained in:
Dillon Kearns 2023-03-03 18:45:25 -08:00
parent a8b8e7421d
commit f4cf8a7069
21 changed files with 70 additions and 80 deletions

View File

@ -188,8 +188,7 @@ createFile { moduleName, fields } =
Just justFormHelp -> Just justFormHelp ->
[ Html.h2 [] [ Html.text "Form" ] [ Html.h2 [] [ Html.text "Form" ]
, justFormHelp.form , justFormHelp.form
|> Form.toDynamicTransition "form" |> Form.renderHtml "form" [] (Elm.get "errors" >> Elm.just) app Elm.unit
|> Form.renderHtml [] (Elm.get "errors" >> Elm.just) app Elm.unit
] ]
Nothing -> Nothing ->
@ -266,8 +265,8 @@ errorsView =
(Type.namedWith [ "Html" ] (Type.namedWith [ "Html" ]
"Html" "Html"
[ Type.namedWith [ Type.namedWith
[ "Pages", "Msg" ] [ "PagesMsg" ]
"Msg" "PagesMsg"
[ Type.named [] "Msg" ] [ Type.named [] "Msg" ]
] ]
) )

View File

@ -215,8 +215,8 @@ view app shared model =
) )
] ]
[ form [ form
|> Form.toDynamicFetcher "dark-mode" |> Form.toDynamicFetcher
|> Form.renderStyledHtml [] (.formResponse >> Just) app app.data.isDarkMode |> Form.renderStyledHtml "dark-mode" [] (.formResponse >> Just) app app.data.isDarkMode
, Html.text <| , Html.text <|
"Current mode: " "Current mode: "
++ (if app.data.isDarkMode then ++ (if app.data.isDarkMode then

View File

@ -245,8 +245,7 @@ view app shared =
[] []
[ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ] [ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ]
, form , form
|> Form.toDynamicTransition "user-form" |> Form.renderHtml "user-form"
|> Form.renderHtml
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"

View File

@ -123,9 +123,8 @@ view app shared =
{ title = "GET Form Example" { title = "GET Form Example"
, body = , body =
[ form [ form
|> Form.toDynamicTransition "user-form"
|> Form.withGetMethod |> Form.withGetMethod
|> Form.renderHtml |> Form.renderHtml "user-form"
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"

View File

@ -218,8 +218,8 @@ view app shared =
) )
] ]
, form , form
|> Form.toDynamicTransition "form" |> Form.renderStyledHtml "form"
|> Form.renderStyledHtml [] []
(.errors >> Just) (.errors >> Just)
app app
() ()

View File

@ -379,8 +379,7 @@ createFile moduleName fields =
Elm.list Elm.list
[ Html.h2 [] [ Html.text "Form" ] [ Html.h2 [] [ Html.text "Form" ]
, form.call [] , form.call []
|> Gen.Form.toDynamicTransition "form" |> Gen.Form.renderStyledHtml "form" [] (Elm.get "errors" >> Elm.just) app Elm.unit
|> Gen.Form.renderStyledHtml [] (Elm.get "errors" >> Elm.just) app Elm.unit
] ]
} }
, update = , update =

View File

@ -261,8 +261,7 @@ view app shared =
[] []
[ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ] [ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ]
, form , form
|> Form.toDynamicTransition "test1" |> Form.renderHtml "test1"
|> Form.renderHtml
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"

View File

@ -201,9 +201,9 @@ view static sharedModel model =
, body = , body =
[ Html.h2 [] [ Html.text "Search" ] [ Html.h2 [] [ Html.text "Search" ]
, form , form
|> Form.toDynamicTransition "test1"
|> Form.withGetMethod |> Form.withGetMethod
|> Form.renderHtml [] |> Form.renderHtml "test1"
[]
-- TODO pass in server data -- TODO pass in server data
(\_ -> Nothing) (\_ -> Nothing)
static static

View File

@ -265,8 +265,8 @@ view app shared model =
] ]
, flashView app.data.flashMessage , flashView app.data.flashMessage
, form , form
|> Form.toDynamicTransition "test1" |> Form.renderHtml "test1"
|> Form.renderHtml [] []
-- TODO pass in server data -- TODO pass in server data
(\_ -> Nothing) (\_ -> Nothing)
app app

View File

@ -719,8 +719,9 @@ view app model sharedModel =
|> Debug.toString |> Debug.toString
) )
, form , form
|> Form.toDynamicTransition "test" |> Form.toDynamicTransition
|> Form.renderStyledHtml [] |> Form.renderStyledHtml "test"
[]
--app.action --app.action
-- |> Maybe.andThen .formResponse -- |> Maybe.andThen .formResponse
(\_ -> Nothing) (\_ -> Nothing)

View File

@ -126,8 +126,7 @@ view maybeUrl sharedModel model app =
{ title = "Create Group" { title = "Create Group"
, body = , body =
[ postForm [ postForm
|> Form.toDynamicTransition "create-group" |> Form.renderHtml "create-group" []
|> Form.renderHtml []
-- TODO pass in form response from ActionData -- TODO pass in form response from ActionData
Nothing Nothing
app app

View File

@ -129,8 +129,8 @@ view maybeUrl sharedModel model app =
, body = , body =
[ Html.h2 [] [ Html.text "Example" ] [ Html.h2 [] [ Html.text "Example" ]
, dependentParser , dependentParser
|> Form.toDynamicTransition "dependent-example" |> Form.toDynamicTransition
|> Form.renderHtml [] |> Form.renderHtml "dependent-example" []
-- TODO pass in form response from ActionData -- TODO pass in form response from ActionData
Nothing Nothing
app app

View File

@ -264,7 +264,6 @@ view maybeUrl sharedModel app =
) )
] ]
, form , form
|> Form.toDynamicTransition "login" |> Form.renderHtml "login" [] app.action app ()
|> Form.renderHtml [] app.action app ()
] ]
} }

View File

@ -210,8 +210,7 @@ view maybeUrl sharedModel model app =
, body = , body =
[ Html.h2 [] [ Html.text "New item" ] [ Html.h2 [] [ Html.text "New item" ]
, form , form
|> Form.toDynamicTransition "form" |> Form.renderHtml "form"
|> Form.renderHtml
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"

View File

@ -120,8 +120,7 @@ view maybeUrl sharedModel model app =
, body = , body =
[ Html.h2 [] [ Html.text "Example" ] [ Html.h2 [] [ Html.text "Example" ]
, dependentParser , dependentParser
|> Form.toDynamicTransition "form" |> Form.renderHtml "form" []
|> Form.renderHtml []
-- TODO pass in form response from ActionData -- TODO pass in form response from ActionData
Nothing Nothing
app app

View File

@ -279,8 +279,7 @@ view maybeUrl sharedModel model app =
_ -> _ ->
Html.text "No errors" Html.text "No errors"
, formParser , formParser
|> Form.toDynamicTransition "edit-form" |> Form.renderHtml "edit-form"
|> Form.renderHtml
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"

View File

@ -340,8 +340,7 @@ view maybeUrl sharedModel model app =
, body = , body =
[ Html.h2 [] [ Html.text "Update item" ] [ Html.h2 [] [ Html.text "Update item" ]
, form , form
|> Form.toDynamicTransition "form" |> Form.renderHtml "form"
|> Form.renderHtml
[ Attr.style "display" "flex" [ Attr.style "display" "flex"
, Attr.style "flex-direction" "column" , Attr.style "flex-direction" "column"
, Attr.style "gap" "20px" , Attr.style "gap" "20px"
@ -354,8 +353,8 @@ view maybeUrl sharedModel model app =
|> Maybe.map pendingView |> Maybe.map pendingView
|> Maybe.withDefault (Html.div [] []) |> Maybe.withDefault (Html.div [] [])
, deleteForm , deleteForm
|> Form.toDynamicTransition "delete-form" |> Form.toDynamicTransition
|> Form.renderHtml [] |> Form.renderHtml "delete-form" []
-- TODO -- TODO
Nothing Nothing
app app

View File

@ -395,8 +395,9 @@ view app shared =
Html.div [] Html.div []
[ Html.text <| "Hello! You are already logged in as " ++ username [ Html.text <| "Hello! You are already logged in as " ++ username
, logoutForm , logoutForm
|> Form.toDynamicTransition "logout" |> Form.toDynamicTransition
|> Form.renderHtml [] |> Form.renderHtml "logout"
[]
(\_ -> Nothing) (\_ -> Nothing)
app app
() ()
@ -406,8 +407,7 @@ view app shared =
Html.text "You aren't logged in yet." Html.text "You aren't logged in yet."
] ]
, form , form
|> Form.toDynamicTransition "login" |> Form.renderHtml "login" [] .maybeError app ()
|> Form.renderHtml [] .maybeError app ()
] ]
] ]
} }

View File

@ -493,11 +493,11 @@ view app shared model =
[ class "todoapp" ] [ class "todoapp" ]
[ addItemForm [ addItemForm
|> Form.toDynamicFetcher |> Form.toDynamicFetcher
|> Form.withOnSubmit (\_ -> NewItemSubmitted)
|> Form.renderHtml
("new-item-" ("new-item-"
++ (model.nextId |> Time.posixToMillis |> String.fromInt) ++ (model.nextId |> Time.posixToMillis |> String.fromInt)
) )
|> Form.withOnSubmit (\_ -> NewItemSubmitted)
|> Form.renderHtml
[ class "create-form" [ class "create-form"
, hidden (not (List.isEmpty failedAddItemActions)) , hidden (not (List.isEmpty failedAddItemActions))
] ]
@ -509,9 +509,10 @@ view app shared model =
|> List.indexedMap |> List.indexedMap
(\index ( key, createFetcherErrors ) -> (\index ( key, createFetcherErrors ) ->
addItemForm addItemForm
|> Form.toDynamicFetcher key |> Form.toDynamicFetcher
|> Form.withOnSubmit (\_ -> NewItemSubmitted) |> Form.withOnSubmit (\_ -> NewItemSubmitted)
|> Form.renderHtml [ class "create-form", hidden (index /= 0) ] |> Form.renderHtml key
[ class "create-form", hidden (index /= 0) ]
(\_ -> Nothing) (\_ -> Nothing)
app app
(Just createFetcherErrors) (Just createFetcherErrors)
@ -735,8 +736,8 @@ viewEntries app visibility entries =
, style "visibility" cssVisibility , style "visibility" cssVisibility
] ]
[ toggleAllForm [ toggleAllForm
|> Form.toDynamicFetcher "toggle-all" |> Form.toDynamicFetcher
|> Form.renderHtml [] (\_ -> Nothing) app { allCompleted = allCompleted } |> Form.renderHtml "toggle-all" [] (\_ -> Nothing) app { allCompleted = allCompleted }
, Keyed.ul [ class "todo-list" ] <| , Keyed.ul [ class "todo-list" ] <|
List.map (viewKeyedEntry app) (List.filter isVisible entries) List.map (viewKeyedEntry app) (List.filter isVisible entries)
] ]
@ -761,18 +762,18 @@ viewEntry app todo =
[ div [ div
[ class "view" ] [ class "view" ]
[ checkItemForm [ checkItemForm
|> Form.toDynamicFetcher ("toggle-" ++ todo.id) |> Form.toDynamicFetcher
|> Form.renderHtml [] (\_ -> Nothing) app todo |> Form.renderHtml ("toggle-" ++ todo.id) [] (\_ -> Nothing) app todo
, editItemForm , editItemForm
|> Form.toDynamicFetcher ("edit-" ++ todo.id) |> Form.toDynamicFetcher
|> Form.renderHtml [] (\_ -> Nothing) app todo |> Form.renderHtml ("edit-" ++ todo.id) [] (\_ -> Nothing) app todo
, if todo.isSaving then , if todo.isSaving then
LoadingSpinner.view LoadingSpinner.view
else else
deleteItemForm deleteItemForm
|> Form.toDynamicFetcher ("delete-" ++ todo.id) |> Form.toDynamicFetcher
|> Form.renderHtml [] (\_ -> Nothing) app todo |> Form.renderHtml ("delete-" ++ todo.id) [] (\_ -> Nothing) app todo
] ]
] ]
@ -862,8 +863,8 @@ visibilitySwap visibilityParam visibility actualVisibility =
viewControlsClear : App Data ActionData RouteParams -> Int -> Html (PagesMsg Msg) viewControlsClear : App Data ActionData RouteParams -> Int -> Html (PagesMsg Msg)
viewControlsClear app entriesCompleted = viewControlsClear app entriesCompleted =
clearCompletedForm clearCompletedForm
|> Form.toDynamicFetcher "clear-completed" |> Form.toDynamicFetcher
|> Form.renderHtml [] (\_ -> Nothing) app { entriesCompleted = entriesCompleted } |> Form.renderHtml "clear-completed" [] (\_ -> Nothing) app { entriesCompleted = entriesCompleted }
infoFooter : Html msg infoFooter : Html msg

View File

@ -52,9 +52,8 @@ type alias PagesMsg userMsg =
-- `Form.renderHtml` gives us `Html (PagesMsg msg)`, so we don't need to wrap its Msg type -- `Form.renderHtml` gives us `Html (PagesMsg msg)`, so we don't need to wrap its Msg type
, logoutForm , logoutForm
|> Form.toDynamicTransition "logout"
|> Form.withOnSubmit (\_ -> NewItemSubmitted) |> Form.withOnSubmit (\_ -> NewItemSubmitted)
|> Form.renderHtml [] (\_ -> Nothing) app Nothing |> Form.renderHtml "logout" [] (\_ -> Nothing) app Nothing
] ]
} }

View File

@ -170,7 +170,7 @@ buildNoState definitions builder_ =
ServerRender declarations builder -> ServerRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared _ app -> \app shared _ ->
definitions.view definitions.view
{ shared = shared { shared = shared
, app = app , app = app
@ -191,7 +191,7 @@ buildNoState definitions builder_ =
PreRender declarations builder -> PreRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared _ app -> \app shared _ ->
definitions.view definitions.view
{ shared = shared { shared = shared
, app = app , app = app
@ -257,7 +257,7 @@ buildWithLocalState definitions builder_ =
ServerRender declarations builder -> ServerRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared model app -> \app shared model ->
definitions.view definitions.view
{ shared = shared { shared = shared
, model = model , model = model
@ -266,7 +266,7 @@ buildWithLocalState definitions builder_ =
, localState = , localState =
Just Just
{ update = { update =
\shared app msg model -> \app shared msg model ->
definitions.update definitions.update
{ shared = shared { shared = shared
, app = app , app = app
@ -274,7 +274,7 @@ buildWithLocalState definitions builder_ =
, model = model , model = model
} }
, init = , init =
\shared app -> \app shared ->
definitions.init definitions.init
{ shared = shared { shared = shared
, app = app , app = app
@ -304,7 +304,7 @@ buildWithLocalState definitions builder_ =
PreRender declarations builder -> PreRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared model app -> \app shared model ->
definitions.view definitions.view
{ shared = shared { shared = shared
, model = model , model = model
@ -313,7 +313,7 @@ buildWithLocalState definitions builder_ =
, localState = , localState =
Just Just
{ update = { update =
\shared app msg model -> \app shared msg model ->
definitions.update definitions.update
{ shared = shared { shared = shared
, app = app , app = app
@ -321,7 +321,7 @@ buildWithLocalState definitions builder_ =
, model = model , model = model
} }
, init = , init =
\shared app -> \app shared ->
definitions.init definitions.init
{ shared = shared { shared = shared
, app = app , app = app
@ -385,7 +385,7 @@ buildWithSharedState definitions builder_ =
ServerRender declarations builder -> ServerRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared model app -> \app shared model ->
definitions.view definitions.view
{ shared = shared { shared = shared
, model = model , model = model
@ -394,7 +394,7 @@ buildWithSharedState definitions builder_ =
, localState = , localState =
Just Just
{ update = { update =
\shared app msg model -> \app shared msg model ->
definitions.update definitions.update
{ shared = shared { shared = shared
, app = app , app = app
@ -402,7 +402,7 @@ buildWithSharedState definitions builder_ =
, model = model , model = model
} }
, init = , init =
\shared app -> \app shared ->
definitions.init definitions.init
{ shared = shared { shared = shared
, app = app , app = app
@ -432,7 +432,7 @@ buildWithSharedState definitions builder_ =
PreRender declarations builder -> PreRender declarations builder ->
userFunction builder.moduleName userFunction builder.moduleName
{ view = { view =
\shared model app -> \app shared model ->
definitions.view definitions.view
{ shared = shared { shared = shared
, model = model , model = model
@ -441,7 +441,7 @@ buildWithSharedState definitions builder_ =
, localState = , localState =
Just Just
{ update = { update =
\shared app msg model -> \app shared msg model ->
definitions.update definitions.update
{ shared = shared { shared = shared
, app = app , app = app
@ -449,7 +449,7 @@ buildWithSharedState definitions builder_ =
, model = model , model = model
} }
, init = , init =
\shared app -> \app shared ->
definitions.init definitions.init
{ shared = shared { shared = shared
, app = app , app = app
@ -520,13 +520,13 @@ userFunction moduleName definitions =
case definitions.localState of case definitions.localState of
Just _ -> Just _ ->
Elm.Declare.fn3 "view" Elm.Declare.fn3 "view"
( "app", Just appType )
( "shared" ( "shared"
, Just (Elm.Annotation.named [ "Shared" ] "Model") , Just (Elm.Annotation.named [ "Shared" ] "Model")
) )
( "model", Just (Elm.Annotation.named [] "Model") ) ( "model", Just (Elm.Annotation.named [] "Model") )
( "app", Just appType ) (\app shared model ->
(\shared model app -> definitions.view app shared model
definitions.view shared model app
|> Elm.withType |> Elm.withType
(Elm.Annotation.namedWith [ "View" ] (Elm.Annotation.namedWith [ "View" ]
"View" "View"
@ -547,14 +547,14 @@ userFunction moduleName definitions =
} }
viewDeclaration = viewDeclaration =
Elm.Declare.fn2 "view" Elm.Declare.fn2 "view"
( "app", Just appType )
( "shared" ( "shared"
, Just (Elm.Annotation.named [ "Shared" ] "Model") , Just (Elm.Annotation.named [ "Shared" ] "Model")
) )
( "app", Just appType )
(definitions.view Elm.unit) (definitions.view Elm.unit)
in in
{ declaration = viewDeclaration.declaration { declaration = viewDeclaration.declaration
, call = \_ -> viewDeclaration.call , call = \app shared _ -> viewDeclaration.call app shared
, callFrom = \a _ c d -> viewDeclaration.callFrom a c d , callFrom = \a _ c d -> viewDeclaration.callFrom a c d
} }
@ -575,17 +575,17 @@ userFunction moduleName definitions =
(\localState -> (\localState ->
{ updateFn = { updateFn =
Elm.Declare.fn4 "update" Elm.Declare.fn4 "update"
( "shared", Just (Elm.Annotation.named [ "Shared" ] "Model") )
( "app", Just appType ) ( "app", Just appType )
( "shared", Just (Elm.Annotation.named [ "Shared" ] "Model") )
( "msg", Just (Elm.Annotation.named [] "Msg") ) ( "msg", Just (Elm.Annotation.named [] "Msg") )
( "model", Just (Elm.Annotation.named [] "Model") ) ( "model", Just (Elm.Annotation.named [] "Model") )
localState.update localState.update
, initFn = , initFn =
Elm.Declare.fn2 "init" Elm.Declare.fn2 "init"
( "shared", Just (Elm.Annotation.named [ "Shared" ] "Model") )
( "app", Just appType ) ( "app", Just appType )
( "shared", Just (Elm.Annotation.named [ "Shared" ] "Model") )
(\shared app -> (\shared app ->
localState.init shared app localState.init app shared
|> Elm.withType |> Elm.withType
(Elm.Annotation.tuple (Elm.Annotation.tuple
(localType "Model") (localType "Model")