finished addfavorite team, page recognizes when team is favorited or not. remove favorite team currently not working

This commit is contained in:
Vishal Vunnam
2024-04-21 23:03:51 -06:00
parent 75d9560293
commit eb779f652a
5 changed files with 35 additions and 37 deletions

View File

@@ -9,12 +9,15 @@ document.addEventListener("DOMContentLoaded", function() {
if (favoriteButton.src.includes("/favorited.png")) {
removeFavoriteTeam(userID, teamID)
.then(() => {
.then((rmv_status) => {
console.log(rmv_status);
if (rmv_status === 200) {
favoriteButton.src = "/img/club-page/unfavorited.png";
})
.catch(error => {
}
})
.catch(error => {
console.error('Error removing favorite team:', error);
});
});
} else {
addFavoriteTeam(userID, teamID, teamName, teamLogo)
.then(() => {
@@ -26,7 +29,8 @@ document.addEventListener("DOMContentLoaded", function() {
}
});
}
});
});
async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
try {
const response = await fetch('/favteam/add', {
@@ -64,9 +68,6 @@ async function removeFavoriteTeam(userID, teamID) {
teamID: teamID
})
});
if (!response.ok) {
throw new Error('Failed to remove favorite team');
}
console.log('Favorite team removed successfully.');
} catch (error) {
console.error('Error removing favorite team:', error);