elm-pages-v3-beta/examples/pokedex/app/Shared.elm

121 lines
2.5 KiB
Elm
Raw Normal View History

module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import DataSource
2022-03-29 01:11:07 +03:00
import Effect exposing (Effect)
import Html exposing (Html)
2022-03-31 21:04:05 +03:00
import Html.Attributes as Attr
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
2021-07-28 20:29:06 +03:00
import Route exposing (Route)
import SharedTemplate exposing (SharedTemplate)
import View exposing (View)
2021-07-28 20:29:06 +03:00
template : SharedTemplate Msg Model Data msg
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
}
| SharedMsg SharedMsg
type alias Data =
()
type SharedMsg
= NoOp
type alias Model =
{ showMobileMenu : Bool
}
init :
2022-03-29 01:11:07 +03:00
Pages.Flags.Flags
->
Maybe
{ path :
{ path : Path
, query : Maybe String
, fragment : Maybe String
}
, metadata : route
, pageUrl : Maybe PageUrl
}
2022-03-29 01:11:07 +03:00
-> ( Model, Effect Msg )
init flags maybePagePath =
( { showMobileMenu = False }
2022-03-29 01:11:07 +03:00
, Effect.none
)
2022-03-29 01:11:07 +03:00
update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
OnPageChange _ ->
2022-03-29 01:11:07 +03:00
( { model | showMobileMenu = False }, Effect.none )
SharedMsg globalMsg ->
2022-03-29 01:11:07 +03:00
( model, Effect.none )
subscriptions : Path -> Model -> Sub Msg
subscriptions _ _ =
Sub.none
data : DataSource.DataSource Data
data =
DataSource.succeed ()
view :
Data
->
{ path : Path
2021-07-28 20:29:06 +03:00
, route : Maybe Route
}
-> Model
-> (Msg -> msg)
-> View msg
-> { body : Html msg, title : String }
view sharedData page model toMsg pageView =
2022-03-31 21:04:05 +03:00
{ body =
Html.div
[]
[ Html.nav
[ Attr.style "display" "flex"
, Attr.style "justify-content" "space-evenly"
]
[ Route.Index
|> Route.link
[]
[ Html.text "Home" ]
, Route.PokedexNumber_ { pokedexNumber = "0" }
|> Route.link
[]
[ Html.text "To 404 page" ]
]
, Html.div
[ Attr.style "padding" "40px"
]
pageView.body
]
, title = pageView.title
}