Skip to content

Commit

Permalink
feat(app): limit number of leagues
Browse files Browse the repository at this point in the history
  • Loading branch information
imollov committed Oct 25, 2023
1 parent 8de0127 commit 82527fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/config/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const currentGameStatuses = ['NS', ...liveGameStatuses]

export const currentSeason = new Date().getFullYear()

export const leaguesCountLimit = 5

export const winnerToResult = {
[Winner.Home]: 1,
[Winner.Away]: 2,
Expand Down
8 changes: 6 additions & 2 deletions app/src/lib/fetch-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import 'server-only'

import { cache } from 'react'
import { add, getUnixTime } from 'date-fns'
import { currentGameStatuses, currentSeason } from '@/config/api'
import {
currentGameStatuses,
currentSeason,
leaguesCountLimit,
} from '@/config/api'
import { Sport, Game, League, LeagueResponse } from '@/types'

export const fetchCurrentGames = async (sport: Sport, leagueId: number) => {
Expand Down Expand Up @@ -118,7 +122,7 @@ export const fetchCurrentLeagues = async (sport: Sport) => {
const currentLeagues = allLeagues.filter((league: LeagueResponse) =>
league.seasons.some((season) => season.current === true),
)
return currentLeagues
return currentLeagues.reverse().slice(0, leaguesCountLimit)
}

export const fetchLeagueDetails = async (sport: Sport, leagueId: number) => {
Expand Down

0 comments on commit 82527fe

Please sign in to comment.