2021-04-24 02:52:35 +03:00
|
|
|
module Shared exposing (Data, Model, Msg, SharedMsg(..), template)
|
2020-05-20 16:42:52 +03:00
|
|
|
|
2021-04-14 19:26:58 +03:00
|
|
|
import Browser.Navigation
|
2021-04-20 17:31:19 +03:00
|
|
|
import DataSource
|
2021-05-14 01:50:28 +03:00
|
|
|
import DocsSection
|
2021-04-13 02:54:08 +03:00
|
|
|
import Document exposing (Document)
|
2020-05-24 01:31:56 +03:00
|
|
|
import Html exposing (Html)
|
2021-04-21 23:34:59 +03:00
|
|
|
import Html.Styled
|
2021-05-17 22:51:04 +03:00
|
|
|
import Json.Decode
|
|
|
|
import Pages.Flags
|
2021-05-14 19:46:02 +03:00
|
|
|
import Pages.PagePath exposing (PagePath)
|
2021-04-13 02:46:08 +03:00
|
|
|
import SharedTemplate exposing (SharedTemplate)
|
2021-05-14 01:50:28 +03:00
|
|
|
import TableOfContents
|
2021-05-10 07:36:10 +03:00
|
|
|
import View.Header
|
2020-05-24 01:31:56 +03:00
|
|
|
|
2020-05-20 16:42:52 +03:00
|
|
|
|
2021-04-24 02:52:35 +03:00
|
|
|
template : SharedTemplate Msg Model Data SharedMsg msg
|
2020-10-04 23:35:33 +03:00
|
|
|
template =
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
2021-04-24 02:22:23 +03:00
|
|
|
, data = data
|
2020-10-04 23:35:33 +03:00
|
|
|
, subscriptions = subscriptions
|
2020-10-25 22:06:08 +03:00
|
|
|
, onPageChange = Just OnPageChange
|
2021-04-24 02:52:35 +03:00
|
|
|
, sharedMsg = SharedMsg
|
2020-09-02 08:38:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 01:31:56 +03:00
|
|
|
type Msg
|
|
|
|
= OnPageChange
|
2021-04-10 20:33:26 +03:00
|
|
|
{ path : PagePath
|
2020-05-24 01:31:56 +03:00
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
| ToggleMobileMenu
|
2020-09-12 19:16:56 +03:00
|
|
|
| SharedMsg SharedMsg
|
2020-05-24 01:31:56 +03:00
|
|
|
|
|
|
|
|
2021-04-24 02:22:23 +03:00
|
|
|
type alias Data =
|
2021-05-14 01:50:28 +03:00
|
|
|
TableOfContents.TableOfContents TableOfContents.Data
|
2020-10-04 23:35:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
type SharedMsg
|
2020-10-25 21:24:52 +03:00
|
|
|
= IncrementFromChild
|
2020-10-04 23:35:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ showMobileMenu : Bool
|
|
|
|
, counter : Int
|
2021-04-14 19:26:58 +03:00
|
|
|
, navigationKey : Maybe Browser.Navigation.Key
|
2020-10-01 22:00:03 +03:00
|
|
|
}
|
2020-10-04 23:35:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
init :
|
2021-04-14 19:26:58 +03:00
|
|
|
Maybe Browser.Navigation.Key
|
2021-05-17 22:51:04 +03:00
|
|
|
-> Pages.Flags.Flags
|
2021-04-14 19:26:58 +03:00
|
|
|
->
|
|
|
|
Maybe
|
|
|
|
{ path :
|
|
|
|
{ path : PagePath
|
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
, metadata : route
|
2020-10-04 23:35:33 +03:00
|
|
|
}
|
|
|
|
-> ( Model, Cmd Msg )
|
2021-05-17 22:51:04 +03:00
|
|
|
init navigationKey flags maybePagePath =
|
|
|
|
let
|
|
|
|
_ =
|
|
|
|
case flags of
|
|
|
|
Pages.Flags.PreRenderFlags ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
Pages.Flags.BrowserFlags browserFlags ->
|
|
|
|
browserFlags
|
|
|
|
|> Json.Decode.decodeValue Json.Decode.string
|
|
|
|
|> Result.toMaybe
|
|
|
|
in
|
2020-09-02 09:49:23 +03:00
|
|
|
( { showMobileMenu = False
|
|
|
|
, counter = 0
|
2021-04-14 19:26:58 +03:00
|
|
|
, navigationKey = navigationKey
|
2020-09-02 09:49:23 +03:00
|
|
|
}
|
|
|
|
, Cmd.none
|
|
|
|
)
|
2020-05-24 03:03:28 +03:00
|
|
|
|
|
|
|
|
2020-05-24 04:59:07 +03:00
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
2021-04-06 00:25:37 +03:00
|
|
|
OnPageChange _ ->
|
2020-05-24 04:59:07 +03:00
|
|
|
( { model | showMobileMenu = False }, Cmd.none )
|
|
|
|
|
|
|
|
ToggleMobileMenu ->
|
|
|
|
( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none )
|
2020-05-24 01:31:56 +03:00
|
|
|
|
2020-09-06 07:02:05 +03:00
|
|
|
SharedMsg globalMsg ->
|
|
|
|
case globalMsg of
|
2020-09-06 07:31:14 +03:00
|
|
|
IncrementFromChild ->
|
|
|
|
( { model | counter = model.counter + 1 }, Cmd.none )
|
|
|
|
|
2020-05-24 01:31:56 +03:00
|
|
|
|
2021-04-10 23:26:19 +03:00
|
|
|
subscriptions : PagePath -> Model -> Sub Msg
|
|
|
|
subscriptions _ _ =
|
2020-09-30 23:05:35 +03:00
|
|
|
Sub.none
|
|
|
|
|
|
|
|
|
2021-04-24 02:22:23 +03:00
|
|
|
data : DataSource.DataSource Data
|
|
|
|
data =
|
2021-05-07 20:04:14 +03:00
|
|
|
--DataSource.Http.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
|
|
|
-- (D.field "stargazers_count" D.int)
|
2021-05-15 04:56:02 +03:00
|
|
|
TableOfContents.dataSource DocsSection.all
|
2020-05-24 01:31:56 +03:00
|
|
|
|
|
|
|
|
2020-08-27 08:05:12 +03:00
|
|
|
view :
|
2021-04-24 02:22:23 +03:00
|
|
|
Data
|
2020-10-01 22:00:03 +03:00
|
|
|
->
|
2021-04-10 20:33:26 +03:00
|
|
|
{ path : PagePath
|
2021-04-02 07:23:55 +03:00
|
|
|
, frontmatter : route
|
2020-10-01 22:00:03 +03:00
|
|
|
}
|
2020-05-24 01:31:56 +03:00
|
|
|
-> Model
|
|
|
|
-> (Msg -> msg)
|
2021-04-13 02:54:08 +03:00
|
|
|
-> Document msg
|
2020-05-24 01:31:56 +03:00
|
|
|
-> { body : Html msg, title : String }
|
2021-05-14 01:50:28 +03:00
|
|
|
view tableOfContents page model toMsg pageView =
|
2020-05-24 01:31:56 +03:00
|
|
|
{ body =
|
2021-05-07 23:37:19 +03:00
|
|
|
case pageView.body of
|
|
|
|
Document.ElmCssView elements ->
|
2021-05-14 01:50:28 +03:00
|
|
|
((View.Header.view ToggleMobileMenu 123 page.path
|
2021-05-08 04:19:24 +03:00
|
|
|
|> Html.Styled.map toMsg
|
|
|
|
)
|
2021-05-14 01:50:28 +03:00
|
|
|
:: TableOfContents.view model.showMobileMenu False Nothing tableOfContents
|
2021-05-08 04:19:24 +03:00
|
|
|
:: elements
|
|
|
|
)
|
2021-05-07 23:37:19 +03:00
|
|
|
|> Html.Styled.div []
|
|
|
|
|> Html.Styled.toUnstyled
|
2020-08-27 06:07:50 +03:00
|
|
|
, title = pageView.title
|
2020-05-24 01:31:56 +03:00
|
|
|
}
|