2021-12-23 02:28:51 +03:00
|
|
|
module Page.Greet exposing (Data, Model, Msg, page)
|
|
|
|
|
|
|
|
import CookieParser
|
|
|
|
import DataSource exposing (DataSource)
|
|
|
|
import Dict
|
|
|
|
import Head
|
|
|
|
import Head.Seo as Seo
|
|
|
|
import Html
|
2021-12-23 08:29:26 +03:00
|
|
|
import Html.Attributes as Attr
|
2021-12-23 02:28:51 +03:00
|
|
|
import Page exposing (Page, PageWithState, StaticPayload)
|
|
|
|
import PageServerResponse exposing (PageServerResponse)
|
|
|
|
import Pages.PageUrl exposing (PageUrl)
|
|
|
|
import Pages.Url
|
2021-12-27 08:56:33 +03:00
|
|
|
import Server.Request as Request
|
2021-12-23 02:28:51 +03:00
|
|
|
import ServerResponse
|
|
|
|
import Shared
|
2021-12-24 00:34:54 +03:00
|
|
|
import Time
|
2021-12-23 02:28:51 +03:00
|
|
|
import View exposing (View)
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Msg =
|
|
|
|
Never
|
|
|
|
|
|
|
|
|
|
|
|
type alias RouteParams =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
page : Page RouteParams Data
|
|
|
|
page =
|
2021-12-24 00:34:19 +03:00
|
|
|
Page.serverRender
|
2021-12-23 02:28:51 +03:00
|
|
|
{ head = head
|
|
|
|
, data = data
|
|
|
|
}
|
|
|
|
|> Page.buildNoState { view = view }
|
|
|
|
|
|
|
|
|
2021-12-28 19:32:25 +03:00
|
|
|
data : RouteParams -> Request.Handler (PageServerResponse Data)
|
2021-12-27 08:56:33 +03:00
|
|
|
data routeParams =
|
|
|
|
Request.oneOfHandler
|
|
|
|
[ Request.map2 Data
|
|
|
|
(Request.expectQueryParam "name")
|
|
|
|
Request.requestTime
|
|
|
|
|> Request.thenRespond
|
|
|
|
(\requestData ->
|
|
|
|
requestData
|
|
|
|
|> PageServerResponse.RenderPage
|
|
|
|
|> DataSource.succeed
|
|
|
|
)
|
|
|
|
, Request.map2 Data
|
|
|
|
(Request.expectCookie "username")
|
|
|
|
Request.requestTime
|
|
|
|
|> Request.thenRespond
|
|
|
|
(\requestData ->
|
|
|
|
requestData
|
|
|
|
|> PageServerResponse.RenderPage
|
|
|
|
|> DataSource.succeed
|
|
|
|
)
|
|
|
|
, Request.succeed ()
|
|
|
|
|> Request.thenRespond
|
|
|
|
(\() ->
|
|
|
|
DataSource.succeed
|
|
|
|
(PageServerResponse.ServerResponse (ServerResponse.temporaryRedirect "/login"))
|
|
|
|
)
|
|
|
|
]
|
2021-12-23 02:28:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
head :
|
|
|
|
StaticPayload Data 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
|
|
|
|
|
|
|
|
|
|
|
|
type alias Data =
|
2021-12-24 00:34:54 +03:00
|
|
|
{ username : String
|
|
|
|
, requestTime : Time.Posix
|
|
|
|
}
|
2021-12-23 02:28:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Maybe PageUrl
|
|
|
|
-> Shared.Model
|
|
|
|
-> StaticPayload Data RouteParams
|
|
|
|
-> View Msg
|
|
|
|
view maybeUrl sharedModel static =
|
|
|
|
{ title = "Hello!"
|
2021-12-23 08:29:26 +03:00
|
|
|
, body =
|
|
|
|
[ Html.text <| "Hello " ++ static.data.username ++ "!"
|
2021-12-24 00:34:54 +03:00
|
|
|
, Html.text <| "Requested page at " ++ String.fromInt (Time.posixToMillis static.data.requestTime)
|
2021-12-23 08:29:26 +03:00
|
|
|
, Html.div []
|
|
|
|
[ Html.form
|
|
|
|
[ Attr.method "post"
|
|
|
|
, Attr.action "/api/logout"
|
|
|
|
]
|
|
|
|
[ Html.button
|
|
|
|
[ Attr.type_ "submit"
|
|
|
|
]
|
|
|
|
[ Html.text "Logout" ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2021-12-23 02:28:51 +03:00
|
|
|
}
|