mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 20:03:31 +03:00
141 lines
3.1 KiB
Elm
141 lines
3.1 KiB
Elm
module Route.Hello exposing (ActionData, Data, Model, Msg, route)
|
|
|
|
import DataSource exposing (DataSource)
|
|
import Effect exposing (Effect)
|
|
import ErrorPage exposing (ErrorPage)
|
|
import Fetcher.Signup
|
|
import Head
|
|
import Head.Seo as Seo
|
|
import Html
|
|
import Http
|
|
import Pages.Msg
|
|
import Pages.PageUrl exposing (PageUrl)
|
|
import Pages.Url
|
|
import Path exposing (Path)
|
|
import Route.Signup
|
|
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
|
|
import Server.Request as Request
|
|
import Server.Response as Response exposing (Response)
|
|
import Shared
|
|
import View exposing (View)
|
|
|
|
|
|
type alias Model =
|
|
{}
|
|
|
|
|
|
type Msg
|
|
= NoOp
|
|
| GotResponse (Result Http.Error Route.Signup.ActionData)
|
|
|
|
|
|
type alias RouteParams =
|
|
{}
|
|
|
|
|
|
route : StatefulRoute RouteParams Data ActionData Model Msg
|
|
route =
|
|
RouteBuilder.serverRender
|
|
{ head = head
|
|
, data = data
|
|
, action = \_ -> Request.succeed (DataSource.succeed (Response.render {}))
|
|
}
|
|
|> RouteBuilder.buildWithLocalState
|
|
{ view = view
|
|
, update = update
|
|
, subscriptions = subscriptions
|
|
, init = init
|
|
}
|
|
|
|
|
|
init :
|
|
Maybe PageUrl
|
|
-> Shared.Model
|
|
-> StaticPayload Data ActionData RouteParams
|
|
-> ( Model, Effect Msg )
|
|
init maybePageUrl sharedModel static =
|
|
( {}
|
|
, Fetcher.Signup.submit GotResponse
|
|
{ headers = []
|
|
, fields =
|
|
[ ( "first", "Jane" )
|
|
, ( "email", "jane@example.com" )
|
|
]
|
|
}
|
|
|> Effect.SubmitFetcher
|
|
)
|
|
|
|
|
|
update :
|
|
PageUrl
|
|
-> Shared.Model
|
|
-> StaticPayload Data ActionData RouteParams
|
|
-> Msg
|
|
-> Model
|
|
-> ( Model, Effect Msg )
|
|
update pageUrl sharedModel static msg model =
|
|
case msg of
|
|
NoOp ->
|
|
( model
|
|
, Effect.none
|
|
)
|
|
|
|
GotResponse result ->
|
|
let
|
|
_ =
|
|
Debug.log "GotResponse" result
|
|
in
|
|
( model
|
|
, Effect.none
|
|
)
|
|
|
|
|
|
subscriptions : Maybe PageUrl -> RouteParams -> Path -> Shared.Model -> Model -> Sub Msg
|
|
subscriptions maybePageUrl routeParams path sharedModel model =
|
|
Sub.none
|
|
|
|
|
|
type alias Data =
|
|
{}
|
|
|
|
|
|
type alias ActionData =
|
|
{}
|
|
|
|
|
|
data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
|
|
data routeParams =
|
|
Request.succeed (DataSource.succeed (Response.render Data))
|
|
|
|
|
|
head :
|
|
StaticPayload Data ActionData RouteParams
|
|
-> List Head.Tag
|
|
head static =
|
|
Seo.summary
|
|
{ canonicalUrlOverride = Nothing
|
|
, siteName = "elm-pages"
|
|
, image =
|
|
{ url = Pages.Url.external "TODO"
|
|
, alt = "elm-pages logo"
|
|
, dimensions = Nothing
|
|
, mimeType = Nothing
|
|
}
|
|
, description = "TODO"
|
|
, locale = Nothing
|
|
, title = "TODO title" -- metadata.title -- TODO
|
|
}
|
|
|> Seo.website
|
|
|
|
|
|
view :
|
|
Maybe PageUrl
|
|
-> Shared.Model
|
|
-> Model
|
|
-> StaticPayload Data ActionData RouteParams
|
|
-> View (Pages.Msg.Msg Msg)
|
|
view maybeUrl sharedModel model static =
|
|
{ title = "Hello!"
|
|
, body = [ Html.text "Hello" ]
|
|
}
|