db config not loading if user started test or changed something if user changed it or

This commit is contained in:
Jack 2020-08-07 21:29:16 +01:00
parent 6b5faeb6c0
commit e14d44ed97
4 changed files with 54 additions and 36 deletions

View file

@ -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;

View file

@ -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");

View file

@ -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"]'),

View file

@ -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);
}
}