mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 14:15:33 +03:00
Fix some errors in smoothies app.
This commit is contained in:
parent
c7d8c07939
commit
fa1686cd4c
@ -91,7 +91,7 @@ data routeParams =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formData [ postForm ]
|
||||
Request.formData (postForm |> Form.initCombined identity)
|
||||
|> Request.map
|
||||
(\parsedForm ->
|
||||
let
|
||||
|
@ -89,7 +89,7 @@ data routeParams =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formData [ dependentParser ]
|
||||
Request.formData (dependentParser |> Form.initCombined identity)
|
||||
|> Request.map
|
||||
(\parsedForm ->
|
||||
let
|
||||
|
@ -124,10 +124,10 @@ type Action
|
||||
| SetQuantity Uuid Int
|
||||
|
||||
|
||||
signoutForm : Form.HtmlForm String Action input Msg
|
||||
signoutForm : Form.HtmlForm String () input Msg
|
||||
signoutForm =
|
||||
Form.init
|
||||
{ combine = Validation.succeed Signout
|
||||
{ combine = Validation.succeed ()
|
||||
, view =
|
||||
\formState ->
|
||||
[ Html.button [] [ Html.text "Sign out" ]
|
||||
@ -136,12 +136,12 @@ signoutForm =
|
||||
|> Form.hiddenKind ( "kind", "signout" ) "Expected signout"
|
||||
|
||||
|
||||
setQuantityForm : Form.HtmlForm String Action ( Int, QuantityChange, Smoothie ) Msg
|
||||
setQuantityForm : Form.HtmlForm String ( Uuid, Int ) ( Int, QuantityChange, Smoothie ) Msg
|
||||
setQuantityForm =
|
||||
Form.init
|
||||
(\uuid quantity ->
|
||||
{ combine =
|
||||
Validation.succeed SetQuantity
|
||||
Validation.succeed Tuple.pair
|
||||
|> Validation.andMap (uuid |> Validation.map Uuid)
|
||||
|> Validation.andMap quantity
|
||||
, view =
|
||||
@ -186,11 +186,11 @@ toQuantity quantityChange =
|
||||
-1
|
||||
|
||||
|
||||
oneOfParsers : List (Form.HtmlForm String Action ( Int, QuantityChange, Smoothie ) Msg)
|
||||
oneOfParsers : Form.ServerForms String Action
|
||||
oneOfParsers =
|
||||
[ signoutForm
|
||||
, setQuantityForm
|
||||
]
|
||||
signoutForm
|
||||
|> Form.initCombined (\() -> Signout)
|
||||
|> Form.combine (\( uuid, int ) -> SetQuantity uuid int) setQuantityForm
|
||||
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
@ -232,6 +232,7 @@ view maybeUrl sharedModel model app =
|
||||
pendingItems : Dict String Int
|
||||
pendingItems =
|
||||
app.fetchers
|
||||
|> Dict.values
|
||||
|> List.filterMap
|
||||
(\pending ->
|
||||
case Form.runOneOfServerSide pending.payload.fields oneOfParsers of
|
||||
|
@ -181,7 +181,7 @@ data routeParams =
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
MySession.withSession
|
||||
(Request.formDataWithServerValidation [ form ])
|
||||
(Request.formDataWithServerValidation (form |> Form.initCombined identity))
|
||||
(\usernameDs session ->
|
||||
usernameDs
|
||||
|> DataSource.andThen
|
||||
|
@ -98,7 +98,7 @@ data routeParams =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formData [ form ]
|
||||
Request.formData (form |> Form.initCombined identity)
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "userId" >> Maybe.map Uuid)
|
||||
(\userId parsed session ->
|
||||
case parsed of
|
||||
|
@ -90,7 +90,7 @@ data routeParams =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formData [ dependentParser ]
|
||||
Request.formData (dependentParser |> Form.initCombined identity)
|
||||
|> Request.map
|
||||
(\parsedForm ->
|
||||
let
|
||||
|
@ -211,7 +211,7 @@ validateUsername rawUsername =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formDataWithServerValidation [ formParser ]
|
||||
Request.formDataWithServerValidation (formParser |> Form.initCombined identity)
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "userId" >> Maybe.map Uuid)
|
||||
(\userId parsedActionData session ->
|
||||
parsedActionData
|
||||
|
@ -123,9 +123,16 @@ data routeParams =
|
||||
)
|
||||
|
||||
|
||||
formParsers : Form.ServerForms String Action
|
||||
formParsers =
|
||||
deleteForm
|
||||
|> Form.initCombined (\() -> Delete)
|
||||
|> Form.combine Edit form
|
||||
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.formData [ form, deleteForm ]
|
||||
Request.formData formParsers
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "userId" >> Maybe.map Uuid)
|
||||
(\userId parsed session ->
|
||||
case parsed of
|
||||
@ -174,10 +181,10 @@ type alias EditInfo =
|
||||
{ name : String, description : String, price : Int, imageUrl : String }
|
||||
|
||||
|
||||
deleteForm : Form.HtmlForm String Action data Msg
|
||||
deleteForm : Form.HtmlForm String () data Msg
|
||||
deleteForm =
|
||||
Form.init
|
||||
{ combine = Validation.succeed Delete
|
||||
{ combine = Validation.succeed ()
|
||||
, view =
|
||||
\formState ->
|
||||
[ Html.button
|
||||
@ -196,7 +203,7 @@ deleteForm =
|
||||
|> Form.hiddenKind ( "kind", "delete" ) "Required"
|
||||
|
||||
|
||||
form : Form.HtmlForm String Action Data Msg
|
||||
form : Form.HtmlForm String EditInfo Data Msg
|
||||
form =
|
||||
Form.init
|
||||
(\name description price imageUrl ->
|
||||
@ -206,7 +213,6 @@ form =
|
||||
|> Validation.andMap description
|
||||
|> Validation.andMap price
|
||||
|> Validation.andMap imageUrl
|
||||
|> Validation.map Edit
|
||||
, view =
|
||||
\formState ->
|
||||
let
|
||||
|
Loading…
Reference in New Issue
Block a user