Skip to content

Commit

Permalink
Reimplemented 2025 functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
weakbox committed Jul 24, 2024
1 parent 8eefc2a commit d05f5a4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ <h1><strong>Stick & Puck Fantasy Dashboard</strong></h1>
<p>Click any matchup to see further info.</p>
</header>

<button id="select-2024-button" class="year-button">2024</button>
<button id="year-select-2024" class="year-button">2024</button>
<button id="year-select-2025" class="year-button">2025 (Ongoing)</button>

<div id="result" class="result-container"></div>

Expand Down
47 changes: 34 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@
// Code written and maintained by Connor McLeod

const result = document.getElementById("result");
const select2024Button = document.getElementById("select-2024-button");

const scheduleCache = {};
const year = 2024;

// Onclick declarations (can be function-atized):
setupYearSelectButton("year-select-2024", 2024);
setupYearSelectButton("year-select-2025", 2025);

select2024Button.year = 2024;
select2024Button.addEventListener("click", (event) =>
fetchScheduleData(year);

/* FUNCTION DECLARATIONS BELOW: */

function setupYearSelectButton(id, year)
{
const year = event.target.year;
fetchScheduleData(year);
});
button = document.getElementById(id);

if (!button)
{
console.error(`Could not find button with id "${id}".`);
return;
}

const defaultYear = 2024;
fetchScheduleData(defaultYear);
button.year = year;

button.addEventListener("click", (event) =>
{
clearMatchups();

year = event.target.year;
fetchScheduleData(year);
});
}

function clearMatchups()
{
result.innerHTML = "";
}

async function fetchScheduleData(year)
{
Expand All @@ -29,15 +50,15 @@ async function fetchScheduleData(year)
return;
}

// Fetch if data was not present in the cache:
try
{
const result = await fetch(url);
const data = await result.json();

scheduleCache[year] = data;

getMatchupPeriodLengths(data, year);
displayScheduleData(data);
console.log(scheduleCache);
}
catch (error)
{
Expand Down Expand Up @@ -143,8 +164,8 @@ function extractMatchupData(matchup, teams)
let { pointsByScoringPeriod: awayPointsByScoringPeriod } = awayStats;
let { pointsByScoringPeriod: homePointsByScoringPeriod } = homeStats;

awayPointsByScoringPeriod = pointsObjectToArray(populateMissingKeysInMatchupObject(awayPointsByScoringPeriod, matchupPeriodId, 2024));
homePointsByScoringPeriod = pointsObjectToArray(populateMissingKeysInMatchupObject(homePointsByScoringPeriod, matchupPeriodId, 2024));
awayPointsByScoringPeriod = pointsObjectToArray(populateMissingKeysInMatchupObject(awayPointsByScoringPeriod, matchupPeriodId, year));
homePointsByScoringPeriod = pointsObjectToArray(populateMissingKeysInMatchupObject(homePointsByScoringPeriod, matchupPeriodId, year));

const awayTeam = teams.find((team) => team['id'] === awayTeamId);
const homeTeam = teams.find((team) => team['id'] === homeTeamId);
Expand Down
1 change: 0 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
:root {
--main-bg-color: rgb(245, 254, 255);
--secondary-bg-color: rgb(205, 235, 255);
--championship-bg-color: rgb(255, 243, 178);
--background-hover-color: rgb(248, 248, 248);
}

Expand Down

0 comments on commit d05f5a4

Please sign in to comment.