From ae30004fc0b0560d1c139e555e658cb44276a030 Mon Sep 17 00:00:00 2001 From: afonsosousah Date: Sun, 5 May 2024 19:39:57 +0100 Subject: [PATCH] feat: added EMEL system messages and added icons to alert boxes --- assets/style.css | 12 ++++++++- index.html | 4 +-- scripts/dialogs.js | 8 +++++- scripts/map.js | 19 ++------------- scripts/user.js | 61 ++++++++++++++++++++++++++++++++-------------- scripts/version.js | 2 +- 6 files changed, 66 insertions(+), 40 deletions(-) diff --git a/assets/style.css b/assets/style.css index de73761..6ac8d5f 100644 --- a/assets/style.css +++ b/assets/style.css @@ -2105,9 +2105,19 @@ input:-webkit-autofill:active{ max-width: 100%; } +#alertBox #title { + color: var(--green); + font-weight: bold; + font-size: 1.2rem; + display: block; + margin-top: 1rem; + margin-left: 1.5rem; +} + #alertBox p { - padding: 8%; + padding: 0.5rem 1.5rem 1.5rem 1.5rem; margin: 0; + font-size: 0.9rem; } #alertBox #customTextPromptInput { diff --git a/index.html b/index.html index 53f9b49..15aadb2 100644 --- a/index.html +++ b/index.html @@ -174,9 +174,9 @@ // define a custom alert box if (document.getElementById) { - window.alert = message => { + window.alert = (message, title = ``) => { // set timeout so that if the user clicks on the place where the button is, it doesn't get automatically clicked - setTimeout(() => createCustomAlert(message), 50); + setTimeout(() => createCustomAlert(message, title), 50); }; } diff --git a/scripts/dialogs.js b/scripts/dialogs.js index 7cd6aa5..467cae3 100644 --- a/scripts/dialogs.js +++ b/scripts/dialogs.js @@ -1,5 +1,5 @@ // Custom styled alert with OK option -function createCustomAlert(message) { +function createCustomAlert(message, title = null) { if (document.getElementById("modalContainer")) return; const mObj = document.createElement("div"); @@ -8,6 +8,12 @@ function createCustomAlert(message) { const alertObj = mObj.appendChild(document.createElement("div")); alertObj.id = "alertBox"; + if (title) { + const titleObj = alertObj.appendChild(document.createElement("span")); + titleObj.id = "title"; + titleObj.innerHTML = title; + } + const msg = alertObj.appendChild(document.createElement("p")); msg.innerHTML = message; diff --git a/scripts/map.js b/scripts/map.js index 3186e31..0c18fad 100644 --- a/scripts/map.js +++ b/scripts/map.js @@ -109,23 +109,8 @@ async function initMap() { user.accessToken = accessTokenCookie; } - // Start WebSocket connection - startWSConnection(); - - // Get all user details - getUserInformation(); - - // Check if update info should be shown - showUpdateInfoIfNeeded(); - - // Get the user location on app open - getLocation(); - - // Start rotation of location dot - startLocationDotRotation(); - - // Get the stations and load them to the map - await getStations(); + /* Run the startup functions */ + await runStartupFunctions(); } function mapDotSVG(ratio, docks = false) { diff --git a/scripts/user.js b/scripts/user.js index 669056e..cece1d6 100644 --- a/scripts/user.js +++ b/scripts/user.js @@ -63,24 +63,7 @@ async function login(event) { user.expiration = response.data.expiration; /* Run the startup functions */ - - // Start WebSocket connection - startWSConnection(); - - // Get all user details - getUserInformation(); - - // Check if update info should be shown - showUpdateInfoIfNeeded(); - - // Get the stations and load them to the map - await getStations(); - - // Get the user location on app open - getLocation(); - - // Start rotation of location dot - startLocationDotRotation(); + await runStartupFunctions(); // Set the cookie expiry to 1 year after today. const refreshTokenExpiryDate = new Date(); @@ -103,6 +86,48 @@ async function login(event) { } } +async function runStartupFunctions() { + // Start WebSocket connection + startWSConnection(); + + // Get all user details + getUserInformation(); + + // Check if update info should be shown + showUpdateInfoIfNeeded(); + + // Get the user location on app open + getLocation(); + + // Start rotation of location dot + startLocationDotRotation(); + + // Get the stations and load them to the map + await getStations(); + + // Show any messages from EMEL + await validateLogin(); +} + +async function validateLogin() { + const response = await makePostRequest( + "https://apigira.emel.pt/graphql", + JSON.stringify({ + query: `mutation { + validateLogin(in: { + language: "pt", + userAgent: "Gira/3.3.5 (Android 34)", + firebaseToken: "cwEUfibvTHCRZ6z3R1l3B8" + }) { messages { code text } } + }`, + }) + ); + + for (const message of response?.data?.validateLogin?.messages) { + createCustomAlert(message.text, ``); + } +} + // Gets all the user information async function getUserInformation() { // get the general information (without using the proxy) diff --git a/scripts/version.js b/scripts/version.js index 188cbf0..054dee3 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -26,7 +26,7 @@ function showUpdateInfoIfNeeded() { // Check version to show update notes const userVersion = getCookie("version"); if (userVersion !== currentVersion) { - alert(changelogHTML); + alert(changelogHTML, ``); createCookie("version", currentVersion, expiryDate); } }, 1500);