@@ -338,7 +338,13 @@ userInfoDiv.classList.add('user-info');
338
338
// User Image
339
339
const userImgDiv = document . createElement ( 'ion-icon' ) ;
340
340
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');
342
348
userInfoDiv . appendChild ( userImgDiv ) ;
343
349
344
350
// Username with link
@@ -735,9 +741,9 @@ async function fetchData(key = 0) {
735
741
const JWTAccessToken = sessionStorage . getItem ( 'accessToken' ) ;
736
742
let apiUrl = 'https://recipiebeckend.azurewebsites.net/recipesUser/home-user-dashboard' ;
737
743
// 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
+ }
741
747
742
748
const headers = {
743
749
'Content-Type' : 'application/json' ,
@@ -930,4 +936,83 @@ function reportRecipe(userRecipeId, reportCause, extraNotes) {
930
936
console . error ( 'Response status:' , error . response . status ) ;
931
937
console . error ( 'Response body:' , error . response . body ) ;
932
938
} ) ;
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();
0 commit comments