Skip to content

Commit

Permalink
Profil-icon update
Browse files Browse the repository at this point in the history
  • Loading branch information
Noxtrah committed May 26, 2024
1 parent 7d1e272 commit eb42729
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 34 deletions.
67 changes: 66 additions & 1 deletion scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,13 @@ document.addEventListener('DOMContentLoaded', function () {
if (JWTAccessToken != null) {
// Change the text of the anchor element
logInLink.textContent = "Log-Out";
logInLink.addEventListener('click', function(event) {
// Prevent default action
event.preventDefault();
sessionStorage.removeItem('accessToken');
sessionStorage.removeItem('refreshToken');
window.location.href = 'logIn.html';
});
}

fetchData(0)
Expand Down Expand Up @@ -755,4 +762,62 @@ async function getMaxPage() {
console.error('Error fetching maximum page:', error);
return null; // Return null in case of error
}
}
}

// Function to fetch user data
function fetchUserData() {
const apiUrl = 'https://recipiebeckend.azurewebsites.net/user/user-profile-info'; // Replace this URL with your actual API endpoint

const JWTAccessToken = sessionStorage.getItem('accessToken');

const headers = {
'Content-Type': 'application/json',
'Authorization': JWTAccessToken,
};

return fetch(apiUrl, { // Return the fetch promise
method: 'GET',
headers: headers,
})
.then(response => {
if (!response.ok) {
throw new Error(`Network response was not ok (status: ${response.status})`);
}
return response.json(); // Assuming the response is JSON
});
}


function updateUserProfileLink(userPhotoUrl, userName) {
const iconElements = document.getElementsByClassName('profile-icon');
if (iconElements.length > 0) {
const iconElement = iconElements[0]; // Get the first element in the collection

// Create a new img element
const imgElement = document.createElement('img');
imgElement.setAttribute('src', userPhotoUrl);
imgElement.setAttribute('alt', userName);
imgElement.classList.add('profile-photo');

// Replace the ion-icon element with the new img element
iconElement.replaceWith(imgElement);
}
}


function initUserProfileUpdate() {
function handleError(error) {
console.error('Error fetching user data:', error);
}

fetchUserData()
.then(data => {
const userPhotoUrl = data.userPhoto;
const userName = `${data.name} ${data.lastName}`;
updateUserProfileLink(userPhotoUrl, userName);
})
.catch(handleError);
}

initUserProfileUpdate();

40 changes: 7 additions & 33 deletions scripts/userDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ const createRecipeElement = async (recipe) => {
} else {
star.textContent = '☆';
}
star.onmouseover = () => hoverStar(star);
const clickHandler = () => setRating(i, starContainer, recipe);
star.onclick = clickHandler;
starContainer.appendChild(star);
}
ratingDiv.appendChild(starContainer);
Expand Down Expand Up @@ -731,9 +734,10 @@ const displayDashboard = async (recipes) => {
async function fetchData(key = 0) {
const JWTAccessToken = sessionStorage.getItem('accessToken');
let apiUrl = 'https://recipiebeckend.azurewebsites.net/recipesUser/home-user-dashboard';
if (key !== undefined) {
apiUrl += `?key=${key}`;
}
// const apiUrl = 'https://run.mocky.io/v3/f162c031-dcc1-4794-bd22-e0b52a55a61d';
// if (key !== undefined) {
// apiUrl += `?key=${key}`;
// }

const headers = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -874,36 +878,6 @@ window.onload = function () {
setupBackButton(); // Call setupBackButton after generateUserRecipeBoxes
};


// async function displayPage(startPage) {
// const maxPage = await getMaxPage();
// if (typeof startPage !== 'number' || startPage < 0 || startPage >= maxPage) {
// console.error(`Invalid startPage value: ${startPage}`);
// startPage = 0; // Set a default valid startPage value
// }

// if (typeof maxPage !== 'number' || maxPage <= 0) {
// console.error(`Invalid maxPagePages value: ${maxPage}`);
// maxPage = 1; // Set a default valid maxPagePages value
// }

// $('#pagination-demo').twbsPagination('destroy');
// $('#pagination-demo').twbsPagination({
// startPage: startPage + 1, // twbsPagination uses 1-based index
// totalPages: maxPage,
// visiblePages: 5,
// next: 'Next',
// prev: 'Prev',
// onPageClick: function (event, page) {
// fetchData(page - 1);
// console.log("Page =", page - 1);
// }
// });
// }

// displayPage(0, 2);


async function getMaxPage() {
const apiUrl = 'https://recipiebeckend.azurewebsites.net/recipes/get-max-page'; // Replace this URL with your actual API endpoint

Expand Down
8 changes: 8 additions & 0 deletions styles/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,14 @@ input[type="radio"],
margin-left: 42px;
}

.profile-photo{
width: 50px;
height: 50px;
border-radius: 50%;
margin-left: 42px;
margin-right: 2px;
}

.profile-dropdown {
position: relative;
display: inline-block;
Expand Down
1 change: 1 addition & 0 deletions styles/userDashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ header {
/* Kalp simgesini büyütmek için */
font-size: 20px; /* İstenilen boyuta göre */
color: rgb(33, 31, 34);
/* cursor: pointer; */
}

.recipe p {
Expand Down

0 comments on commit eb42729

Please sign in to comment.