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 =
let
currentRoute = Home --parseLocation location
in
(initialModel currentRoute, Cmd.none)
(parseLocation location |> initialModel, Cmd.none)
main : Program Never Model Msg

View File

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

View File

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

View File

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

View File

@ -1,9 +1,10 @@
module Update exposing (..)
import Dict
import Models exposing (Model)
import Messages exposing (Msg(..))
import Navigation exposing (newUrl)
import Routing exposing (parseLocation)
import Routing exposing (Route(..), parseLocation)
import Utils.View exposing (documentTitle)
@ -13,9 +14,19 @@ update msg model =
OnLocationChange location ->
let
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
({model | route = newRoute}, Cmd.none)
({ model | route = newRoute, title = pageTitle }, documentTitle model.title)
NavTo url ->
(model, newUrl url)
UpdateTitle newTitle ->
(model, documentTitle newTitle)
(model, documentTitle model.title)

View File

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

View File

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

View File

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