Theme doing devel detection properly with new state

This commit is contained in:
Neale Pickett 2020-02-28 15:42:55 -07:00
parent b540861097
commit 94acae13ca
2 changed files with 12 additions and 15 deletions

View File

@ -193,7 +193,7 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler):
self.send_header("Location", "%s/" % seed) self.send_header("Location", "%s/" % seed)
self.send_header("Content-Type", "text/html") self.send_header("Content-Type", "text/html")
self.end_headers() self.end_headers()
self.wfile.write("Your browser was supposed to redirect you to <a href=\"%s/\">here</a>." % seed) self.wfile.write(b"Your browser was supposed to redirect you to <a href=\"%i/\">here</a>." % seed)
endpoints.append((r"/", handle_index)) endpoints.append((r"/", handle_index))

View File

@ -1,5 +1,6 @@
// jshint asi:true // jshint asi:true
var devel = false
var teamId var teamId
var heartbeatInterval = 40000 var heartbeatInterval = 40000
@ -42,7 +43,7 @@ function renderPuzzles(obj) {
h.textContent = cat h.textContent = cat
// Extras if we're running a devel server // Extras if we're running a devel server
if (obj.__devel__) { if (devel) {
let a = document.createElement('a') let a = document.createElement('a')
h.insertBefore(a, h.firstChild) h.insertBefore(a, h.firstChild)
a.textContent = "⬇️" a.textContent = "⬇️"
@ -88,20 +89,16 @@ function renderPuzzles(obj) {
container.appendChild(puzzlesElement) container.appendChild(puzzlesElement)
} }
function renderState(obj) {
devel = obj.config.devel
console.log(obj)
renderPuzzles(obj.puzzles)
renderNotices(obj.messages)
}
function heartbeat(teamId, participantId) { function heartbeat(teamId, participantId) {
let noticesUrl = new URL("notices.html", window.location) let url = new URL("state", window.location)
fetch(noticesUrl)
.then(resp => {
if (resp.ok) {
resp.text()
.then(renderNotices)
.catch(err => console.log)
}
})
.catch(err => console.log)
let url = new URL("puzzles.json", window.location)
url.searchParams.set("id", teamId) url.searchParams.set("id", teamId)
if (participantId) { if (participantId) {
url.searchParams.set("pid", participantId) url.searchParams.set("pid", participantId)
@ -112,7 +109,7 @@ function heartbeat(teamId, participantId) {
.then(resp => { .then(resp => {
if (resp.ok) { if (resp.ok) {
resp.json() resp.json()
.then(renderPuzzles) .then(renderState)
.catch(err => { .catch(err => {
toast("Error fetching recent puzzles. I'll try again in a moment.") toast("Error fetching recent puzzles. I'll try again in a moment.")
console.log(err) console.log(err)