Skip to content

Commit

Permalink
fix: Jundefined now gone
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Nov 13, 2024
1 parent 6f423fa commit be0c600
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions scripts/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function getUserInformation() {
if (typeof response !== "undefined") user = { ...user, ...response.data };

// Update user image based on user details
setUserImageInitials(user.name);
document.getElementById("userInitials").innerText = getUserInitials(user.name);

// Make batch query for Gira client information, activeUserSubscriptions and tripHistory to speed up request
response = await makePostRequest(
Expand Down Expand Up @@ -234,10 +234,6 @@ async function openUserSettings() {
// Get subscription expiration
const subscriptionExpiration = new Date(userObj.activeUserSubscriptions[0].expirationDate);

// Get user initials
let allNames = userObj.name.trim().split(" "); // separate all names
let initials = allNames.length === 1 ? allNames[0][0] : allNames[0][0] + allNames.at(-1)[0]; // first letter of first name + first letter of last name

// Populate the element
settingsElement.innerHTML = `
<div id="topUserContainer">
Expand All @@ -246,7 +242,7 @@ async function openUserSettings() {
<img id="footer" src="assets/images/gira_footer_white.svg" alt="backImage">
<div id="bottomCard"></div>
<div id="userImage">
<div id="userInitialsSettings">${initials}</div>
<div id="userInitialsSettings">${getUserInitials(userObj.name)}</div>
</div>
</div>
<div id="userName">${userObj.name}</div>
Expand Down Expand Up @@ -394,17 +390,11 @@ function openSetProxyPrompt() {
);
}

function setUserImageInitials(username) {
// Set the initials of the user name to act like picture
// (removes dependency on ui-avatars.com)

function getUserInitials(username) {
// Get the initials
let allNames = username.split(" "); // separate all names
let initials = allNames[0][0] + allNames.at(-1)[0]; // first letter of first name + first letter of last name

// User picture (main screen)
let userInitialsElement = document.getElementById("userInitials");
userInitialsElement.innerHTML = initials;
const allNames = username.trim().split(" "); // separate all names
// first letter of first name + first letter of last name when present
return allNames.length === 1 ? allNames[0][0] : allNames[0][0] + allNames.at(-1)[0];
}

async function openTripHistory() {
Expand Down

0 comments on commit be0c600

Please sign in to comment.