Ott 339 matches request (#103)
* refactor(#314): moved matches state from header filters store to specific profiles * refactor(#314): changed Mathes type import path Co-authored-by: mirlan.maksitaliev <mirlan.maksitaliev@instatsport.com>keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
01124ce8ca
commit
c2c5e9ad0c
@ -0,0 +1,39 @@ |
|||||||
|
import { useEffect, useState } from 'react' |
||||||
|
|
||||||
|
import type { Matches } from 'requests' |
||||||
|
import { getMatches } from 'requests' |
||||||
|
|
||||||
|
import { useHeaderFiltersStore } from 'features/HeaderFilters' |
||||||
|
|
||||||
|
export const useHomePage = () => { |
||||||
|
const { |
||||||
|
selectedDateFormatted, |
||||||
|
selectedMatchStatus, |
||||||
|
selectedSportTypeId, |
||||||
|
selectedTournamentId, |
||||||
|
} = useHeaderFiltersStore() |
||||||
|
|
||||||
|
const [matches, setMatches] = useState<Matches>({ |
||||||
|
broadcast: [], |
||||||
|
features: [], |
||||||
|
highlights: [], |
||||||
|
isVideoSections: false, |
||||||
|
}) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
getMatches({ |
||||||
|
date: selectedDateFormatted, |
||||||
|
matchStatus: selectedMatchStatus, |
||||||
|
sportType: selectedSportTypeId, |
||||||
|
teamId: null, |
||||||
|
tournamentId: selectedTournamentId, |
||||||
|
}).then(setMatches) |
||||||
|
}, [ |
||||||
|
selectedDateFormatted, |
||||||
|
selectedMatchStatus, |
||||||
|
selectedSportTypeId, |
||||||
|
selectedTournamentId, |
||||||
|
]) |
||||||
|
|
||||||
|
return { matches } |
||||||
|
} |
||||||
@ -1,10 +1,15 @@ |
|||||||
import React from 'react' |
import React from 'react' |
||||||
|
|
||||||
import { Matches } from 'features/Matches' |
import { Matches } from 'features/Matches' |
||||||
|
|
||||||
|
import { useHomePage } from './hooks' |
||||||
import { Content } from './styled' |
import { Content } from './styled' |
||||||
|
|
||||||
export const HomePage = () => ( |
export const HomePage = () => { |
||||||
<Content> |
const { matches } = useHomePage() |
||||||
<Matches /> |
return ( |
||||||
</Content> |
<Content> |
||||||
) |
<Matches matches={matches} /> |
||||||
|
</Content> |
||||||
|
) |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,83 @@ |
|||||||
|
import { useMemo } from 'react' |
||||||
|
|
||||||
|
import map from 'lodash/map' |
||||||
|
import flatten from 'lodash/flatten' |
||||||
|
import pipe from 'lodash/fp/pipe' |
||||||
|
import fpMap from 'lodash/fp/map' |
||||||
|
import fpOrderBy from 'lodash/fp/orderBy' |
||||||
|
|
||||||
|
import type { Matches, Content } from 'requests' |
||||||
|
import { SPORT_NAMES } from 'config' |
||||||
|
import { getProfileLogo } from 'helpers' |
||||||
|
import { useLexicsStore } from 'features/LexicsStore' |
||||||
|
|
||||||
|
export type Props = { |
||||||
|
matches: Matches, |
||||||
|
} |
||||||
|
|
||||||
|
type Name = 'name_rus' | 'name_eng' |
||||||
|
|
||||||
|
export type Match = { |
||||||
|
date: string, |
||||||
|
id: number, |
||||||
|
preview: string, |
||||||
|
sportName: string, |
||||||
|
sportType: number, |
||||||
|
streamStatus: number, |
||||||
|
team1Logo: string, |
||||||
|
team1Name: string, |
||||||
|
team1Score: number, |
||||||
|
team2Logo: string, |
||||||
|
team2Name: string, |
||||||
|
team2Score: number, |
||||||
|
tournamentName: string, |
||||||
|
} |
||||||
|
|
||||||
|
const prepareMatches = (content: Array<Content>, suffix: string) => pipe( |
||||||
|
fpMap<Content, Array<Match>>(({ |
||||||
|
matches: matchesList, |
||||||
|
sport, |
||||||
|
...rest |
||||||
|
}) => map(matchesList, ({ |
||||||
|
date, |
||||||
|
id, |
||||||
|
stream_status, |
||||||
|
team1, |
||||||
|
team2, |
||||||
|
}) => ({ |
||||||
|
date, |
||||||
|
id, |
||||||
|
preview: '/images/preview.png', |
||||||
|
sportName: SPORT_NAMES[sport], |
||||||
|
sportType: sport, |
||||||
|
streamStatus: stream_status, |
||||||
|
team1Logo: getProfileLogo({ |
||||||
|
id: team1.id, |
||||||
|
profileType: 2, |
||||||
|
sportType: sport, |
||||||
|
}), |
||||||
|
team1Name: team1[`name_${suffix}` as Name], |
||||||
|
team1Score: team1.score, |
||||||
|
team2Logo: getProfileLogo({ |
||||||
|
id: team2.id, |
||||||
|
profileType: 2, |
||||||
|
sportType: sport, |
||||||
|
}), |
||||||
|
team2Name: team2[`name_${suffix}` as Name], |
||||||
|
team2Score: team2.score, |
||||||
|
tournamentName: rest[`name_${suffix}` as Name], |
||||||
|
}))), |
||||||
|
flatten, |
||||||
|
fpOrderBy((match: Match) => Number(new Date(match.date)), 'desc'), |
||||||
|
)(content) as Array<Match> |
||||||
|
|
||||||
|
export const useMatches = ({ matches }: Props) => { |
||||||
|
const { suffix } = useLexicsStore() |
||||||
|
|
||||||
|
return useMemo(() => ({ |
||||||
|
broadcast: prepareMatches(matches.broadcast, suffix), |
||||||
|
features: prepareMatches(matches.features, suffix), |
||||||
|
highlights: prepareMatches(matches.highlights, suffix), |
||||||
|
isVideoSections: matches.isVideoSections, |
||||||
|
}), [suffix, matches]) |
||||||
|
} |
||||||
Loading…
Reference in new issue