forked from lucaspatenaude/ScoreSpot
Merge branch 'main' of https://github.com/LucasPatenaude/ScoreSpot
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// create-league-routes.js
|
||||
|
||||
const express = require('express');
|
||||
const exphbs = require('express-handlebars');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.engine('hbs', exphbs({ extname: '.hbs' }));
|
||||
app.set('view engine', 'hbs');
|
||||
|
||||
// Define the redirectToLeaguePage function
|
||||
function redirectToLeaguePage(leagueName) {
|
||||
window.location.href = '/views/pages/league-page/league-page.hbs?leagueName=' + encodeURIComponent(leagueName);
|
||||
}
|
||||
|
||||
// Define a route to render the league-page.hbs template
|
||||
app.get('/league-page/:leagueName', (req, res) => {
|
||||
const leagueName = req.params.leagueName;
|
||||
// Here you might fetch data related to the clicked league
|
||||
// Pass the data to the template and render it
|
||||
res.render('league-page/league-page', { leagueName });
|
||||
});
|
||||
|
||||
// Export the app and redirectToLeaguePage function
|
||||
module.exports = { app, redirectToLeaguePage };
|
||||
@@ -0,0 +1,37 @@
|
||||
// navbar-sticky.js
|
||||
|
||||
// Function to add sticky behavior to the navbar
|
||||
function makeNavbarSticky() {
|
||||
// Get the navigation bar element
|
||||
var navbar = document.getElementById("navigation-bar-container");
|
||||
|
||||
// Get the initial offset of the navbar from the top of the page
|
||||
var navbarOffset = navbar.offsetTop;
|
||||
|
||||
// Function to add sticky behavior when scrolling
|
||||
function stickyNavbar() {
|
||||
// Check if the current scroll position is greater than or equal to the initial offset of the navbar
|
||||
if (window.pageYOffset >= navbarOffset) {
|
||||
// Add the 'fixed-top' class to make the navbar sticky
|
||||
navbar.classList.add("fixed-top");
|
||||
// Add padding to the body to prevent content from jumping when the navbar becomes sticky
|
||||
document.body.style.paddingTop = navbar.offsetHeight + "px";
|
||||
} else {
|
||||
// Remove the 'fixed-top' class to make the navbar non-sticky
|
||||
navbar.classList.remove("fixed-top");
|
||||
// Reset the padding of the body
|
||||
document.body.style.paddingTop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Call the stickyNavbar function when the page is scrolled
|
||||
window.onscroll = function() {
|
||||
stickyNavbar();
|
||||
};
|
||||
}
|
||||
|
||||
// Call the makeNavbarSticky function when the page loads
|
||||
window.onload = function() {
|
||||
makeNavbarSticky();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Convert finished matches to "FT"
|
||||
const convert_time = (req, res, next) => {
|
||||
try {
|
||||
// Access matches data from res.locals
|
||||
const matches = res.locals.matches;
|
||||
|
||||
// Loop through matches and convert "FINISHED" to "FT" for minute
|
||||
const convertedMatches = matches.map(match => {
|
||||
if (match.minute === "FINISHED") {
|
||||
match.minute = "FT";
|
||||
}
|
||||
else if (match.minute === "TIMED") {
|
||||
match.minute = "TM";
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
// Update res.locals with converted matches
|
||||
res.locals.matches = convertedMatches;
|
||||
|
||||
// Proceed to the next middleware/route handler
|
||||
next();
|
||||
} catch (error) {
|
||||
// If an error occurs, log it and proceed to the next middleware/route handler
|
||||
console.error('Error converting finished matches:', error);
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = convert_time;
|
||||
@@ -0,0 +1,66 @@
|
||||
const moment = require('moment');
|
||||
const axios = require('axios');
|
||||
|
||||
// Middleware function to fetch matches data
|
||||
const fetchMatchesData = async (req, res, next) => {
|
||||
try {
|
||||
const today = moment().format('YYYY-MM-DD'); // Get today's date in YYYY-MM-DD format
|
||||
|
||||
// Subtract one day to get yesterday's date
|
||||
const yesterdayUnformatted = moment().subtract(3, 'days');
|
||||
|
||||
// Format yesterday's date as YYYY-MM-DD
|
||||
const yesterday = yesterdayUnformatted.format('YYYY-MM-DD');
|
||||
|
||||
// Array of years to fetch matches data
|
||||
const league_ids = [2021]; /* Readd , 2002, 2014, 2019, 2015, 2013 */
|
||||
|
||||
// Array to store all matches data
|
||||
let allMatches = [];
|
||||
|
||||
// Loop through each year and fetch matches data
|
||||
for (const league_id of league_ids) {
|
||||
const response = await axios({
|
||||
url: `http://api.football-data.org/v4/competitions/2021/matches`, /* Resinsert ${league_id} for 2021 */
|
||||
method: 'GET',
|
||||
params: {
|
||||
dateFrom: yesterday, // Set dateFrom to yesterday's date
|
||||
dateTo: today, // Set dateTo to today's date
|
||||
},
|
||||
headers: {
|
||||
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here
|
||||
},
|
||||
});
|
||||
|
||||
// Extract relevant data from the API response
|
||||
const matches = response.data.matches.map(match => ({
|
||||
homeTeam: {
|
||||
name: match.homeTeam.tla,
|
||||
crest: match.homeTeam.crest,
|
||||
},
|
||||
awayTeam: {
|
||||
name: match.awayTeam.tla,
|
||||
crest: match.awayTeam.crest,
|
||||
},
|
||||
score: {
|
||||
homeScore: match.score.fullTime.home,
|
||||
awayScore: match.score.fullTime.away,
|
||||
},
|
||||
minute: match.status, // Set the minute of the game
|
||||
}));
|
||||
|
||||
// Concatenate matches data to allMatches array
|
||||
allMatches = allMatches.concat(matches);
|
||||
}
|
||||
|
||||
// Attach all matches data to res.locals
|
||||
res.locals.matches = allMatches;
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error('Error fetching matches data:', error);
|
||||
res.locals.matches = []; // Set an empty array if there's an error
|
||||
next(); // Call next middleware or route handler
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = fetchMatchesData;
|
||||
@@ -0,0 +1,8 @@
|
||||
$(document).ready(function() {
|
||||
// When #user is clicked
|
||||
$('#user').click(function() {
|
||||
// Toggle the visibility of the login container
|
||||
$('#login-container').toggle();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user