42f5fb0ef407 — Ted Unangst 3 months ago
try anchoring specific post in threads
3 files changed, 22 insertions(+), 7 deletions(-)

M honk.go
M views/honk.html
M views/honkpage.js
M honk.go +4 -0
@@ 200,6 200,10 @@ func (honk *Honk) IsReacted() bool {
 	return honk.Flags&flagIsReacted != 0
 }
 
+func (honk *Honk) ShortXID() string {
+	return shortxid(honk.XID)
+}
+
 type Donk struct {
 	FileID   int64
 	XID      string

          
M views/honk.html +2 -2
@@ 1,4 1,4 @@ 
-<article class="honk {{ .Honk.Style }}" data-convoy="{{ .Honk.Convoy }}" data-hname="{{ .Honk.Handles }}" data-xid="{{ .Honk.XID }}" data-id="{{ .Honk.ID }}">
+<article id="{{ .Honk.ShortXID }}" class="honk {{ .Honk.Style }}" data-convoy="{{ .Honk.Convoy }}" data-hname="{{ .Honk.Handles }}" data-xid="{{ .Honk.XID }}" data-id="{{ .Honk.ID }}">
 {{ $bonkcsrf := .BonkCSRF }}
 {{ $IsPreview := .IsPreview }}
 {{ $maplink := .MapLink }}

          
@@ 47,7 47,7 @@ in reply to: <a href="{{ .RID }}" rel=no
 {{ end }}
 <br>
 {{ if $bonkcsrf }}
-<span class="left1em clip">convoy: <a class="convoylink" href="/t?c={{ .Convoy }}">{{ .Convoy }}</a></span>
+<span class="left1em clip">convoy: <a class="convoylink" href="/t?c={{ .Convoy }}#{{ .ShortXID }}">{{ .Convoy }}</a></span>
 {{ end }}
 </header>
 <p>

          
M views/honkpage.js +16 -5
@@ 194,7 194,7 @@ function statechanger(evt) {
 	}
 	switchtopage(data.name, data.arg)
 }
-function switchtopage(name, arg) {
+function switchtopage(name, arg, anchor) {
 	var stash = curpagestate.name + ":" + curpagestate.arg
 	var honksonpage = document.getElementById("honksonpage")
 	var holder = honksonpage.children[0]

          
@@ 220,6 220,10 @@ function switchtopage(name, arg) {
 		if (msg) {
 			srvel.prepend(msg)
 		}
+		if (anchor) {
+			let el = document.getElementById(anchor)
+			el.scrollIntoView()
+		}
 	} else {
 		// or create one and fill it
 		honksonpage.prepend(document.createElement("div"))

          
@@ 227,6 231,10 @@ function switchtopage(name, arg) {
 		get("/hydra?" + encode(args), function(xhr) {
 			if (xhr.status == 200) {
 				fillinhonks(xhr, false)
+				if (anchor) {
+					let el = document.getElementById(anchor)
+					el.scrollIntoView()
+				}
 			} else {
 				refreshupdate(" status: " + xhr.status)
 			}

          
@@ 246,11 254,14 @@ function pageswitcher(name, arg) {
 		if (name == curpagestate.name && arg == curpagestate.arg) {
 			return false
 		}
-		switchtopage(name, arg)
-		var url = evt.srcElement.href
-		if (!url) {
+		let url = evt.srcElement.href
+		if (!url)
 			url = evt.srcElement.parentElement.href
-		}
+		let anchor
+		let arr = url.split("#")
+		if (arr.length == 2)
+			anchor = arr[1]
+		switchtopage(name, arg, anchor)
 		history.pushState(newpagestate(name, arg), "some title", url)
 		window.scrollTo(0, 0)
 		return false