mirror of https://github.com/dirtbags/moth.git
Chanding how cache button is drawn/hidden
This commit is contained in:
parent
ae882ff349
commit
cea803ee92
|
@ -133,3 +133,7 @@ li[draggable] {
|
||||||
[draggable].over {
|
[draggable].over {
|
||||||
border: 1px white dashed;
|
border: 1px white dashed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#cacheButton.disabled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="scoreboard.html">Scoreboard</a></li>
|
<li><a href="scoreboard.html">Scoreboard</a></li>
|
||||||
<li><a href="logout.html">Sign Out</a></li>
|
<li><a href="logout.html">Sign Out</a></li>
|
||||||
|
<li id="cacheButton" class="disabled"><a href="#" onclick='fetchAll()' title="Cache am offline copy of current content">Cache</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -111,18 +111,7 @@ function showPuzzles(teamId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawCacheButton(teamId) {
|
function drawCacheButton(teamId) {
|
||||||
let cacher = document.createElement("li")
|
let cacher = document.querySelector("#cacheButton")
|
||||||
let cache_button = document.createElement("a")
|
|
||||||
cache_button.innerText = "Cache"
|
|
||||||
cache_button.title = "Cache an offine copy of current content"
|
|
||||||
cache_button.href = "#"
|
|
||||||
cache_button.addEventListener("click", async function() {
|
|
||||||
toast("Caching all currently-open content")
|
|
||||||
await fetchAll(teamId)
|
|
||||||
toast("Done caching content")
|
|
||||||
})
|
|
||||||
cacher.appendChild(cache_button)
|
|
||||||
document.getElementsByTagName("nav")[0].getElementsByTagName("ul")[0].appendChild(cacher)
|
|
||||||
|
|
||||||
function updateCacheButton() {
|
function updateCacheButton() {
|
||||||
let headers = new Headers()
|
let headers = new Headers()
|
||||||
|
@ -133,13 +122,13 @@ function drawCacheButton(teamId) {
|
||||||
fetch(url, {method: "HEAD", headers: headers})
|
fetch(url, {method: "HEAD", headers: headers})
|
||||||
.then( resp => {
|
.then( resp => {
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
cacher.style.disply = "initial"
|
cacher.classList.remove("disabled")
|
||||||
} else {
|
} else {
|
||||||
cacher.style.display = "none"
|
cacher.classList.add("disabled")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(ex => {
|
.catch(ex => {
|
||||||
cacher.style.display = "none"
|
cacher.classList.add("disabled")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +136,8 @@ function drawCacheButton(teamId) {
|
||||||
updateCacheButton()
|
updateCacheButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAll(teamId) {
|
async function fetchAll() {
|
||||||
|
let teamId = sessionStorage.getItem("id")
|
||||||
let headers = new Headers()
|
let headers = new Headers()
|
||||||
headers.append("pragma", "no-cache")
|
headers.append("pragma", "no-cache")
|
||||||
headers.append("cache-control", "no-cache")
|
headers.append("cache-control", "no-cache")
|
||||||
|
@ -155,6 +145,7 @@ async function fetchAll(teamId) {
|
||||||
let url = new URL("current_manifest.json", window.location)
|
let url = new URL("current_manifest.json", window.location)
|
||||||
url.searchParams.set("id", teamId)
|
url.searchParams.set("id", teamId)
|
||||||
|
|
||||||
|
toast("Caching all currently-open content")
|
||||||
requests.push( fetch(url, {headers: headers})
|
requests.push( fetch(url, {headers: headers})
|
||||||
.then( resp => {
|
.then( resp => {
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
|
@ -198,7 +189,8 @@ async function fetchAll(teamId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.all(requests)
|
await Promise.all(requests)
|
||||||
|
toast("Done caching content")
|
||||||
}
|
}
|
||||||
|
|
||||||
function login(e) {
|
function login(e) {
|
||||||
|
|
Loading…
Reference in New Issue