addFavorite team is working, button and remove will be finished tonight

This commit is contained in:
Vishal Vunnam
2024-04-21 14:11:35 -06:00
parent ac19be3cd9
commit 75d9560293
5 changed files with 87 additions and 85 deletions

View File

@@ -1,23 +1,34 @@
document.addEventListener("DOMContentLoaded", function() {
console.log(clubData.club.club_ID);
var favoriteButton = document.getElementById("club-favorite-button");
if (favoriteButton) {
favoriteButton.addEventListener("click", function() {
var userID = document.getElementById("userID").value;
var teamID = document.getElementById("teamID").value;
var teamName = document.getElementById("teamName").value;
var teamLogo = document.getElementById("teamLogo").value;
if (favoriteButton.src.includes("/favorited.png")) {
favoriteButton.src = "/img/club-page/unfavorited.png";
removeFavoriteTeam(1, 3);
removeFavoriteTeam(userID, teamID)
.then(() => {
favoriteButton.src = "/img/club-page/unfavorited.png";
})
.catch(error => {
console.error('Error removing favorite team:', error);
});
} else {
console.log("kjhdsgkjh");
favoriteButton.src = "/img/club-page/favorited.png";
addFavoriteTeam(1, 3, 'Manchester City FC', 'https://crests.football-data.org/65.png');
addFavoriteTeam(userID, teamID, teamName, teamLogo)
.then(() => {
favoriteButton.src = "/img/club-page/favorited.png";
})
.catch(error => {
console.error('Error adding favorite team:', error);
});
}
});
}
});
async function addFavoriteTeam(userID, teamID, teamName, teamLogo) {
});
async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
try {
console.log("yesss")
const response = await fetch('/favteam/add', {
method: 'POST',
headers: {
@@ -30,12 +41,15 @@ async function addFavoriteTeam(userID, teamID, teamName, teamLogo) {
teamLogo: teamLogo
})
});
if (!response.ok) {
throw new Error('Failed to add favorite team');
}
console.log('New favorite team added successfully.');
} catch (error) {
console.error('Error adding favorite team:', error);
}
}
async function removeFavoriteTeam(userID, teamID) {