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