Chanding how cache button is drawn/hidden

This commit is contained in:
John Donaldson 2019-11-08 19:24:33 +00:00
parent ae882ff349
commit cea803ee92
3 changed files with 14 additions and 17 deletions

View File

@ -133,3 +133,7 @@ li[draggable] {
[draggable].over {
border: 1px white dashed;
}
#cacheButton.disabled {
display: none;
}

View File

@ -27,6 +27,7 @@
<ul>
<li><a href="scoreboard.html">Scoreboard</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>
</nav>
</body>

View File

@ -111,18 +111,7 @@ function showPuzzles(teamId) {
}
function drawCacheButton(teamId) {
let cacher = document.createElement("li")
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)
let cacher = document.querySelector("#cacheButton")
function updateCacheButton() {
let headers = new Headers()
@ -133,13 +122,13 @@ function drawCacheButton(teamId) {
fetch(url, {method: "HEAD", headers: headers})
.then( resp => {
if (resp.ok) {
cacher.style.disply = "initial"
cacher.classList.remove("disabled")
} else {
cacher.style.display = "none"
cacher.classList.add("disabled")
}
})
.catch(ex => {
cacher.style.display = "none"
cacher.classList.add("disabled")
})
}
@ -147,7 +136,8 @@ function drawCacheButton(teamId) {
updateCacheButton()
}
async function fetchAll(teamId) {
async function fetchAll() {
let teamId = sessionStorage.getItem("id")
let headers = new Headers()
headers.append("pragma", "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)
url.searchParams.set("id", teamId)
toast("Caching all currently-open content")
requests.push( fetch(url, {headers: headers})
.then( resp => {
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) {