Update docs example.

This commit is contained in:
Dillon Kearns 2022-05-11 15:27:37 -07:00
parent 296066c292
commit b5c3573d68
6 changed files with 95 additions and 30 deletions

View File

@ -1,8 +1,11 @@
module Effect exposing (Effect(..), batch, fromCmd, map, none, perform)
import Browser.Navigation
import Bytes exposing (Bytes)
import Bytes.Decode
import Http
import Json.Decode as Decode
import Pages.Fetcher
import Url exposing (Url)
@ -11,11 +14,18 @@ type Effect msg
| Cmd (Cmd msg)
| Batch (List (Effect msg))
| GetStargazers (Result Http.Error Int -> msg)
| FetchPageData
| FetchRouteData
{ body : Maybe { contentType : String, body : String }
, path : Maybe String
, toMsg : Result Http.Error Url -> msg
}
| Submit
{ values : List ( String, String )
, path : Maybe (List String)
, method : Maybe String
, toMsg : Result Http.Error Url -> msg
}
| SubmitFetcher (Pages.Fetcher.Fetcher msg)
type alias RequestInfo =
@ -54,13 +64,26 @@ map fn effect =
GetStargazers toMsg ->
GetStargazers (toMsg >> fn)
FetchPageData fetchInfo ->
FetchPageData
FetchRouteData fetchInfo ->
FetchRouteData
{ body = fetchInfo.body
, path = fetchInfo.path
, toMsg = fetchInfo.toMsg >> fn
}
Submit fetchInfo ->
Submit
{ values = fetchInfo.values
, path = fetchInfo.path
, method = fetchInfo.method
, toMsg = fetchInfo.toMsg >> fn
}
SubmitFetcher fetcher ->
fetcher
|> Pages.Fetcher.map fn
|> SubmitFetcher
perform :
{ fetchRouteData :
@ -69,14 +92,23 @@ perform :
, toMsg : Result Http.Error Url -> pageMsg
}
-> Cmd msg
--, fromSharedMsg : Shared.Msg -> msg
, submit :
{ values : List ( String, String )
, encType : Maybe String
, method : Maybe String
, path : Maybe String
, toMsg : Result Http.Error Url -> pageMsg
}
-> Cmd msg
, runFetcher :
Pages.Fetcher.Fetcher pageMsg
-> Cmd msg
, fromPageMsg : pageMsg -> msg
, key : Browser.Navigation.Key
}
-> Effect pageMsg
-> Cmd msg
perform ({ fetchRouteData, fromPageMsg } as info) effect =
perform ({ fromPageMsg, key } as helpers) effect =
case effect of
None ->
Cmd.none
@ -85,17 +117,30 @@ perform ({ fetchRouteData, fromPageMsg } as info) effect =
Cmd.map fromPageMsg cmd
Batch list ->
Cmd.batch (List.map (perform info) list)
Cmd.batch (List.map (perform helpers) list)
GetStargazers toMsg ->
Http.get
{ url = "https://api.github.com/repos/dillonkearns/elm-pages"
{ url =
"https://api.github.com/repos/dillonkearns/elm-pages"
, expect = Http.expectJson (toMsg >> fromPageMsg) (Decode.field "stargazers_count" Decode.int)
}
FetchPageData fetchInfo ->
fetchRouteData
FetchRouteData fetchInfo ->
helpers.fetchRouteData
{ body = fetchInfo.body
, path = fetchInfo.path
, toMsg = fetchInfo.toMsg
}
Submit record ->
helpers.submit
{ values = record.values
, path = Nothing --fetchInfo.path
, method = record.method
, encType = Nothing -- TODO
, toMsg = record.toMsg
}
SubmitFetcher record ->
helpers.runFetcher record

View File

@ -1,4 +1,4 @@
module Route.Blog exposing (Data, Model, Msg, route)
module Route.Blog exposing (ActionData, Data, Model, Msg, route)
import Article
import DataSource
@ -22,7 +22,7 @@ type alias Msg =
()
route : StatelessRoute RouteParams Data
route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.single
{ head = head
@ -42,6 +42,10 @@ type alias Data =
List ( Route, Article.ArticleMetadata )
type alias ActionData =
{}
type alias RouteParams =
{}
@ -53,7 +57,7 @@ type alias Model =
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data {}
-> StaticPayload Data ActionData {}
-> View msg
view maybeUrl sharedModel staticPayload =
{ title = "elm-pages blog"
@ -155,7 +159,7 @@ view maybeUrl sharedModel staticPayload =
}
head : StaticPayload Data {} -> List Head.Tag
head : StaticPayload Data ActionData {} -> List Head.Tag
head staticPayload =
Seo.summary
{ canonicalUrlOverride = Nothing

View File

@ -1,4 +1,4 @@
module Route.Blog.Slug_ exposing (Data, Model, Msg, route)
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
import Article
import Cloudinary
@ -39,7 +39,7 @@ type alias RouteParams =
{ slug : String }
route : StatelessRoute RouteParams Data
route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.preRender
{ data = data
@ -63,7 +63,7 @@ pages =
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data RouteParams
-> StaticPayload Data ActionData RouteParams
-> View Msg
view maybeUrl sharedModel static =
{ title = static.data.metadata.title
@ -179,7 +179,7 @@ authorView author static =
head :
StaticPayload Data RouteParams
StaticPayload Data ActionData RouteParams
-> List Head.Tag
head static =
let
@ -233,6 +233,10 @@ type alias Data =
}
type alias ActionData =
{}
data : RouteParams -> DataSource Data
data routeParams =
MarkdownCodec.withFrontmatter Data

View File

@ -1,4 +1,4 @@
module Route.Docs.Section__ exposing (Data, Model, Msg, route)
module Route.Docs.Section__ exposing (ActionData, Data, Model, Msg, route)
import Css
import Css.Global
@ -41,7 +41,7 @@ type alias RouteParams =
{ section : Maybe String }
route : StatelessRoute RouteParams Data
route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.preRender
{ head = head
@ -160,7 +160,7 @@ titleForSection section =
head :
StaticPayload Data RouteParams
StaticPayload Data ActionData RouteParams
-> List Head.Tag
head static =
Seo.summary
@ -190,10 +190,14 @@ type alias Data =
}
type alias ActionData =
{}
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data RouteParams
-> StaticPayload Data ActionData RouteParams
-> View Msg
view maybeUrl sharedModel static =
{ title = static.data.titles.title ++ " - elm-pages docs"

View File

@ -1,4 +1,4 @@
module Route.Index exposing (Data, Model, Msg, route)
module Route.Index exposing (ActionData, Data, Model, Msg, route)
import Css
import DataSource exposing (DataSource)
@ -38,7 +38,11 @@ type alias Data =
()
route : StatelessRoute RouteParams Data
type alias ActionData =
{}
route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.single
{ head = head
@ -48,7 +52,7 @@ route =
head :
StaticPayload Data RouteParams
StaticPayload Data ActionData RouteParams
-> List Head.Tag
head static =
Seo.summary
@ -70,7 +74,7 @@ head static =
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data RouteParams
-> StaticPayload Data ActionData RouteParams
-> View Msg
view maybeUrl sharedModel static =
{ title = "elm-pages - a statically typed site generator"

View File

@ -1,4 +1,4 @@
module Route.Showcase exposing (Data, Model, Msg, route)
module Route.Showcase exposing (ActionData, Data, Model, Msg, route)
import Css
import DataSource
@ -29,7 +29,7 @@ type alias RouteParams =
{}
route : StatefulRoute RouteParams Data Model Msg
route : StatefulRoute RouteParams Data ActionData Model Msg
route =
RouteBuilder.single
{ head = head
@ -47,10 +47,14 @@ type alias Data =
List Showcase.Entry
type alias ActionData =
{}
view :
Maybe PageUrl
-> Shared.Model
-> StaticPayload Data {}
-> StaticPayload Data ActionData {}
-> View Msg
view maybeUrl sharedModel static =
{ title = "elm-pages blog"
@ -84,7 +88,7 @@ view maybeUrl sharedModel static =
}
head : StaticPayload Data {} -> List Head.Tag
head : StaticPayload Data ActionData {} -> List Head.Tag
head staticPayload =
Seo.summary
{ canonicalUrlOverride = Nothing