Page titles working but not quite right

The on page title is correct; the title bar lags one click behind.
This commit is contained in:
Daniel J. Summers 2016-12-11 22:29:16 -06:00
parent 1e8b34e548
commit 864777a831
8 changed files with 39 additions and 29 deletions

View File

@ -10,10 +10,7 @@ import View exposing (view)
init : Location -> (Model, Cmd Msg) init : Location -> (Model, Cmd Msg)
init location = init location =
let (parseLocation location |> initialModel, Cmd.none)
currentRoute = Home --parseLocation location
in
(initialModel currentRoute, Cmd.none)
main : Program Never Model Msg main : Program Never Model Msg

View File

@ -6,8 +6,8 @@ import Models exposing (Model)
import Utils.View exposing (fullRow) import Utils.View exposing (fullRow)
view : Model -> List (Html Msg) view : List (Html Msg)
view model = view =
let let
paragraphs = paragraphs =
[ " " [ " "

View File

@ -1,6 +1,7 @@
module Messages exposing (..) module Messages exposing (..)
import Navigation exposing (Location) import Navigation exposing (Location)
import Routing exposing (Route)
type Msg type Msg

View File

@ -1,7 +1,7 @@
module Routing exposing (..) module Routing exposing (..)
import Navigation exposing (Location) import Navigation exposing (Location)
import UrlParser exposing (..) import UrlParser exposing ((</>), Parser, map, oneOf, parsePath, s, top)
type Route type Route

View File

@ -1,9 +1,10 @@
module Update exposing (..) module Update exposing (..)
import Dict
import Models exposing (Model) import Models exposing (Model)
import Messages exposing (Msg(..)) import Messages exposing (Msg(..))
import Navigation exposing (newUrl) import Navigation exposing (newUrl)
import Routing exposing (parseLocation) import Routing exposing (Route(..), parseLocation)
import Utils.View exposing (documentTitle) import Utils.View exposing (documentTitle)
@ -13,9 +14,19 @@ update msg model =
OnLocationChange location -> OnLocationChange location ->
let let
newRoute = parseLocation location newRoute = parseLocation location
title =
case newRoute of
ChangePassword -> "Change Your Password"
Home -> "Welcome"
LogOn -> "Log On"
LogOff -> "Log Off"
NotFound -> "Page Not Found"
pageTitle = title ++ " | myPrayerJournal"
in in
({model | route = newRoute}, Cmd.none) ({ model | route = newRoute, title = pageTitle }, documentTitle model.title)
NavTo url -> NavTo url ->
(model, newUrl url) (model, newUrl url)
UpdateTitle newTitle -> UpdateTitle newTitle ->
(model, documentTitle newTitle) (model, documentTitle model.title)

View File

@ -33,8 +33,7 @@ navLink url linkText attrs =
let let
attributes = attributes =
List.concat List.concat
[ [ [ title linkText
[ title linkText
, onWithOptions , onWithOptions
"click" { defaultOptions | preventDefault = True } "click" { defaultOptions | preventDefault = True }
<| Json.succeed <| Json.succeed

View File

@ -1,10 +1,11 @@
module View exposing (view) module View exposing (view)
import Html exposing (..) import Html exposing (Html, button, div, footer, h2, li, p, span, text, ul)
import Html.Attributes exposing (attribute, class) import Html.Attributes exposing (attribute, class)
import Messages exposing (Msg(..)) import Messages exposing (Msg(..))
import Models exposing (..) import Models exposing (..)
import Routing exposing (Route(..)) import Routing exposing (Route(..))
import String exposing (split, trim)
import Utils.View exposing (documentTitle, navLink) import Utils.View exposing (documentTitle, navLink)
import Home.Public import Home.Public
@ -51,10 +52,15 @@ pageHeader =
] ]
pageTitle : String -> Html Msg pageTitle : Model -> Html Msg
pageTitle title = pageTitle model =
let let
x = documentTitle <| title ++ " | myPrayerJournal" title =
case List.head <| split "|" model.title of
Just ttl ->
trim ttl
Nothing ->
""
in in
h2 [ class "page-title" ] [ text title ] h2 [ class "page-title" ] [ text title ]
@ -69,11 +75,11 @@ pageFooter =
] ]
layout : Model -> String -> List (Html Msg) -> Html Msg layout : Model -> List (Html Msg) -> Html Msg
layout model pgTitle contents = layout model contents =
let let
pageContent = pageContent =
[ [ pageTitle pgTitle ] [ [ pageTitle model ]
, contents , contents
, [ pageFooter ] , [ pageFooter ]
] ]
@ -93,12 +99,12 @@ view : Model -> Html Msg
view model = view model =
case model.route of case model.route of
ChangePassword -> ChangePassword ->
layout model "Change Your Password" [ text "password change page goes here" ] layout model [ text "password change page goes here" ]
Home -> Home ->
layout model "Welcome" (Home.Public.view model) layout model Home.Public.view
LogOff -> LogOff ->
layout model "Log Off" [ text "Log off page goes hwere" ] layout model [ text "Log off page goes here" ]
LogOn -> LogOn ->
layout model "Log On" [ text "Log On page goes here" ] layout model [ text "Log On page goes here" ]
NotFound -> NotFound ->
layout model "Page Not Found" [ text "404, dude" ] layout model [ text "404, dude" ]

View File

@ -14,11 +14,7 @@
<div id="app"></div> <div id="app"></div>
<script> <script>
var app = Elm.App.embed(document.getElementById('app')) var app = Elm.App.embed(document.getElementById('app'))
app.ports.documentTitle.subscribe(function (title) app.ports.documentTitle.subscribe(function (title) { document.title = title })
{
alert("Setting title to " + title)
document.title = title
})
</script> </script>
</body> </body>
</html> </html>