elm-pages-v3-beta/examples/pokedex/app/Route/Index.elm

102 lines
2.3 KiB
Elm
Raw Normal View History

module Route.Index exposing (Data, Model, Msg, route)
import DataSource exposing (DataSource)
2022-02-10 21:10:26 +03:00
import DataSource.Env as Env
import DataSource.Http
import Head
import Head.Seo as Seo
import Html exposing (..)
2022-01-28 02:45:51 +03:00
import Json.Decode as Decode exposing (Decoder)
import Json.Encode
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
2021-06-01 20:57:08 +03:00
import Route
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (StatelessRoute, StaticPayload)
import Shared
import View exposing (View)
type alias Model =
2021-12-15 20:26:23 +03:00
{}
type alias Msg =
()
type alias RouteParams =
{}
route : StatelessRoute RouteParams Data
route =
2022-03-05 20:50:01 +03:00
RouteBuilder.single
{ head = head
, data = data
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-04 22:08:21 +03:00
type alias Data =
{ pokemon : List String, envValue : Maybe String }
2022-02-04 22:08:21 +03:00
data : DataSource Data
data =
2022-01-28 02:45:51 +03:00
DataSource.map2 Data
(DataSource.Http.get
"https://pokeapi.co/api/v2/pokemon/?limit=100&offset=0"
(Decode.field "results"
(Decode.list (Decode.field "name" Decode.string))
)
)
2022-02-10 21:10:26 +03:00
(Env.get "HELLO")
head :
StaticPayload Data RouteParams
-> List Head.Tag
head static =
Seo.summary
{ canonicalUrlOverride = Nothing
, siteName = "elm-pages Pokedex"
, image =
{ url = Pages.Url.external ""
, alt = "elm-pages logo"
, dimensions = Nothing
, mimeType = Nothing
}
, description = "This is a simple app to showcase server-rendering with elm-pages."
, locale = Nothing
, title = "Elm Pages Pokedex Example"
}
|> Seo.website
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data RouteParams
-> View Msg
view maybeUrl sharedModel static =
{ title = "Pokedex"
, body =
[ ul []
(List.indexedMap
(\index name ->
let
pokedexNumber =
index + 1
in
li []
[ Route.link (Route.PokedexNumber_ { pokedexNumber = String.fromInt pokedexNumber })
[]
[ text name ]
]
)
2022-01-28 02:45:51 +03:00
static.data.pokemon
)
2022-01-28 02:45:51 +03:00
, Html.text (Debug.toString static.data.envValue)
]
}