elm-pages-v3-beta/examples/end-to-end/app/Shared.elm

100 lines
1.8 KiB
Elm
Raw Normal View History

2021-07-21 23:29:45 +03:00
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import DataSource
2022-03-21 19:45:11 +03:00
import Effect exposing (Effect)
2021-07-21 23:29:45 +03:00
import Html exposing (Html)
import Html.Styled
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
2021-07-26 18:45:27 +03:00
import Route exposing (Route)
2021-07-21 23:29:45 +03:00
import SharedTemplate exposing (SharedTemplate)
import View exposing (View)
2021-07-28 19:01:49 +03:00
template : SharedTemplate Msg Model Data msg
2021-07-21 23:29:45 +03:00
template =
{ init = init
, update = update
, view = view
, data = data
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
}
type Msg
= OnPageChange
{ path : Path
, query : Maybe String
, fragment : Maybe String
}
type alias Data =
()
type SharedMsg
= NoOp
type alias Model =
{ showMobileMenu : Bool
}
init :
2022-03-25 19:03:22 +03:00
Pages.Flags.Flags
2021-07-21 23:29:45 +03:00
->
Maybe
{ path :
{ path : Path
, query : Maybe String
, fragment : Maybe String
}
, metadata : route
, pageUrl : Maybe PageUrl
}
2022-03-21 19:45:11 +03:00
-> ( Model, Effect Msg )
2022-03-25 19:03:22 +03:00
init flags maybePagePath =
2021-07-21 23:29:45 +03:00
( { showMobileMenu = False }
2022-03-21 19:45:11 +03:00
, Effect.none
2021-07-21 23:29:45 +03:00
)
2022-03-21 19:45:11 +03:00
update : Msg -> Model -> ( Model, Effect Msg )
2021-07-21 23:29:45 +03:00
update msg model =
case msg of
OnPageChange _ ->
2022-03-21 19:45:11 +03:00
( { model | showMobileMenu = False }, Effect.none )
2021-07-21 23:29:45 +03:00
subscriptions : Path -> Model -> Sub Msg
subscriptions _ _ =
Sub.none
data : DataSource.DataSource Data
data =
DataSource.succeed ()
view :
Data
->
{ path : Path
2021-07-26 18:45:27 +03:00
, route : Maybe Route
2021-07-21 23:29:45 +03:00
}
-> Model
-> (Msg -> msg)
-> View msg
-> { body : Html msg, title : String }
view stars page model toMsg pageView =
{ body =
Html.Styled.div []
pageView.body
|> Html.Styled.toUnstyled
, title = pageView.title
}