forked from lucaspatenaude/ScoreSpot
added js and worked on Login feature(still in progress)
This commit is contained in:
@@ -2,7 +2,35 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
if (favoriteButton) {
|
||||
favoriteButton.addEventListener("click", function() {
|
||||
favoriteButton.src = "/img/club-page/favorited.png";
|
||||
if (favoriteButton.src.includes("/favorited.png")) {
|
||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||
} else {
|
||||
favoriteButton.src = "/img/club-page/favorited.png";
|
||||
addFavoriteTeam(1, 65, 'Manchester City FC', 'https://crests.football-data.org/65.png');
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
async function addFavoriteTeam(userID, teamID, teamName, teamLogo) {
|
||||
try {
|
||||
const response = await fetch('/courses/add', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userID: userID,
|
||||
teamID: teamID,
|
||||
teamName: teamName,
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user