From 864777a831061032760147bc0816aef8c7afe5c7 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 11 Dec 2016 22:29:16 -0600 Subject: [PATCH] Page titles working but not quite right The on page title is correct; the title bar lags one click behind. --- src/wwwroot/App.elm | 5 +---- src/wwwroot/Home/Public.elm | 4 ++-- src/wwwroot/Messages.elm | 1 + src/wwwroot/Routing.elm | 2 +- src/wwwroot/Update.elm | 17 ++++++++++++++--- src/wwwroot/Utils/View.elm | 3 +-- src/wwwroot/View.elm | 30 ++++++++++++++++++------------ src/wwwroot/index.html | 6 +----- 8 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/wwwroot/App.elm b/src/wwwroot/App.elm index 9a2fe5b..5a4af80 100644 --- a/src/wwwroot/App.elm +++ b/src/wwwroot/App.elm @@ -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 diff --git a/src/wwwroot/Home/Public.elm b/src/wwwroot/Home/Public.elm index 15bff12..e345aec 100644 --- a/src/wwwroot/Home/Public.elm +++ b/src/wwwroot/Home/Public.elm @@ -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 = [ " " diff --git a/src/wwwroot/Messages.elm b/src/wwwroot/Messages.elm index 963a8af..ae4a5ef 100644 --- a/src/wwwroot/Messages.elm +++ b/src/wwwroot/Messages.elm @@ -1,6 +1,7 @@ module Messages exposing (..) import Navigation exposing (Location) +import Routing exposing (Route) type Msg diff --git a/src/wwwroot/Routing.elm b/src/wwwroot/Routing.elm index afb5fd6..1b1d346 100644 --- a/src/wwwroot/Routing.elm +++ b/src/wwwroot/Routing.elm @@ -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 diff --git a/src/wwwroot/Update.elm b/src/wwwroot/Update.elm index cdb6f50..a491f70 100644 --- a/src/wwwroot/Update.elm +++ b/src/wwwroot/Update.elm @@ -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) \ No newline at end of file + (model, documentTitle model.title) \ No newline at end of file diff --git a/src/wwwroot/Utils/View.elm b/src/wwwroot/Utils/View.elm index 8d4e397..0885bf1 100644 --- a/src/wwwroot/Utils/View.elm +++ b/src/wwwroot/Utils/View.elm @@ -33,8 +33,7 @@ navLink url linkText attrs = let attributes = List.concat - [ - [ title linkText + [ [ title linkText , onWithOptions "click" { defaultOptions | preventDefault = True } <| Json.succeed diff --git a/src/wwwroot/View.elm b/src/wwwroot/View.elm index 969e362..957c1fe 100644 --- a/src/wwwroot/View.elm +++ b/src/wwwroot/View.elm @@ -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" ] diff --git a/src/wwwroot/index.html b/src/wwwroot/index.html index 2f9a6b1..ae5a8f3 100644 --- a/src/wwwroot/index.html +++ b/src/wwwroot/index.html @@ -14,11 +14,7 @@
\ No newline at end of file