marlConsole

This commit is contained in:
Vincent CLAVIEN
2025-01-16 18:48:31 +01:00
parent de62473ace
commit 46bea0b205
3 changed files with 14 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ document.addEventListener("alpine:init", () => {
"Bonjour!",
"Oh hey!",
];
Alpine.store("ui").logMsg(`MARL loaded. ${salutations[Math.floor(Math.random() * salutations.length)]} 😊`);
marlConsole(`MARL loaded. ${salutations[Math.floor(Math.random() * salutations.length)]} 😊`);
resetStores();
});

View File

@@ -3,7 +3,7 @@ const userPrefsStore = {
save(pref, value) {
const msg = `Saving user preference <b>(${pref}: ${value})</b>`;
Alpine.store("ui").logMsg(msg, "info");
marlConsole(msg, "info");
localStorage.setItem(this.prefix + pref, value);
},
load(pref) {
@@ -41,7 +41,7 @@ const userPrefsStore = {
if (value) {
const msg = `<b>Unrecognized language</b> in user preferences: ${value}`;
console.warn(msg);
Alpine.store("ui").logMsg(msg, "warn");
marlConsole(msg, "warn");
}
value = "en";
this.save("lang", value);

View File

@@ -1,3 +1,7 @@
function marlConsole(msg, cls = "info") {
Alpine.store("ui").logMsg(msg, cls);
}
function resetStores() {
Alpine.store("files").resetState();
Alpine.store("lightbox").resetState();
@@ -25,11 +29,11 @@ function unZip(files) {
) {
const msg = `File already loaded: <b>${file.name}</b>`;
console.warn(msg);
Alpine.store("ui").logMsg(msg, "warn");
marlConsole(msg, "warn");
continue;
}
Alpine.store("ui").logMsg(`Loading file: <b>${file.name}</b>`, "info");
marlConsole(`Loading file: <b>${file.name}</b>`, "info");
JSZip.loadAsync(file).then(
(content) => {
@@ -72,7 +76,7 @@ function unZip(files) {
(error) => {
const msg = `Error loading <b>${file.name}</b>: ${error.message}`;
console.error(msg);
Alpine.store("ui").logMsg(msg, "error");
marlConsole(msg, "error");
abortLoading();
}
);
@@ -91,13 +95,13 @@ function loadJsonFile(name, index, fileInfos) {
// we can still run the app without those files
const msg = `<b>${fileInfos.name}</b>: File ${name}.json not found in archive.`;
console.warn(msg);
Alpine.store("ui").logMsg(msg, "warn");
marlConsole(msg, "warn");
Alpine.store("files").sources[index].loaded[name] = true;
} else {
// this should NOT happen and will prevent the app from running
const msg = `<b>Critical error - ${fileInfos.name}</b>: File ${name}.json not found in archive.`;
console.error(msg);
Alpine.store("ui").logMsg(msg, "error");
marlConsole(msg, "error");
}
return;
}
@@ -625,7 +629,7 @@ function detectLangFromBrowser() {
const msg = `Setting language based on browser preference: <b>'${lang}' (${
Alpine.store("ui").appLangs[lang]
})</b>`;
Alpine.store("ui").logMsg(msg, "info");
marlConsole(msg, "info");
return lang;
}
}
@@ -640,7 +644,7 @@ function setLang() {
document.getElementsByTagName("html")[0].setAttribute("lang", lang);
const msg = `App language set to <b>'${lang}' (${Alpine.store("ui").appLangs[lang]})</b>`;
Alpine.store("ui").logMsg(msg);
marlConsole(msg);
}
function setTheme(theme) {