Adds titles to threads and profiles.
This commit is contained in:
parent
2f2d83b86c
commit
3a87ecb0ab
3 changed files with 10 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import strformat, times, options, json, tables, sugar, httpcore, uri
|
import strformat, times, options, json, tables, sugar, httpcore, uri
|
||||||
from dom import window, Location
|
from dom import window, Location, document
|
||||||
|
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import jester/[patterns]
|
import jester/[patterns]
|
||||||
|
|
@ -10,6 +10,7 @@ import karaxutils
|
||||||
|
|
||||||
type
|
type
|
||||||
State = ref object
|
State = ref object
|
||||||
|
originalTitle: cstring
|
||||||
url: Location
|
url: Location
|
||||||
profile: ProfileState
|
profile: ProfileState
|
||||||
newThread: NewThread
|
newThread: NewThread
|
||||||
|
|
@ -33,6 +34,7 @@ proc copyLocation(loc: Location): Location =
|
||||||
|
|
||||||
proc newState(): State =
|
proc newState(): State =
|
||||||
State(
|
State(
|
||||||
|
originalTitle: document.title,
|
||||||
url: copyLocation(window.location),
|
url: copyLocation(window.location),
|
||||||
profile: newProfileState(),
|
profile: newProfileState(),
|
||||||
newThread: newNewThread(),
|
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
|
# 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.
|
# always updated. This should be moved into Karax in the future.
|
||||||
kout(kstring"New URL: ", window.location.href, " ", state.url.href)
|
kout(kstring"New URL: ", window.location.href, " ", state.url.href)
|
||||||
|
document.title = state.originalTitle
|
||||||
if state.url.href != window.location.href:
|
if state.url.href != window.location.href:
|
||||||
state = newState() # Reload the state to remove stale data.
|
state = newState() # Reload the state to remove stale data.
|
||||||
state.url = copyLocation(window.location)
|
state.url = copyLocation(window.location)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ type
|
||||||
posts*: seq[Post]
|
posts*: seq[Post]
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
from dom import nil
|
from dom import document
|
||||||
|
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [vstyles, kajax, kdom]
|
import karax / [vstyles, kajax, kdom]
|
||||||
|
|
@ -65,6 +65,8 @@ when defined(js):
|
||||||
|
|
||||||
state.list = some(list)
|
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.
|
# The anchor should be jumped to once all the posts have been loaded.
|
||||||
if postId.isSome():
|
if postId.isSome():
|
||||||
discard setTimeout(
|
discard setTimeout(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import options, httpcore, json, sugar, times, strformat, strutils
|
||||||
import threadlist, post, category, error, user
|
import threadlist, post, category, error, user
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
|
from dom import document
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax/[kajax, kdom]
|
import karax/[kajax, kdom]
|
||||||
import karaxutils, postbutton, delete, profilesettings
|
import karaxutils, postbutton, delete, profilesettings
|
||||||
|
|
@ -37,6 +38,8 @@ when defined(js):
|
||||||
state.profile = some(profile)
|
state.profile = some(profile)
|
||||||
state.settings = some(newProfileSettings(profile))
|
state.settings = some(newProfileSettings(profile))
|
||||||
|
|
||||||
|
dom.document.title = profile.user.name & " - " & dom.document.title
|
||||||
|
|
||||||
proc genPostLink(link: PostLink): VNode =
|
proc genPostLink(link: PostLink): VNode =
|
||||||
let url = renderPostUrl(link)
|
let url = renderPostUrl(link)
|
||||||
result = buildHtml():
|
result = buildHtml():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue