Merge pull request #27 from LucasPatenaude/favorites-in-navigation-bar
Favorites in Navigation Bar Implemented
This commit is contained in:
@@ -303,6 +303,7 @@ app.post('/favteam/add', async (req, res, next) => {
|
|||||||
return res.status(500).json({ error: 'Error adding favorite team' });
|
return res.status(500).json({ error: 'Error adding favorite team' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/favteam/remove', async (req, res) => {
|
app.post('/favteam/remove', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { userID, teamID } = req.body;
|
const { userID, teamID } = req.body;
|
||||||
@@ -355,7 +356,6 @@ async function getFavoriteTeamsForUser(userId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
// <!-- Section 5 : Start Server-->
|
// <!-- Section 5 : Start Server-->
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
|||||||
@@ -16,3 +16,8 @@
|
|||||||
{
|
{
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#competition-logo {
|
||||||
|
width: 60px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
@@ -33,6 +33,27 @@
|
|||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#favorite-teams-container {
|
||||||
|
margin-right: 25px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 28px;
|
||||||
|
height: auto;
|
||||||
|
margin: 0 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
transition: width 0.3s ease; /* Adding transition for smooth effect */
|
||||||
|
}
|
||||||
|
|
||||||
|
img:hover {
|
||||||
|
width: 32px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#user {
|
#user {
|
||||||
width: 25px;
|
width: 25px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
overflow: hidden; /* Hide the overflowing skewed content */
|
overflow: hidden; /* Hide the overflowing skewed content */
|
||||||
transform: skewX(-20deg); /* Skew the banner to create a triangular side */
|
transform: skewX(-20deg); /* Skew the banner to create a triangular side */
|
||||||
transition: transform 0.3s ease, box-shadow 0.3s ease; /* Transition for smooth transformation and box-shadow */
|
transition: transform 0.3s ease, box-shadow 0.3s ease; /* Transition for smooth transformation and box-shadow */
|
||||||
cursor: pointer; /* Change cursor to pointer on hover */
|
|
||||||
|
|
||||||
transition: transform 0.4s ease; /* Add transition for smooth effect */
|
transition: transform 0.4s ease; /* Add transition for smooth effect */
|
||||||
}
|
}
|
||||||
@@ -61,11 +60,17 @@
|
|||||||
|
|
||||||
/* Container for each team in card's information */
|
/* Container for each team in card's information */
|
||||||
.team {
|
.team {
|
||||||
display: flex; /* Keeps all items in a row */
|
|
||||||
align-items: center; /* Center items vertically */
|
align-items: center; /* Center items vertically */
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.team a {
|
||||||
|
color: black;
|
||||||
|
display: flex;
|
||||||
|
text-decoration: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.team p {
|
.team p {
|
||||||
margin: 0; /* Remove default margin */
|
margin: 0; /* Remove default margin */
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
var teamLogo = document.getElementById("teamLogo").value;
|
var teamLogo = document.getElementById("teamLogo").value;
|
||||||
|
|
||||||
if (favoriteButton.src.includes("/favorited.png")) {
|
if (favoriteButton.src.includes("/favorited.png")) {
|
||||||
removeFavoriteTeam(userID, teamID)
|
removeFavoriteTeam(userID, teamID);
|
||||||
}
|
} else {
|
||||||
else {
|
addFavoriteTeam(userID, teamID, teamName, teamLogo);
|
||||||
addFavoriteTeam(userID, teamID, teamName, teamLogo)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -35,16 +34,19 @@ async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to add favorite team');
|
throw new Error('Failed to add favorite team');
|
||||||
}
|
}
|
||||||
//Changes button if favorite team is added//
|
|
||||||
|
if (response.status === 200) {
|
||||||
console.log('New favorite team added successfully.');
|
console.log('New favorite team added successfully.');
|
||||||
var favoriteButton = document.getElementById("club-favorite-button");
|
var favoriteButton = document.getElementById("club-favorite-button");
|
||||||
favoriteButton.src = "/img/club-page/favorited.png";
|
favoriteButton.src = "/img/club-page/favorited.png";
|
||||||
|
location.reload(); // Refresh the page
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding favorite team:', error);
|
console.error('Error adding favorite team:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async function removeFavoriteTeam(userID, teamID) {
|
async function removeFavoriteTeam(userID, teamID) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/favteam/remove', {
|
const response = await fetch('/favteam/remove', {
|
||||||
@@ -57,10 +59,13 @@ async function removeFavoriteTeam(userID, teamID) {
|
|||||||
teamID: teamID
|
teamID: teamID
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
console.log('Favorite team removed successfully.');
|
console.log('Favorite team removed successfully.');
|
||||||
//Change button source//
|
|
||||||
var favoriteButton = document.getElementById("club-favorite-button");
|
var favoriteButton = document.getElementById("club-favorite-button");
|
||||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||||
|
location.reload(); // Refresh the page
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error removing favorite team:', error);
|
console.error('Error removing favorite team:', error);
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ const fetchMatchesData = async (req, res, next) => {
|
|||||||
// Extract relevant data from the API response
|
// Extract relevant data from the API response
|
||||||
const matches = response.data.matches.map(match => ({
|
const matches = response.data.matches.map(match => ({
|
||||||
homeTeam: {
|
homeTeam: {
|
||||||
|
teamID: match.homeTeam.id,
|
||||||
name: match.homeTeam.tla,
|
name: match.homeTeam.tla,
|
||||||
crest: match.homeTeam.crest,
|
crest: match.homeTeam.crest,
|
||||||
},
|
},
|
||||||
awayTeam: {
|
awayTeam: {
|
||||||
|
teamID: match.awayTeam.id,
|
||||||
name: match.awayTeam.tla,
|
name: match.awayTeam.tla,
|
||||||
crest: match.awayTeam.crest,
|
crest: match.awayTeam.crest,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -81,11 +81,13 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#each club.runningCompetitions}}
|
{{#each club.runningCompetitions}}
|
||||||
<tr>
|
<tr>
|
||||||
|
<td><img id="competition-logo" src="{{emblem}}"></td>
|
||||||
<td>{{name}}</td>
|
<td>{{name}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -19,6 +19,6 @@
|
|||||||
|
|
||||||
<!-- Club Pages Scripts -->
|
<!-- Club Pages Scripts -->
|
||||||
<script src="/js/club-page/favorite-button.js"></script>
|
<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>
|
</footer>
|
||||||
@@ -41,6 +41,14 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="favorite-teams-container" class="logos-container">
|
||||||
|
{{#each fav_teams}}
|
||||||
|
<a href="/club/{{this.teamid}}">
|
||||||
|
<img id="teamlogo" src="{{this.teamlogo}}" alt="teamlogo">
|
||||||
|
</a>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="user" class="user-icon">
|
<div id="user" class="user-icon">
|
||||||
<img src="/img/navigation-bar/user.png" alt="Your Image" class="img-fluid">
|
<img src="/img/navigation-bar/user.png" alt="Your Image" class="img-fluid">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,15 +6,19 @@
|
|||||||
|
|
||||||
<!-- Team 1 Name with Score -->
|
<!-- Team 1 Name with Score -->
|
||||||
<div class="team">
|
<div class="team">
|
||||||
|
<a href="/club/{{homeTeam.teamID}}">
|
||||||
<img src="{{ homeTeam.crest }}" alt="{{ homeTeam.name }} Crest">
|
<img src="{{ homeTeam.crest }}" alt="{{ homeTeam.name }} Crest">
|
||||||
<p id="team-name">{{ homeTeam.name }}</p> <!-- {{team1.name}} -->
|
<p id="team-name">{{ homeTeam.name }}</p> <!-- {{team1.name}} -->
|
||||||
<p id="team-score">{{ score.homeScore }}</p>
|
<p id="team-score">{{ score.homeScore }}</p>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<!-- Team 2 Name with Score -->
|
<!-- Team 2 Name with Score -->
|
||||||
<div class="team">
|
<div class="team">
|
||||||
|
<a href="/club/{{awayTeam.teamID}}">
|
||||||
<img src="{{ awayTeam.crest }}" alt="{{ awayTeam.name }} Crest">
|
<img src="{{ awayTeam.crest }}" alt="{{ awayTeam.name }} Crest">
|
||||||
<p id="team-name">{{ awayTeam.name }}</p> <!-- {{team1.name}} -->
|
<p id="team-name">{{ awayTeam.name }}</p> <!-- {{team1.name}} -->
|
||||||
<p id="team-score">{{ score.awayScore }}</p>
|
<p id="team-score">{{ score.awayScore }}</p>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user