Update starter template.

This commit is contained in:
Dillon Kearns 2022-03-14 11:39:41 -07:00
parent 56a4abf2fb
commit 55ac3da02d
6 changed files with 72 additions and 28 deletions

View File

@ -7,6 +7,7 @@ import Html
import Html.Attributes as Attr
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import RouteBuilder exposing (StatelessRoute, StaticPayload)
import Shared
import View exposing (View)
@ -50,7 +51,7 @@ head static =
{ canonicalUrlOverride = Nothing
, siteName = "elm-pages"
, image =
{ url = Pages.Url.external "TODO"
{ url = [ "images", "icon-png.png" ] |> Path.join |> Pages.Url.fromPath
, alt = "elm-pages logo"
, dimensions = Nothing
, mimeType = Nothing

View File

@ -3,6 +3,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import Browser.Navigation
import DataSource
import Html exposing (Html)
import Html.Events
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
@ -18,17 +19,13 @@ template =
, view = view
, data = data
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
, onPageChange = Nothing
}
type Msg
= OnPageChange
{ path : Path
, query : Maybe String
, fragment : Maybe String
}
| SharedMsg SharedMsg
= SharedMsg SharedMsg
| MenuClicked
type alias Data =
@ -40,7 +37,7 @@ type SharedMsg
type alias Model =
{ showMobileMenu : Bool
{ showMenu : Bool
}
@ -59,7 +56,7 @@ init :
}
-> ( Model, Cmd Msg )
init navigationKey flags maybePagePath =
( { showMobileMenu = False }
( { showMenu = False }
, Cmd.none
)
@ -67,12 +64,12 @@ init navigationKey flags maybePagePath =
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
OnPageChange _ ->
( { model | showMobileMenu = False }, Cmd.none )
SharedMsg globalMsg ->
( model, Cmd.none )
MenuClicked ->
( { model | showMenu = not model.showMenu }, Cmd.none )
subscriptions : Path -> Model -> Sub Msg
subscriptions _ _ =
@ -95,6 +92,30 @@ view :
-> View msg
-> { body : Html msg, title : String }
view sharedData page model toMsg pageView =
{ body = Html.div [] pageView.body
{ body =
Html.div []
[ Html.nav []
[ Html.button
[ Html.Events.onClick MenuClicked ]
[ Html.text
(if model.showMenu then
"Close Menu"
else
"Open Menu"
)
]
, if model.showMenu then
Html.ul []
[ Html.li [] [ Html.text "Menu item 1" ]
, Html.li [] [ Html.text "Menu item 2" ]
]
else
Html.text ""
]
|> Html.map toMsg
, Html.main_ [] pageView.body
]
, title = pageView.title
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B

View File

@ -7,6 +7,7 @@ import Html
import Html.Attributes as Attr
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import RouteBuilder exposing (StatelessRoute, StaticPayload)
import Shared
import View exposing (View)
@ -50,7 +51,7 @@ head static =
{ canonicalUrlOverride = Nothing
, siteName = "elm-pages"
, image =
{ url = Pages.Url.external "TODO"
{ url = [ "images", "icon-png.png" ] |> Path.join |> Pages.Url.fromPath
, alt = "elm-pages logo"
, dimensions = Nothing
, mimeType = Nothing

View File

@ -3,6 +3,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import Browser.Navigation
import DataSource
import Html exposing (Html)
import Html.Events
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
@ -18,17 +19,13 @@ template =
, view = view
, data = data
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
, onPageChange = Nothing
}
type Msg
= OnPageChange
{ path : Path
, query : Maybe String
, fragment : Maybe String
}
| SharedMsg SharedMsg
= SharedMsg SharedMsg
| MenuClicked
type alias Data =
@ -40,7 +37,7 @@ type SharedMsg
type alias Model =
{ showMobileMenu : Bool
{ showMenu : Bool
}
@ -59,7 +56,7 @@ init :
}
-> ( Model, Cmd Msg )
init navigationKey flags maybePagePath =
( { showMobileMenu = False }
( { showMenu = False }
, Cmd.none
)
@ -67,12 +64,12 @@ init navigationKey flags maybePagePath =
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
OnPageChange _ ->
( { model | showMobileMenu = False }, Cmd.none )
SharedMsg globalMsg ->
( model, Cmd.none )
MenuClicked ->
( { model | showMenu = not model.showMenu }, Cmd.none )
subscriptions : Path -> Model -> Sub Msg
subscriptions _ _ =
@ -95,6 +92,30 @@ view :
-> View msg
-> { body : Html msg, title : String }
view sharedData page model toMsg pageView =
{ body = Html.div [] pageView.body
{ body =
Html.div []
[ Html.nav []
[ Html.button
[ Html.Events.onClick MenuClicked ]
[ Html.text
(if model.showMenu then
"Close Menu"
else
"Open Menu"
)
]
, if model.showMenu then
Html.ul []
[ Html.li [] [ Html.text "Menu item 1" ]
, Html.li [] [ Html.text "Menu item 2" ]
]
else
Html.text ""
]
|> Html.map toMsg
, Html.main_ [] pageView.body
]
, title = pageView.title
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B