Skip to content

Commit 5595e34

Browse files
committed
Worked on user-images
1 parent eb42729 commit 5595e34

File tree

3 files changed

+125
-16
lines changed

3 files changed

+125
-16
lines changed

scripts/dashboard.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const displayDashboard = async (recipes) => {
395395
// Function to fetch data from the API
396396
async function fetchData(key = 0) {
397397
const JWTAccessToken = sessionStorage.getItem('accessToken');
398-
// let apiUrl = 'https://recipiebeckend.azurewebsites.net/recipes/home';
398+
let apiUrl = 'https://recipiebeckend.azurewebsites.net/recipes/home';
399399
if (key !== undefined) {
400400
apiUrl += `?key=${key}`;
401401
}
@@ -805,16 +805,39 @@ function updateUserProfileLink(userPhotoUrl, userName) {
805805
}
806806

807807

808+
// function initUserProfileUpdate() {
809+
// function handleError(error) {
810+
// console.error('Error fetching user data:', error);
811+
// }
812+
813+
// fetchUserData()
814+
// .then(data => {
815+
// const userPhotoUrl = data.userPhoto;
816+
// const userName = `${data.name} ${data.lastName}`;
817+
// updateUserProfileLink(userPhotoUrl, userName);
818+
// })
819+
// .catch(handleError);
820+
// }
821+
822+
function insertUsername(username) {
823+
const h2Element = document.querySelector('article h2');
824+
if (h2Element) {
825+
h2Element.textContent = `Hello, ${username}`;
826+
}
827+
}
828+
808829
function initUserProfileUpdate() {
809830
function handleError(error) {
810831
console.error('Error fetching user data:', error);
811832
}
812-
813833
fetchUserData()
814834
.then(data => {
815835
const userPhotoUrl = data.userPhoto;
816836
const userName = `${data.name} ${data.lastName}`;
837+
const username = data.username; // Get the username from the response
838+
817839
updateUserProfileLink(userPhotoUrl, userName);
840+
insertUsername(username); // Insert the username into the <h2> tag
818841
})
819842
.catch(handleError);
820843
}

scripts/userDashboard.js

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,13 @@ userInfoDiv.classList.add('user-info');
338338
// User Image
339339
const userImgDiv = document.createElement('ion-icon');
340340
userImgDiv.classList.add('user-img');
341-
userImgDiv.setAttribute('name', 'person-circle-outline');
341+
if(recipe.userPhotoPath == null){
342+
userImgDiv.setAttribute('name', 'person-circle-outline');
343+
}else{
344+
userImgDiv.setAttribute('name', recipe.userPhotoPath);
345+
}
346+
// userInfoDiv.appendChild(userImgDiv)
347+
// userImgDiv.setAttribute('name', 'person-circle-outline');
342348
userInfoDiv.appendChild(userImgDiv);
343349

344350
// Username with link
@@ -735,9 +741,9 @@ async function fetchData(key = 0) {
735741
const JWTAccessToken = sessionStorage.getItem('accessToken');
736742
let apiUrl = 'https://recipiebeckend.azurewebsites.net/recipesUser/home-user-dashboard';
737743
// const apiUrl = 'https://run.mocky.io/v3/f162c031-dcc1-4794-bd22-e0b52a55a61d';
738-
// if (key !== undefined) {
739-
// apiUrl += `?key=${key}`;
740-
// }
744+
if (key !== undefined) {
745+
apiUrl += `?key=${key}`;
746+
}
741747

742748
const headers = {
743749
'Content-Type': 'application/json',
@@ -930,4 +936,83 @@ function reportRecipe(userRecipeId, reportCause, extraNotes) {
930936
console.error('Response status:', error.response.status);
931937
console.error('Response body:', error.response.body);
932938
});
933-
}
939+
}
940+
941+
// function fetchUserProfileData() {
942+
// const apiUrl = 'https://recipiebeckend.azurewebsites.net/user/user-profile-info'; // Replace this URL with your actual API endpoint
943+
944+
// const JWTAccessToken = sessionStorage.getItem('accessToken');
945+
946+
// const headers = {
947+
// 'Content-Type': 'application/json',
948+
// 'Authorization': JWTAccessToken,
949+
// };
950+
951+
// return fetch(apiUrl, { // Return the fetch promise
952+
// method: 'GET',
953+
// headers: headers,
954+
// })
955+
// .then(response => {
956+
// if (!response.ok) {
957+
// throw new Error(`Network response was not ok (status: ${response.status})`);
958+
// }
959+
// return response.json(); // Assuming the response is JSON
960+
// });
961+
// }
962+
963+
// function updateUserIcon(userPhotoUrl) {
964+
// const userImgElements = document.getElementsByClassName('user-img');
965+
// if (userImgElements.length > 0) {
966+
// const userImgDiv = userImgElements[0]; // Access the first element with the class 'user-img'
967+
968+
// // Create a new img element
969+
// const imgElement = document.createElement('img');
970+
// imgElement.setAttribute('src', userPhotoUrl);
971+
// imgElement.classList.add('profile-photo');
972+
973+
// // Replace the ion-icon element with the new img element
974+
// userImgDiv.replaceWith(imgElement);
975+
// }
976+
// }
977+
978+
// // Fetch user data
979+
// function fetchUserData() {
980+
// const apiUrl = 'https://recipiebeckend.azurewebsites.net/user/user-profile-info'; // Replace this URL with your actual API endpoint
981+
982+
// const JWTAccessToken = sessionStorage.getItem('accessToken');
983+
984+
// const headers = {
985+
// 'Content-Type': 'application/json',
986+
// 'Authorization': JWTAccessToken,
987+
// };
988+
989+
// return fetch(apiUrl, { // Return the fetch promise
990+
// method: 'GET',
991+
// headers: headers,
992+
// })
993+
// .then(response => {
994+
// if (!response.ok) {
995+
// throw new Error(`Network response was not ok (status: ${response.status})`);
996+
// }
997+
// return response.json(); // Assuming the response is JSON
998+
// });
999+
// }
1000+
1001+
// // Handle errors
1002+
// function handleError(error) {
1003+
// console.error('Error fetching user data:', error);
1004+
// }
1005+
1006+
// // Initialize the user icon update process
1007+
// function initUserIconUpdate() {
1008+
// fetchUserData()
1009+
// .then(data => {
1010+
// const userPhotoUrl = data.userPhoto;
1011+
// console.log('User Photo URL:', userPhotoUrl);
1012+
// updateUserIcon(userPhotoUrl);
1013+
// })
1014+
// .catch(handleError);
1015+
// }
1016+
1017+
// // Start the process
1018+
// initUserIconUpdate();

templates/dashboard.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,18 @@
193193
-webkit-background-clip: text;
194194
-webkit-text-fill-color: transparent;
195195
text-align: center;">
196+
<h2></h2>
196197
<h1
197198
style=" font-weight:bold;
198-
min-block-size: 100%;
199-
min-inline-size: 100%;
200-
box-sizing: border-box;
201-
display: grid;
202-
place-content: center;
203-
font-family: system-ui;
204-
font-size: min(200%, 5vmin); font-size: 6vmin;
205-
line-height: 1.1;">
206-
Explore Recipies</h1>
199+
min-block-size: 100%;
200+
min-inline-size: 100%;
201+
box-sizing: border-box;
202+
display: grid;
203+
place-content: center;
204+
font-family: system-ui;
205+
font-size: min(200%, 5vmin); font-size: 6vmin;
206+
line-height: 1.1;">
207+
Explore Recipies</h1>
207208
</article>
208209
</div>
209210
</div>

0 commit comments

Comments
 (0)