all repos — honk @ dabfdf4ee1de720202b200299ad848fffb6891e1

my fork of honk

experimental refresh button. dynamic html here we come.
Ted Unangst tedu@tedunangst.com
Mon, 19 Aug 2019 03:02:24 -0400
commit

dabfdf4ee1de720202b200299ad848fffb6891e1

parent

2928641390c96b82fc1a934377f352cf68b637c5

3 files changed, 52 insertions(+), 1 deletions(-)

jump to
M honk.gohonk.go

@@ -165,10 +165,25 @@ honks = gethonksforme(userid)

} else { honks = gethonksforuser(userid) honks = osmosis(honks, userid) + if len(honks) > 0 { + templinfo["TopXID"] = honks[0].XID + } } templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } + tname := "honkpage.html" + if topxid := r.FormValue("topxid"); topxid != "" { + for i, h := range honks { + if h.XID == topxid { + honks = honks[0:i] + break + } + } + log.Printf("topxid %d frags", len(honks)) + tname = "honkfrags.html" + } + reverbolate(userid, honks) templinfo["Honks"] = honks

@@ -179,7 +194,9 @@ w.Header().Set("Cache-Control", "max-age=60")

} else { w.Header().Set("Cache-Control", "max-age=0") } - err := readviews.Execute(w, "honkpage.html", templinfo) + w.Header().Set("Content-Type", "text/html") + + err := readviews.Execute(w, tname, templinfo) if err != nil { log.Print(err) }

@@ -1513,6 +1530,7 @@ debug := false

getconfig("debug", &debug) readviews = templates.Load(debug, "views/honkpage.html", + "views/honkfrags.html", "views/honkers.html", "views/zonkers.html", "views/combos.html",
A views/honkfrags.html

@@ -0,0 +1,5 @@

+<div>{{ .TopXID }}</div> +{{ $BonkCSRF := .HonkCSRF }} +{{ range .Honks }} +{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }} +{{ end }}
M views/honkpage.htmlviews/honkpage.html

@@ -11,6 +11,27 @@ {{ template "honkform.html" . }}

{{ end }} </div> {{ $BonkCSRF := .HonkCSRF }} +{{ if .TopXID }} +<div class="info" id="refreshbox"> +<script> +var topxid = {{ .TopXID }} +function refreshhonks() { + get("/?topxid=" + escape(topxid), function(xhr) { + var doc = xhr.responseXML + topel = doc.children[0].children[1].children[0] + topxid = topel.innerText + honks = doc.children[0].children[1].children + var mebox = document.getElementById("refreshbox") + for (var i = honks.length; i > 1; i--) { + mebox.insertAdjacentElement('afterend', honks[i-1]) + } + }) +} +</script> +<p><button onclick="refreshhonks()">refresh</button> +</div> + +{{ end }} {{ range .Honks }} {{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }} {{ end }}

@@ -30,6 +51,13 @@ var x = new XMLHttpRequest()

x.open("POST", url) x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") x.send(data) +} +function get(url, whendone) { + var x = new XMLHttpRequest() + x.open("GET", url) + x.responseType = "document" + x.onload = function() { whendone(x) } + x.send() } function bonk(el, xid) { el.innerHTML = "bonked"