-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile.js
56 lines (45 loc) · 1.66 KB
/
profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Handling profile buttons
*/
document.addEventListener('DOMContentLoaded', () => {
const avatarUpload = document.getElementById('avatar-upload');
const bioInput = document.getElementById('bio-input');
const profileForm = document.getElementById('profile-form');
loadUserProfile();
// Handle the profile form submission
profileForm.addEventListener('submit', (event) => {
event.preventDefault();
saveProfileChanges();
});
// ...
function saveProfileChanges() {
const avatarFile = avatarUpload.files[0];
const bioText = bioInput.value;
if (avatarFile) {
const reader = new FileReader();
reader.onload = (event) => {
const avatarImg = document.getElementById('avatar');
avatarImg.src = event.target.result;
};
reader.readAsDataURL(avatarFile);
}
if (bioText) {
const bioElement = document.getElementById('bio');
bioElement.textContent = bioText;
}
}
});
function loadUserProfile() {
const userData = JSON.parse(localStorage.getItem('user'));
const userProfile = {
...userData,
avatarUrl: 'default-avatar.png',
};
updateProfilePage(userProfile);
}
function updateProfilePage(userProfile) {
document.getElementById('user-name').textContent = userProfile.username;
document.getElementById('user-email').textContent = userProfile.email;
document.getElementById('user-joined').textContent = userProfile.joined;
document.getElementById('user-avatar').src = userProfile.avatarUrl;
}