elm-pages-v3-beta/examples/pokedex/src/Page/Index.elm

89 lines
1.7 KiB
Elm
Raw Normal View History

module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
import DataSource.Http
import Head
import Head.Seo as Seo
import Html exposing (..)
import OptimizedDecoder as Decode
import Page exposing (Page, PageWithState, StaticPayload)
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
2021-06-01 20:57:08 +03:00
import Route
import Secrets
import Shared
import View exposing (View)
type alias Model =
()
type alias Msg =
Never
type alias RouteParams =
{}
page : Page RouteParams Data
page =
Page.singleRoute
{ head = head
, data = data
}
|> Page.buildNoState { view = view }
data : DataSource Data
data =
DataSource.Http.get (Secrets.succeed "https://pokeapi.co/api/v2/pokemon/?limit=20&offset=0")
(Decode.field "results"
(Decode.list (Decode.field "name" Decode.string))
)
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 =
List String
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data RouteParams
-> View Msg
view maybeUrl sharedModel static =
{ title = "Pokedex"
, body =
[ ul []
(List.map
(\name ->
li []
[ text name ]
)
static.data
)
]
}