From e14d44ed97ec38a4b1bb683db2f5f2b87470e7ce Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 7 Aug 2020 21:29:16 +0100 Subject: [PATCH] db config not loading if user started test or changed something if user changed it or --- public/js/account.js | 67 +++++++++++++++++++++++------------------ public/js/script.js | 4 +++ public/js/settings.js | 4 +-- public/js/userconfig.js | 15 ++++++--- 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/public/js/account.js b/public/js/account.js index e624dae82..7692a6b66 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -229,39 +229,46 @@ firebase.auth().onAuthStateChanged(function (user) { }); refreshTagsSettingsSection(); updateDiscordSettingsSection(); - if (cookieConfig === null) { - applyConfig(dbSnapshot.config); - // showNotification('Applying db config',3000); - updateSettingsPage(); - saveConfigToCookie(); - } else if (dbSnapshot.config !== undefined) { - let configsDifferent = false; - Object.keys(config).forEach((key) => { - if (!configsDifferent) { - try { - if (key !== "resultFilters") { - if (Array.isArray(config[key])) { - config[key].forEach((arrval, index) => { - if (arrval != dbSnapshot.config[key][index]) - configsDifferent = true; - }); - } else { - if (config[key] != dbSnapshot.config[key]) - configsDifferent = true; - } - } - } catch (e) { - console.log(e); - configsDifferent = true; - } - } - }); - if (configsDifferent) { + if (!configChangedBeforeDb) { + if (cookieConfig === null) { + dbConfigLoaded = true; + accountIconLoading(false); applyConfig(dbSnapshot.config); - // showNotification('Applying db config',3000); + showNotification('Applying db config',3000); updateSettingsPage(); - saveConfigToCookie(); + saveConfigToCookie(true); + } else if (dbSnapshot.config !== undefined) { + let configsDifferent = false; + Object.keys(config).forEach((key) => { + if (!configsDifferent) { + try { + if (key !== "resultFilters") { + if (Array.isArray(config[key])) { + config[key].forEach((arrval, index) => { + if (arrval != dbSnapshot.config[key][index]) + configsDifferent = true; + }); + } else { + if (config[key] != dbSnapshot.config[key]) + configsDifferent = true; + } + } + } catch (e) { + console.log(e); + configsDifferent = true; + } + } + }); + if (configsDifferent) { + dbConfigLoaded = true; + accountIconLoading(false); + applyConfig(dbSnapshot.config); + updateSettingsPage(); + saveConfigToCookie(true); + } } + } else { + accountIconLoading(false); } }); var displayName = user.displayName; diff --git a/public/js/script.js b/public/js/script.js index a50f2df78..457fb6fda 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1891,6 +1891,10 @@ function showResult(difficultyFailed = false) { } function startTest() { + if (!dbConfigLoaded) { + console.log('config changed before db loaded!'); + configChangedBeforeDb = true; + } try { if (firebase.auth().currentUser != null) { firebase.analytics().logEvent("testStarted"); diff --git a/public/js/settings.js b/public/js/settings.js index f8bd2e155..061d76d2c 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -588,7 +588,7 @@ $(".pageSettings .section.themes .tabs .button").click((e) => { $target.addClass("active"); setCustomThemeInputs(); if ($target.attr("tab") == "preset") { - setCustomTheme(false); + setCustomTheme(false, true); applyCustomThemeColors(); swapElements( $('.pageSettings .section.themes .tabContainer [tabContent="custom"]'), @@ -596,7 +596,7 @@ $(".pageSettings .section.themes .tabs .button").click((e) => { 250 ); } else { - setCustomTheme(true); + setCustomTheme(true, true); applyCustomThemeColors(); swapElements( $('.pageSettings .section.themes .tabContainer [tabContent="preset"]'), diff --git a/public/js/userconfig.js b/public/js/userconfig.js index a42ab3c9c..0d7ea8d92 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -53,8 +53,15 @@ let config = { ...defaultConfig, }; +let dbConfigLoaded = false; +let configChangedBeforeDb = false; + //cookies -async function saveConfigToCookie() { +async function saveConfigToCookie(noDbCheck = false) { + if (!dbConfigLoaded && !noDbCheck) { + console.log('config changed before db loaded!'); + configChangedBeforeDb = true; + } // showNotification('saving to cookie',1000); if (config.freedomMode === null) config.freedomMode = false; let d = new Date(); @@ -65,7 +72,7 @@ async function saveConfigToCookie() { path: "/", }); restartCount = 0; - saveConfigToDB(); + if(!noDbCheck) saveConfigToDB(); } async function saveConfigToDB() { @@ -76,7 +83,7 @@ async function saveConfigToDB() { (d) => { accountIconLoading(false); if (d.data === 1) { - // showNotification('config saved to db',1000); + showNotification('config saved to db',1000); } else { showNotification("Error saving config to DB!", 4000); } @@ -111,7 +118,7 @@ function loadConfigFromCookie() { applyConfig(newConfig); cookieConfig = newConfig; - saveConfigToCookie(); + saveConfigToCookie(true); } }