From 7e58ec442dca8064a8128484b498c45bfa587519 Mon Sep 17 00:00:00 2001 From: Ryan <48137622+rstrom1763@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:00:45 -0800 Subject: [PATCH] Created callback for gallery load There is now a callback that makes it so when the gallery loads, the pick loading and page computation happen prior to the loading page being lifted. It still has a slight delay for some reason but it is at least an improvement. --- api/static/js/gallery.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/api/static/js/gallery.js b/api/static/js/gallery.js index b16ef08..cc42827 100644 --- a/api/static/js/gallery.js +++ b/api/static/js/gallery.js @@ -59,7 +59,7 @@ function markImage(id) { img.childNodes[0].style = "outline: " + borderPX + "px solid #ff6600;outline-offset: -" + borderPX + "px;" window.picks.count++ window.picks.picks.push(id) // Adds a picture to the list - savePicksToCookie(window.picks,"."+window.location.hostname,()=>{ + savePicksToCookie(window.picks,"."+window.location.hostname,()=> { document.getElementById("counter").innerHTML = window.picks.count + " Items Selected"; }); } @@ -113,7 +113,7 @@ function loadSelected(){ url = url.split("/"); url[5] = String("updatePicksCookie") url = url.join("/") - get_picks(url,() =>{ + get_picks(url,() => { // Set picks to cookie value let picks = getCookie("picks") @@ -143,19 +143,38 @@ function loadSelected(){ }); } +// Makes all the calls for things that happen on the page prior to the loading page going away +// Callback will be to take down loading page +function loadingStuff() { + + return new Promise((resolve,reject) => { + loadSelected() // Mark the previously selected images + + let url = window.location.href; + + url = url.split("/"); + document.getElementById("page_num").innerHTML = "Page " + String(parseInt(url[url.length - 1]) + 1) + resolve(); + reject(new Error("Something failed")); + }); + +} + // Wait for all images to load window.addEventListener("load", function () { - // Hide the loading screen once all images are loaded - const loadingScreen = document.getElementById("loading-screen"); - loadingScreen.style.display = "none"; + loadingStuff().then((result) => { - loadSelected() // Mark the previously selected images + // Hide the loading screen once all images are loaded + const loadingScreen = document.getElementById("loading-screen"); + loadingScreen.style.display = "none"; - let url = window.location.href; + }).catch((error) => { + + console.log(error) + + }); - url = url.split("/"); - document.getElementById("page_num").innerHTML = "Page " + String(parseInt(url[url.length - 1]) + 1) }); function nextPage() {