Adds titles to threads and profiles.

This commit is contained in:
Dominik Picheta 2018-05-22 22:57:28 +01:00
commit 3a87ecb0ab
3 changed files with 10 additions and 2 deletions

View file

@ -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)

View file

@ -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(

View file

@ -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():