Extract favorite finding in playoffs to separate method

This commit is contained in:
Daniel Schädler 2025-03-19 09:17:34 +01:00
parent 7837b40d56
commit 7a0bbccc19
1 changed files with 11 additions and 6 deletions

View File

@ -53,12 +53,8 @@ export function FavoriteBar({teams}) {
setIsVisible(false); // Close the favorite menu
};
const scrollToFavorite = () => {
if (!favorite) {
return; // Exit if there is no favorite team selected
}
const matchesWithFavoriteParticipation = document.querySelectorAll(`[data-team-level-ids*='-${favorite.id}']`);
function findLowestPlayoffParticipation(favoriteId) {
const matchesWithFavoriteParticipation = document.querySelectorAll(`[data-team-level-ids*='-${favoriteId}']`);
let lowestMatch = null; // lowest means lowest stage number > latest game of the favorite
let lowestStageNum = Infinity;
@ -73,6 +69,15 @@ export function FavoriteBar({teams}) {
}
});
});
return lowestMatch;
}
const scrollToFavorite = () => {
if (!favorite) {
return; // Exit if there is no favorite team selected
}
const lowestMatch = findLowestPlayoffParticipation(favorite.id);
let scrollTo;
if (lowestMatch) {