From 3a87ecb0ab1706c45ed8596e44d7d1c4c913148d Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 22 May 2018 22:57:28 +0100 Subject: [PATCH] Adds titles to threads and profiles. --- src/frontend/forum.nim | 5 ++++- src/frontend/postlist.nim | 4 +++- src/frontend/profile.nim | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/frontend/forum.nim b/src/frontend/forum.nim index 5c12905..6aef3b6 100644 --- a/src/frontend/forum.nim +++ b/src/frontend/forum.nim @@ -1,5 +1,5 @@ import strformat, times, options, json, tables, sugar, httpcore, uri -from dom import window, Location +from dom import window, Location, document include karax/prelude import jester/[patterns] @@ -10,6 +10,7 @@ import karaxutils type State = ref object + originalTitle: cstring url: Location profile: ProfileState newThread: NewThread @@ -33,6 +34,7 @@ proc copyLocation(loc: Location): Location = proc newState(): State = State( + originalTitle: document.title, url: copyLocation(window.location), profile: newProfileState(), newThread: newNewThread(), @@ -48,6 +50,7 @@ proc onPopState(event: dom.Event) = # history. I fire it in karaxutils.anchorCB as well to ensure the URL is # always updated. This should be moved into Karax in the future. kout(kstring"New URL: ", window.location.href, " ", state.url.href) + document.title = state.originalTitle if state.url.href != window.location.href: state = newState() # Reload the state to remove stale data. state.url = copyLocation(window.location) diff --git a/src/frontend/postlist.nim b/src/frontend/postlist.nim index 0e998c0..bd10d20 100644 --- a/src/frontend/postlist.nim +++ b/src/frontend/postlist.nim @@ -14,7 +14,7 @@ type posts*: seq[Post] when defined(js): - from dom import nil + from dom import document include karax/prelude import karax / [vstyles, kajax, kdom] @@ -65,6 +65,8 @@ when defined(js): state.list = some(list) + dom.document.title = list.thread.topic & " - " & dom.document.title + # The anchor should be jumped to once all the posts have been loaded. if postId.isSome(): discard setTimeout( diff --git a/src/frontend/profile.nim b/src/frontend/profile.nim index fd2f70c..cfe198c 100644 --- a/src/frontend/profile.nim +++ b/src/frontend/profile.nim @@ -3,6 +3,7 @@ import options, httpcore, json, sugar, times, strformat, strutils import threadlist, post, category, error, user when defined(js): + from dom import document include karax/prelude import karax/[kajax, kdom] import karaxutils, postbutton, delete, profilesettings @@ -37,6 +38,8 @@ when defined(js): state.profile = some(profile) state.settings = some(newProfileSettings(profile)) + dom.document.title = profile.user.name & " - " & dom.document.title + proc genPostLink(link: PostLink): VNode = let url = renderPostUrl(link) result = buildHtml():