Skip to content

Commit

Permalink
Profile picture always on top when changed or added
Browse files Browse the repository at this point in the history
  • Loading branch information
saertna committed Sep 1, 2024
1 parent 5dfe25a commit 17b8002
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class GamifiedPkmProfileView extends ItemView {

const profileContainer = container.createDiv({ cls: 'avatar-profile' });

const imagePath = this.mediator.getSettingString('avatarPicture'); // Assuming a function to get the setting value
this.updateProfilePicture();

/*const imagePath = this.mediator.getSettingString('avatarPicture'); // Assuming a function to get the setting value
// Conditionally create the avatar image if the path is provided
if (imagePath) {
Expand All @@ -43,7 +45,7 @@ export class GamifiedPkmProfileView extends ItemView {
} else {
// Remove the image container if no path is provided
profileContainer.empty();
}
}*/

const levelAndPointsContainer = profileContainer.createDiv({ cls: 'level-and-points' });
levelAndPointsContainer.innerHTML = `
Expand Down Expand Up @@ -354,20 +356,25 @@ export class GamifiedPkmProfileView extends ItemView {

updateProfilePicture() {
const container = this.containerEl.children[1];
const profileContainer = container.querySelector('.avatar-profile');
const profileContainer = container.querySelector('.avatar-profile') as HTMLElement;

if (profileContainer) {
const imagePath = this.mediator.getSettingString('avatarPicture'); // Fetch the updated setting
const avatarImage = profileContainer.querySelector('.avatar-image') as HTMLImageElement;

if (avatarImage) {
avatarImage.src = this.app.vault.adapter.getResourcePath(imagePath);
} else {
// Create a new image element if it doesn't exist
const newAvatarImage = profileContainer.createEl('img', { cls: 'avatar-image' });
newAvatarImage.src = this.app.vault.adapter.getResourcePath(imagePath);
// Clear existing profile picture
const existingAvatarImage = profileContainer.querySelector('.avatar-image') as HTMLImageElement;
if (existingAvatarImage) {
existingAvatarImage.remove();
}

// Add new profile picture if path is provided
const imagePath = this.mediator.getSettingString('avatarPicture');
if (imagePath) {
const fullPath = this.app.vault.adapter.getResourcePath(imagePath);
const avatarImage = profileContainer.createEl('img', { cls: 'avatar-image' });
avatarImage.src = fullPath;
profileContainer.prepend(avatarImage); // Ensure it is added at the top
}
}
}


}

0 comments on commit 17b8002

Please sign in to comment.