Fix to favorites button code so page is refreshed each time it's clicked
This commit is contained in:
@@ -8,10 +8,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
var teamLogo = document.getElementById("teamLogo").value;
|
||||
|
||||
if (favoriteButton.src.includes("/favorited.png")) {
|
||||
removeFavoriteTeam(userID, teamID)
|
||||
}
|
||||
else {
|
||||
addFavoriteTeam(userID, teamID, teamName, teamLogo)
|
||||
removeFavoriteTeam(userID, teamID);
|
||||
} else {
|
||||
addFavoriteTeam(userID, teamID, teamName, teamLogo);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -35,16 +34,19 @@ async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to add favorite team');
|
||||
}
|
||||
//Changes button if favorite team is added//
|
||||
console.log('New favorite team added successfully.');
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
favoriteButton.src = "/img/club-page/favorited.png";
|
||||
|
||||
if (response.status === 200) {
|
||||
console.log('New favorite team added successfully.');
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
favoriteButton.src = "/img/club-page/favorited.png";
|
||||
location.reload(); // Refresh the page
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error adding favorite team:', error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function removeFavoriteTeam(userID, teamID) {
|
||||
try {
|
||||
const response = await fetch('/favteam/remove', {
|
||||
@@ -57,10 +59,13 @@ async function removeFavoriteTeam(userID, teamID) {
|
||||
teamID: teamID
|
||||
})
|
||||
});
|
||||
console.log('Favorite team removed successfully.');
|
||||
//Change button source//
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||
|
||||
if (response.status === 200) {
|
||||
console.log('Favorite team removed successfully.');
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||
location.reload(); // Refresh the page
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error removing favorite team:', error);
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
|
||||
<!-- Club Pages Scripts -->
|
||||
<script src="/js/club-page/favorite-button.js"></script>
|
||||
<script src="/js/club-page/player-card-hover.js"></script>
|
||||
<script src="/js/club-page/refresh-for-favorite.js"></script>
|
||||
|
||||
</footer>
|
||||
Reference in New Issue
Block a user