|
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { useEffect, useMemo } from 'react' |
|
|
|
|
import { useMemo } from 'react' |
|
|
|
|
|
|
|
|
|
import orderBy from 'lodash/orderBy' |
|
|
|
|
|
|
|
|
|
@ -19,10 +19,8 @@ interface TournamentsSortProps { |
|
|
|
|
|
|
|
|
|
export const useTournaments = (matches: Array<Match>) => { |
|
|
|
|
const { |
|
|
|
|
selectedDate, |
|
|
|
|
selectedLeague, |
|
|
|
|
selectedSport, |
|
|
|
|
setSportIds, |
|
|
|
|
} = useHeaderFiltersStore() |
|
|
|
|
const { isInFavorites } = useUserFavoritesStore() |
|
|
|
|
|
|
|
|
|
@ -43,7 +41,6 @@ export const useTournaments = (matches: Array<Match>) => { |
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
const tournamentSort: Array<TournamentsSortProps> = [] |
|
|
|
|
const sportIds = new Set<number>([]) |
|
|
|
|
|
|
|
|
|
const tournaments = matches.reduce((acc: TournamentListProps, match: Match) => { |
|
|
|
|
if (matches.length === 0) return {} |
|
|
|
|
@ -76,7 +73,6 @@ export const useTournaments = (matches: Array<Match>) => { |
|
|
|
|
isLive: match.live, |
|
|
|
|
isSuperTournament: Boolean(match.tournament.is_super_tournament), |
|
|
|
|
}) |
|
|
|
|
sportIds.add(match.sportType) |
|
|
|
|
} else if (compareSport(match, selectedSport) && compareLeague(match.tournament.id)) { |
|
|
|
|
acc[match.tournament.id] = { |
|
|
|
|
...acc[match.tournament.id], |
|
|
|
|
@ -98,11 +94,6 @@ export const useTournaments = (matches: Array<Match>) => { |
|
|
|
|
['desc', 'desc', 'desc'], |
|
|
|
|
), [tournamentSort]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
sportIds && setSportIds(sportIds) |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [selectedDate, matches]) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
tournamentSort: tournamentsSorted, |
|
|
|
|
tournaments, |
|
|
|
|
|