2021-07-27 20:48:42 +03:00
|
|
|
module Shared exposing (Data, Model, Msg, 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
|
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 Pages.Flags
|
2021-05-24 21:17:34 +03:00
|
|
|
import Pages.PageUrl exposing (PageUrl)
|
2021-05-23 20:43:53 +03:00
|
|
|
import Path exposing (Path)
|
2021-07-27 20:48:42 +03:00
|
|
|
import Route exposing (Route)
|
2021-04-13 02:46:08 +03:00
|
|
|
import SharedTemplate exposing (SharedTemplate)
|
2021-05-14 01:50:28 +03:00
|
|
|
import TableOfContents
|
2021-05-23 19:00:20 +03:00
|
|
|
import View exposing (View)
|
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-07-27 20:48:42 +03:00
|
|
|
template : SharedTemplate Msg Model Data 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
|
2020-09-02 08:38:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 01:31:56 +03:00
|
|
|
type Msg
|
|
|
|
= OnPageChange
|
2021-05-23 20:43:53 +03:00
|
|
|
{ path : Path
|
2020-05-24 01:31:56 +03:00
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
| ToggleMobileMenu
|
2021-07-27 20:48:42 +03:00
|
|
|
| IncrementFromChild
|
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 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 :
|
2021-05-23 20:43:53 +03:00
|
|
|
{ path : Path
|
2021-04-14 19:26:58 +03:00
|
|
|
, query : Maybe String
|
|
|
|
, fragment : Maybe String
|
|
|
|
}
|
|
|
|
, metadata : route
|
2021-05-24 21:17:34 +03:00
|
|
|
, pageUrl : Maybe PageUrl
|
2020-10-04 23:35:33 +03:00
|
|
|
}
|
|
|
|
-> ( Model, Cmd Msg )
|
2021-05-17 22:51:04 +03:00
|
|
|
init navigationKey flags maybePagePath =
|
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
|
|
|
|
2021-07-27 20:48:42 +03:00
|
|
|
IncrementFromChild ->
|
|
|
|
( { model | counter = model.counter + 1 }, Cmd.none )
|
2020-09-06 07:31:14 +03:00
|
|
|
|
2020-05-24 01:31:56 +03:00
|
|
|
|
2021-05-23 20:43:53 +03:00
|
|
|
subscriptions : Path -> Model -> Sub Msg
|
2021-04-10 23:26:19 +03:00
|
|
|
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-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-05-23 20:43:53 +03:00
|
|
|
{ path : Path
|
2021-07-27 20:48:42 +03:00
|
|
|
, route : Maybe Route
|
2020-10-01 22:00:03 +03:00
|
|
|
}
|
2020-05-24 01:31:56 +03:00
|
|
|
-> Model
|
|
|
|
-> (Msg -> msg)
|
2021-05-23 19:00:20 +03:00
|
|
|
-> View 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-23 19:00:20 +03:00
|
|
|
((View.Header.view ToggleMobileMenu 123 page.path
|
|
|
|
|> Html.Styled.map toMsg
|
|
|
|
)
|
|
|
|
:: TableOfContents.view model.showMobileMenu False Nothing tableOfContents
|
|
|
|
:: pageView.body
|
|
|
|
)
|
|
|
|
|> 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
|
|
|
}
|