mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 20:03:31 +03:00
111 lines
2.2 KiB
Elm
111 lines
2.2 KiB
Elm
module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
|
|
|
|
import BackendTask
|
|
import Effect exposing (Effect)
|
|
import FatalError exposing (FatalError)
|
|
import Html exposing (Html)
|
|
import Html.Attributes as Attr
|
|
import Pages.Flags
|
|
import Pages.PageUrl exposing (PageUrl)
|
|
import Route exposing (Route)
|
|
import SharedTemplate exposing (SharedTemplate)
|
|
import UrlPath exposing (UrlPath)
|
|
import View exposing (View)
|
|
|
|
|
|
template : SharedTemplate Msg Model Data msg
|
|
template =
|
|
{ init = init
|
|
, update = update
|
|
, view = view
|
|
, data = data
|
|
, subscriptions = subscriptions
|
|
, onPageChange = Just OnPageChange
|
|
}
|
|
|
|
|
|
type Msg
|
|
= OnPageChange
|
|
{ path : UrlPath
|
|
, query : Maybe String
|
|
, fragment : Maybe String
|
|
}
|
|
|
|
|
|
type alias Data =
|
|
()
|
|
|
|
|
|
type SharedMsg
|
|
= NoOp
|
|
|
|
|
|
type alias Model =
|
|
{ showMobileMenu : Bool
|
|
}
|
|
|
|
|
|
init :
|
|
Pages.Flags.Flags
|
|
->
|
|
Maybe
|
|
{ path :
|
|
{ path : UrlPath
|
|
, query : Maybe String
|
|
, fragment : Maybe String
|
|
}
|
|
, metadata : route
|
|
, pageUrl : Maybe PageUrl
|
|
}
|
|
-> ( Model, Effect Msg )
|
|
init flags maybePagePath =
|
|
( { showMobileMenu = False }
|
|
, Effect.none
|
|
)
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Effect Msg )
|
|
update msg model =
|
|
case msg of
|
|
OnPageChange _ ->
|
|
( { model | showMobileMenu = False }, Effect.none )
|
|
|
|
|
|
subscriptions : UrlPath -> Model -> Sub Msg
|
|
subscriptions _ _ =
|
|
Sub.none
|
|
|
|
|
|
data : BackendTask.BackendTask FatalError Data
|
|
data =
|
|
BackendTask.succeed ()
|
|
|
|
|
|
view :
|
|
Data
|
|
->
|
|
{ path : UrlPath
|
|
, route : Maybe Route
|
|
}
|
|
-> Model
|
|
-> (Msg -> msg)
|
|
-> View msg
|
|
-> { body : List (Html msg), title : String }
|
|
view sharedData page model toMsg pageView =
|
|
{ body =
|
|
[ Html.div
|
|
[]
|
|
[ Html.nav
|
|
[ Attr.style "display" "flex"
|
|
, Attr.style "justify-content" "space-evenly"
|
|
]
|
|
[]
|
|
, Html.div
|
|
[ Attr.style "padding" "40px"
|
|
]
|
|
pageView.body
|
|
]
|
|
]
|
|
, title = pageView.title
|
|
}
|