You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/TournamentList/index.tsx

71 lines
1.9 KiB

import { useRouteMatch } from 'react-router-dom'
import type { Match } from 'features/Matches'
import { MatchCard } from 'features/MatchCard'
import type { TournamentType } from 'requests/getMatches/types'
import { PAGES } from 'config/pages'
import { isMobileDevice } from 'config/userAgent'
import { TournamentMobile } from './components/TournamentMobile'
import { useTournaments } from './hooks'
import { CollapseTournament } from './components/CollapseTournament'
type TournamentTypeProps = {
matches: Array<Match>,
}
export type TournamentProps = {
tournament: TournamentType & {
countryId: number,
isFavorite: boolean,
live: boolean,
sportType: number,
},
tournamentMatches: Array<Match>,
}
export type TournamentListProps = {
[key: number]: TournamentProps,
}
export const TournamentList = ({ matches }: TournamentTypeProps) => {
const { tournaments, tournamentSort } = useTournaments(matches)
const isHomePage = useRouteMatch(PAGES.home)?.isExact
switch (true) {
case isMobileDevice && isHomePage:
return (
<>
{tournamentSort?.map((tournament) => (
<TournamentMobile
key={tournament.id}
tournament={tournaments[tournament.id].tournament}
tournamentMatches={tournaments[tournament.id].tournamentMatches}
/>
))}
</>
)
case isHomePage && matches.length >= 12:
return (
<>
{tournamentSort?.map((tournament) => (
<CollapseTournament
key={tournament.id}
tournament={tournaments[tournament.id].tournament}
tournamentMatches={tournaments[tournament.id].tournamentMatches}
/>
))}
</>
)
default:
return (
<>
{matches.map((match) => (
<MatchCard key={match.id} match={match} />
))}
</>
)
}
}