diff --git a/tunictracker/tracker/static/tracker/assets/main.js b/tunictracker/tracker/static/tracker/assets/main.js index f84c233..3af87f4 100644 --- a/tunictracker/tracker/static/tracker/assets/main.js +++ b/tunictracker/tracker/static/tracker/assets/main.js @@ -79,7 +79,6 @@ async function initialize_elements() { return; } - // Initialize global state current_checks = checks.collected + checks.found; current_entrances = entrances.found; @@ -122,32 +121,39 @@ async function initialize_elements() { async function refresh_elements() { try { - const response = await update.fetch_api(server_address, "overview"); + const response = await update.fetch_api(server_address, "overview"); - // Check if the "Hide completed areas" option is checked - hide_completed_areas = document.getElementById("hideDone").checked; + // Check if the "Hide completed areas" option is checked + hide_completed_areas = document.getElementById("hideDone").checked; - if (response.data) { - if (!can_access_api_server) { - console.info("I found the server!"); - document.getElementById("status-block").classList.add("hidden"); - can_access_api_server = true; - await initialize_elements(); - } - is_timeout = false; - await update_if_changes(response.data); - setTimeout(refresh_elements, 500) - } else if (response.error) { - setTimeout(refresh_elements, 1100) - if (response.error.error) { - if (!is_timeout) { - is_timeout = true; - console.debug("Received timeout from API server."); - } + if (response.data) { if (!can_access_api_server) { console.info("I found the server!"); document.getElementById("status-block").classList.add("hidden"); can_access_api_server = true; + await initialize_elements(); + } + is_timeout = false; + await update_if_changes(response.data); + setTimeout(refresh_elements, 500); + } else if (response.error) { + setTimeout(refresh_elements, 1100); + if (response.error.error) { + if (!is_timeout) { + is_timeout = true; + console.debug("Received timeout from API server."); + } + if (!can_access_api_server) { + console.info("I found the server!"); + document.getElementById("status-block").classList.add("hidden"); + can_access_api_server = true; + } + } else { + if (can_access_api_server) { + console.debug("Could not access the API server."); + document.getElementById("status-block").classList.remove("hidden"); + } + can_access_api_server = false; } } else { if (can_access_api_server) { @@ -155,21 +161,11 @@ async function refresh_elements() { document.getElementById("status-block").classList.remove("hidden"); } can_access_api_server = false; + setTimeout(refresh_elements, 1100); } - } else { - if (can_access_api_server) { - console.debug("Could not access the API server."); - document.getElementById("status-block").classList.remove("hidden"); - } - can_access_api_server = false; - setTimeout(refresh_elements, 1100) - } - } catch (error) { - setTimeout(refresh_elements, 1100) + setTimeout(refresh_elements, 1100); } - - } async function update_if_changes(overview) { @@ -574,7 +570,9 @@ async function initialize_checks_list(checks_list, checks) { // Update the check totals checks_list.querySelector( ".breakdown-block-checks-title" - ).textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining} left)`; + ).textContent = `Checks: ${checks.collected + checks.found}/${ + checks.total + } (${checks.remaining} left)`; checks_list.querySelector( ".breakdown-block-checks-title" ).dataset.checksCollected = checks.collected + checks.found; @@ -725,7 +723,9 @@ async function initialize_summary(summary_element, scene, checks, entrances) { summary_checks.dataset.checksCollected = checks.collected + checks.found; summary_checks.dataset.checksRemaining = checks.remaining; summary_checks.dataset.checksTotal = checks.total; - summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining})`; + summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${ + checks.total + } (${checks.remaining})`; const summary_entrances = summary_element.querySelector(".summary-entrances"); summary_entrances.dataset.entrancesFound = entrances.found; @@ -787,7 +787,9 @@ async function update_summary(scene, checks, entrances) { summary_checks.dataset.checksCollected = checks.collected + checks.found; summary_checks.dataset.checksRemaining = checks.remaining; summary_checks.dataset.checksTotal = checks.total; - summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining})`; + summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${ + checks.total + } (${checks.remaining})`; } if (entrances_changed) { summary_entrances.dataset.entrancesFound = entrances.found; @@ -856,7 +858,9 @@ async function update_breakdown_checks(scene, checks) { // Update the check totals document.querySelector( `.breakdown[data-scene="${scene}"] .breakdown-block-checks-title` - ).textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining} left)`; + ).textContent = `Checks: ${checks.collected + checks.found}/${ + checks.total + } (${checks.remaining} left)`; document.querySelector( `.breakdown[data-scene="${scene}"] .breakdown-block-checks-title` ).dataset.checksCollected = checks.collected + checks.found; @@ -925,7 +929,10 @@ async function update_breakdown(scene, checks, entrances) { ); // Check for changes, and if so, update - if (breakdown_checks.dataset.checksCollected != checks.collected + checks.found) { + if ( + breakdown_checks.dataset.checksCollected != + checks.collected + checks.found + ) { update_breakdown_checks(scene, checks); } if (breakdown_entrances.dataset.entrancesFound != entrances.found) { @@ -948,9 +955,12 @@ async function update_breakdown_list(data, changed) { update_breakdown( scene, { - collected: document.querySelector( - `.breakdown[data-scene="${scene}"] .breakdown-block-checks-title` - ).dataset.checksCollected, + collected: parseInt( + document.querySelector( + `.breakdown[data-scene="${scene}"] .breakdown-block-checks-title` + ).dataset.checksCollected + ), + found: 0, }, data.scenes[scene] )