Frontend: Refactor indexjs

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-23 19:29:20 +00:00
parent 67cc929158
commit 0958bc92f5
2 changed files with 40 additions and 32 deletions

View File

@ -1,38 +1,21 @@
// Init:
setQls();
clearLoading();
pageInit();
async function sidebarOpen() {
document.getElementById("sidebar").style.width = "50%";
document.getElementById("sidebar_open_short").style.display = "none";
document.getElementById("sidebar_close_short").style.display = "block";
}
async function sidebarClose() {
document.getElementById("sidebar").style.width = "0%"
document.getElementById("sidebar_open_short").style.display = "block";
document.getElementById("sidebar_close_short").style.display = "none";
async function pageInit() {
await loadQuickLinks();
hideLoading();
}
async function gotoBoard(station){
window.location.assign(`${window.location.origin}/board.html?stn=${station}`)
window.location.assign(`${window.location.origin}/board.html?stn=${station}`);
}
async function setQls(){
var qlOpt = JSON.parse(localStorage.getItem("qlOpt"))
var qlDef = ["bri","lwh","srd","mtp","rda","cfn","sml","shh","pri","avn","sar","svb"]
if (qlOpt) {
for(var i = 0; i < qlOpt.length; i++) {
console.log(`Button: ${qlOpt[i]}`)
var btn = `<button class="actionbutton" onclick="gotoBoard('${qlOpt[i]}')">${qlOpt[i].toUpperCase()}</button>`
console.log(btn);
document.getElementById("quick_links").insertAdjacentHTML("beforeend", btn) // Append btn
}
} else {
for(var i = 0; i < qlDef.length; i++) {
console.log(`Button: ${qlDef[i]}`)
var btn = `<button class="actionbutton" onclick="gotoBoard('${qlDef[i]}')">${qlDef[i].toUpperCase()}</button>`
document.getElementById("quick_links").insertAdjacentHTML("beforeend", btn) // Append btn
async function loadQuickLinks(){
var data = await getQuickLinks(); // From lib.main
var buttons = "";
for(var i = 0; i < data.length; i++) {
buttons += `
<button class="actionbutton" onclick="gotoBoard('${data[i]}')">${data[i].toUpperCase()}</button>`
}
}
document.getElementById("quick_links").insertAdjacentHTML("beforeend", buttons)
}

View File

@ -16,7 +16,7 @@ async function storageAvailable(type) {
}
/* Delays */
/* Timeouts */
/* Usage: '' */
const delay = ms => new Promise(res => setTimeout(res, ms));
@ -43,6 +43,19 @@ async function log(msg, type) {
};
};
/* Menu Control */
async function sidebarOpen() {
document.getElementById("sidebar").style.width = "50%";
document.getElementById("sidebar_open_short").style.display = "none";
document.getElementById("sidebar_close_short").style.display = "block";
}
async function sidebarClose() {
document.getElementById("sidebar").style.width = "0%"
document.getElementById("sidebar_open_short").style.display = "block";
document.getElementById("sidebar_close_short").style.display = "none";
}
/* Loading Box Control */
async function hideLoading() {
document.getElementById("loading").style = "display: none;";
@ -50,7 +63,7 @@ async function hideLoading() {
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
async function clearLoading() {
log("Depreciated function called - clearLoading()", "WARN")
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN")
await hideLoading();
}
@ -61,3 +74,15 @@ async function showLoading() {
async function setLoadingDesc(desc) {
document.getElementById("loading_desc").textContent = `${desc}`;
}
/* Fetch User Settings */
async function getQuickLinks() {
try {
var data = JSON.parse(localStorage.getItem("qlOpt"));
} catch (err) {
var data =
["bri","lwh","srd","mtp","rda","cfn",
"sml","shh","pri","avn","sar","svb"];
}
return data;
}