added js and worked on Login feature(still in progress)

This commit is contained in:
Vishal Vunnam
2024-04-17 18:06:45 -06:00
parent 77b990cd1e
commit 6faec75ae2
15 changed files with 99 additions and 23 deletions

View File

@@ -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);
}
}

View File

@@ -37,4 +37,5 @@ document.addEventListener("DOMContentLoaded", function() {
selectElement.add(option);
}
});

View File

@@ -63,7 +63,6 @@ const fetchClubsData = async (req, res, next) => {
staff: clubData.staff,
lastUpdated: clubData.lastUpdated
};
next();
} catch (error) {
console.error('Error fetching clubs data:', error);

View File

@@ -17,6 +17,8 @@ const fetchLeaguesData = async (req, res, next) => {
const leagueData = response.data;
// Attach the data to res.locals
res.locals.username = req.session.user.username;
console.log(req.session.user)
res.locals.league = {
area: {
league_flag: leagueData.area.flag,
@@ -39,7 +41,7 @@ const fetchLeaguesData = async (req, res, next) => {
draws: team.draw,
goal_difference: team.goalDifference,
points: team.points
}))
})),
};
next();
} catch (error) {

View File

@@ -11,7 +11,7 @@ module.exports = function generateClubRoutes(app) {
const clubID = req.params.clubID;
// Render the league page template using Handlebars
res.render('pages/club-page', { clubID: clubID });
res.render('pages/club-page', { clubID: clubID, user:user });
});
};

View File

@@ -8,10 +8,11 @@ module.exports = function generateLeagueRoutes(app) {
// Define a route to handle requests to "/league/:leagueName"
app.get('/league/:leagueID', (req, res) => {
// Extract the league name from the URL parameters
console.log("jskjfhskjhdfkjh")
const leagueID = req.params.leagueID;
const user = req.session.user;
// Render the league page template using Handlebars
res.render('pages/leagues-page', { leagueID: leagueID });
res.render('pages/leagues-page', { leagueID: leagueID, user: user});
});
};

View File

@@ -9,7 +9,7 @@ const fetchTeamNames = async (selectedLeague) => {
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3',
},
});
const teams = response.data.teams.map(team => team.name);
return teams;
} catch (error) {