2022-03-05 21:35:17 +03:00
|
|
|
module Route.Index exposing (Data, Model, Msg, route)
|
2021-06-01 20:36:52 +03:00
|
|
|
|
|
|
|
import DataSource exposing (DataSource)
|
2022-02-10 21:10:26 +03:00
|
|
|
import DataSource.Env as Env
|
2021-06-01 20:36:52 +03:00
|
|
|
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
|
2021-06-01 20:36:52 +03:00
|
|
|
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)
|
2021-06-01 20:36:52 +03:00
|
|
|
import Shared
|
|
|
|
import View exposing (View)
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
2021-12-15 20:26:23 +03:00
|
|
|
{}
|
2021-06-01 20:36:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias Msg =
|
2022-01-06 01:09:37 +03:00
|
|
|
()
|
2021-06-01 20:36:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias RouteParams =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2022-03-05 21:35:17 +03:00
|
|
|
route : StatelessRoute RouteParams Data
|
|
|
|
route =
|
2022-03-05 20:50:01 +03:00
|
|
|
RouteBuilder.single
|
2021-06-01 20:36:52 +03:00
|
|
|
{ head = head
|
|
|
|
, data = data
|
|
|
|
}
|
2022-03-05 20:50:01 +03:00
|
|
|
|> RouteBuilder.buildNoState { view = view }
|
2021-06-01 20:36:52 +03:00
|
|
|
|
|
|
|
|
2022-02-04 22:08:21 +03:00
|
|
|
type alias Data =
|
2022-02-04 22:17:24 +03:00
|
|
|
{ pokemon : List String, envValue : Maybe String }
|
2022-02-04 22:08:21 +03:00
|
|
|
|
|
|
|
|
2021-06-01 20:36:52 +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))
|
|
|
|
)
|
2021-06-01 20:36:52 +03:00
|
|
|
)
|
2022-02-10 21:10:26 +03:00
|
|
|
(Env.get "HELLO")
|
2022-01-21 20:31:18 +03:00
|
|
|
|
|
|
|
|
2021-06-01 20:36:52 +03:00
|
|
|
head :
|
|
|
|
StaticPayload Data RouteParams
|
|
|
|
-> List Head.Tag
|
|
|
|
head static =
|
|
|
|
Seo.summary
|
|
|
|
{ canonicalUrlOverride = Nothing
|
2021-12-21 02:02:12 +03:00
|
|
|
, siteName = "elm-pages Pokedex"
|
2021-06-01 20:36:52 +03:00
|
|
|
, image =
|
2021-12-21 02:02:12 +03:00
|
|
|
{ url = Pages.Url.external ""
|
2021-06-01 20:36:52 +03:00
|
|
|
, alt = "elm-pages logo"
|
|
|
|
, dimensions = Nothing
|
|
|
|
, mimeType = Nothing
|
|
|
|
}
|
2021-12-21 02:02:12 +03:00
|
|
|
, description = "This is a simple app to showcase server-rendering with elm-pages."
|
2021-06-01 20:36:52 +03:00
|
|
|
, locale = Nothing
|
2021-12-21 02:02:12 +03:00
|
|
|
, title = "Elm Pages Pokedex Example"
|
2021-06-01 20:36:52 +03:00
|
|
|
}
|
|
|
|
|> Seo.website
|
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Maybe PageUrl
|
|
|
|
-> Shared.Model
|
|
|
|
-> StaticPayload Data RouteParams
|
|
|
|
-> View Msg
|
|
|
|
view maybeUrl sharedModel static =
|
|
|
|
{ title = "Pokedex"
|
|
|
|
, body =
|
|
|
|
[ ul []
|
2021-12-21 02:02:12 +03:00
|
|
|
(List.indexedMap
|
|
|
|
(\index name ->
|
|
|
|
let
|
|
|
|
pokedexNumber =
|
|
|
|
index + 1
|
|
|
|
in
|
2021-06-01 20:36:52 +03:00
|
|
|
li []
|
2021-12-21 02:02:12 +03:00
|
|
|
[ Route.link (Route.PokedexNumber_ { pokedexNumber = String.fromInt pokedexNumber })
|
|
|
|
[]
|
|
|
|
[ text name ]
|
|
|
|
]
|
2021-06-01 20:36:52 +03:00
|
|
|
)
|
2022-01-28 02:45:51 +03:00
|
|
|
static.data.pokemon
|
2021-06-01 20:36:52 +03:00
|
|
|
)
|
2022-01-28 02:45:51 +03:00
|
|
|
, Html.text (Debug.toString static.data.envValue)
|
2021-06-01 20:36:52 +03:00
|
|
|
]
|
|
|
|
}
|