mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 11:55:41 +03:00
Update examples.
This commit is contained in:
parent
b0516a8608
commit
921aa4bc9d
@ -251,9 +251,11 @@ type alias Data =
|
|||||||
|
|
||||||
data :
|
data :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
|
-> Request
|
||||||
data routeParams =
|
-> BackendTask FatalError (Response Data ErrorPage)
|
||||||
withUserOrRedirect
|
data routeParams request =
|
||||||
|
request
|
||||||
|
|> withUserOrRedirect
|
||||||
(\\user ->
|
(\\user ->
|
||||||
BackendTask.map (Data user)
|
BackendTask.map (Data user)
|
||||||
(BackendTask.Custom.run "getPosts"
|
(BackendTask.Custom.run "getPosts"
|
||||||
@ -266,9 +268,10 @@ data routeParams =
|
|||||||
|
|
||||||
withUserOrRedirect :
|
withUserOrRedirect :
|
||||||
(User -> BackendTask FatalError (Response Data ErrorPage))
|
(User -> BackendTask FatalError (Response Data ErrorPage))
|
||||||
-> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
|
-> Request
|
||||||
withUserOrRedirect withUser =
|
-> BackendTask FatalError (Response Data ErrorPage)
|
||||||
Request.succeed ()
|
withUserOrRedirect withUser request =
|
||||||
|
request
|
||||||
|> Session.withSession
|
|> Session.withSession
|
||||||
{ name = "session"
|
{ name = "session"
|
||||||
, secrets =
|
, secrets =
|
||||||
@ -349,9 +352,10 @@ view app shared =
|
|||||||
|
|
||||||
data :
|
data :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
|
-> Request
|
||||||
data routeParams =
|
-> BackendTask FatalError (Response Data ErrorPage)
|
||||||
Request.succeed (BackendTask.succeed (Response.render {}))
|
data routeParams request =
|
||||||
|
BackendTask.succeed (Response.render {})
|
||||||
|
|
||||||
|
|
||||||
head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
|
head : RouteBuilder.App Data ActionData RouteParams -> List Head.Tag
|
||||||
@ -361,33 +365,32 @@ head app =
|
|||||||
|
|
||||||
action :
|
action :
|
||||||
RouteParams
|
RouteParams
|
||||||
-> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
|
-> Request
|
||||||
action routeParams =
|
-> BackendTask FatalError (Response ActionData ErrorPage)
|
||||||
formHandlers
|
action routeParams request =
|
||||||
|> Request.formData
|
case request |> Request.formData formHandlers of
|
||||||
|> Request.map
|
Just ( response, parsedForm ) ->
|
||||||
(\\formData ->
|
case parsedForm of
|
||||||
case formData of
|
Form.Valid (SignUp okForm) ->
|
||||||
( response, parsedForm ) ->
|
BackendTask.Custom.run "createUser"
|
||||||
case parsedForm of
|
-- client-side validations run on the server, too,
|
||||||
Ok (SignUp okForm) ->
|
-- so we know that the password and password-confirmation matched
|
||||||
BackendTask.Custom.run "createUser"
|
(Encode.object
|
||||||
-- client-side validations run on the server, too,
|
[ ( "username", Encode.string okForm.username )
|
||||||
-- so we know that the password and password-confirmation matched
|
, ( "password", Encode.string okForm.password )
|
||||||
(Encode.object
|
]
|
||||||
[ ( "username", Encode.string okForm.username )
|
)
|
||||||
, ( "password", Encode.string okForm.password )
|
(Decode.succeed ())
|
||||||
]
|
|> BackendTask.allowFatal
|
||||||
)
|
|> BackendTask.map (\\() -> Response.render { errors = response })
|
||||||
(Decode.succeed ())
|
|
||||||
|> BackendTask.allowFatal
|
|
||||||
|> BackendTask.map (\\() -> Response.render { errors = response })
|
|
||||||
|
|
||||||
Err error ->
|
Form.Invalid _ _ ->
|
||||||
"Error!"
|
"Error!"
|
||||||
|> Pages.Script.log
|
|> Pages.Script.log
|
||||||
|> BackendTask.map (\\() -> Response.render { errors = response })
|
|> BackendTask.map (\\() -> Response.render { errors = response })
|
||||||
)
|
|
||||||
|
Nothing ->
|
||||||
|
BackendTask.fail (FatalError.fromString "Expected form submission."
|
||||||
|
|
||||||
|
|
||||||
errorsView :
|
errorsView :
|
||||||
|
Loading…
Reference in New Issue
Block a user