forked from lucaspatenaude/ScoreSpot
login feature is fully complete, testing is required, favorite teams database is fully functioning
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
console.log(clubData.club.club_ID);
|
||||
var favoriteButton = document.getElementById("club-favorite-button");
|
||||
if (favoriteButton) {
|
||||
favoriteButton.addEventListener("click", function() {
|
||||
if (favoriteButton.src.includes("/favorited.png")) {
|
||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||
removeFavoriteTeam(1, 3);
|
||||
} else {
|
||||
console.log("kjhdsgkjh");
|
||||
favoriteButton.src = "/img/club-page/favorited.png";
|
||||
addFavoriteTeam(1, 65, 'Manchester City FC', 'https://crests.football-data.org/65.png');
|
||||
addFavoriteTeam(1, 3, 'Manchester City FC', 'https://crests.football-data.org/65.png');
|
||||
|
||||
}
|
||||
});
|
||||
@@ -14,7 +17,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
});
|
||||
async function addFavoriteTeam(userID, teamID, teamName, teamLogo) {
|
||||
try {
|
||||
const response = await fetch('/courses/add', {
|
||||
console.log("yesss")
|
||||
const response = await fetch('/favteam/add', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -33,4 +37,24 @@ async function addFavoriteTeam(userID, teamID, teamName, teamLogo) {
|
||||
} catch (error) {
|
||||
console.error('Error adding favorite team:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
async function removeFavoriteTeam(userID, teamID) {
|
||||
try {
|
||||
const response = await fetch('/favteam/remove', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userID: userID,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user