Skip to content

Commit

Permalink
eunice_homework4
Browse files Browse the repository at this point in the history
  • Loading branch information
eunice-shobowale authored Nov 1, 2024
1 parent 0cd8888 commit 74a15ed
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions public/scripts/club.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
// Function to handle the profile picture change
function changeProfilePicture(event) {
const reader = new FileReader();
const file = event.target.files[0];

reader.onload = function () {
const profilePic = document.getElementById("club-profile-pic");
profilePic.src = reader.result;

// Save the image data to localStorage
localStorage.setItem("profilePicture", reader.result);
};

if (file) {
reader.readAsDataURL(file);
}
class ProfilePictureChange {
loadProfilePicture() {
const savedProfilePic = localStorage.getItem("profilePicture");
if (savedProfilePic) {
const profilePic = document.getElementById("club-profile-pic");
profilePic.src = savedProfilePic;
}
}

changeProfilePicture(event) {
const reader = new FileReader();
const file = event.target.files[0];

reader.onload = function () {
const profilePic = document.getElementById("club-profile-pic");
profilePic.src = reader.result;

// Image data is saved to the localstorage
localStorage.setItem("profilePicture", reader.result);
};

if (file) {
reader.readAsDataURL(file);
}
}
}

// Function to load the profile picture from localStorage on page load
function loadProfilePicture() {
const savedProfilePic = localStorage.getItem("profilePicture");
if (savedProfilePic) {
document.getElementById("club-profile-pic").src = savedProfilePic;
}
class ChangeProfileAdapter {
constructor(profilePictureChange) {
this.profilePictureChange = profilePictureChange;
}

load() {
this.profilePictureChange.loadProfilePicture();
}


update(event) {
this.profilePictureChange.changeProfilePicture(event);
}
}

// Load the profile picture when the page is loaded
window.onload = loadProfilePicture;
const profilePictureChange = new ProfilePictureChange();
const changeProfileAdapter = new ChangeProfileAdapter(profilePictureChange);

window.onload = function() {
changeProfileAdapter.load(); // Load profile picture when the page loads
};

0 comments on commit 74a15ed

Please sign in to comment.