Ott 299 team page (#90)
* fix(ott-287): changed default football to null * fix(ott-287): minor bug * fix(ott-287): temp * feat(ott-287): created infinite scroll * feat(ott-287): added infinite scroll * fix(ott-299): changed imports position * fix(ott-299): comment bug fix * fix(ott-299): minor bug fix * fix(ott-299): some minor css bugs * fix(ott-299): fixed width styles * fix(ott-299): fixed menu right margin * fix(ott-299): fixed comments, added team type * fix(ott-299): conflict resolved * fix(ott-299): conflict consequences are resolved * fix(ott-299): some minor bugs fixkeep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
6460d0cc2e
commit
2534688392
@ -0,0 +1,57 @@ |
||||
import React, { Fragment } from 'react' |
||||
|
||||
import isEmpty from 'lodash/isEmpty' |
||||
|
||||
import { getSportColor } from 'helpers/getSportColor' |
||||
|
||||
import { SportName } from 'features/Common/SportName' |
||||
|
||||
import { useSportNameParam } from 'hooks/useSportNameParam' |
||||
import { useMatchPage } from '../hooks' |
||||
|
||||
import { |
||||
Wrapper, |
||||
Teams, |
||||
Score, |
||||
Tournament, |
||||
Dash, |
||||
} from './styled' |
||||
|
||||
export const MatchProfileCard = () => { |
||||
const { |
||||
matchProfile, |
||||
matchProfileNames: { |
||||
team1Name, |
||||
team2Name, |
||||
tournament, |
||||
}, |
||||
} = useMatchPage() |
||||
|
||||
const { sportName, sportType } = useSportNameParam() |
||||
|
||||
const { team1, team2 } = matchProfile || {} |
||||
|
||||
const color = getSportColor(sportType) |
||||
|
||||
return ( |
||||
<Wrapper> |
||||
{!isEmpty(matchProfile) |
||||
&& ( |
||||
<Fragment> |
||||
<Teams> |
||||
{team1Name} <Dash /> {team2Name} |
||||
</Teams> |
||||
<Score> |
||||
{team1?.score} : {team2?.score} |
||||
</Score> |
||||
<Tournament> |
||||
<SportName |
||||
color={color} |
||||
t={sportName} |
||||
/>{tournament} |
||||
</Tournament> |
||||
</Fragment> |
||||
)} |
||||
</Wrapper> |
||||
) |
||||
} |
||||
@ -0,0 +1,38 @@ |
||||
import styled from 'styled-components/macro' |
||||
|
||||
export const Wrapper = styled.div` |
||||
display: flex; |
||||
font-weight: bold; |
||||
font-size: 36px; |
||||
line-height: 24px; |
||||
color: white; |
||||
min-height: 28px; |
||||
` |
||||
|
||||
export const Teams = styled.div` |
||||
display: flex; |
||||
` |
||||
|
||||
export const Dash = styled.span` |
||||
position: relative; |
||||
width: 40px; |
||||
border-bottom: 3px solid white; |
||||
margin: 0 15px; |
||||
height: fit-content; |
||||
align-self: center; |
||||
` |
||||
|
||||
export const Score = styled.div` |
||||
display: flex; |
||||
margin-left: 48px; |
||||
` |
||||
|
||||
export const Tournament = styled.div` |
||||
display: flex; |
||||
font-weight: 500; |
||||
font-size: 12px; |
||||
line-height: 16px; |
||||
align-self: flex-end; |
||||
margin-left: 48px; |
||||
color: #666666; |
||||
` |
||||
@ -0,0 +1,53 @@ |
||||
import { useEffect, useState } from 'react' |
||||
|
||||
import type { MatchInfo } from 'requests' |
||||
import { getMatchInfo } from 'requests' |
||||
|
||||
import { useHeaderFiltersStore } from 'features/HeaderFilters' |
||||
import { useLexicsStore } from 'features/LexicsStore' |
||||
|
||||
import { useSportNameParam, usePageId } from 'hooks' |
||||
|
||||
type Name = 'name_rus' | 'name_eng' |
||||
|
||||
export const useMatchPage = () => { |
||||
const [matchProfile, setMatchProfile] = useState<MatchInfo>(null) |
||||
const { sportType } = useSportNameParam() |
||||
const pageId = usePageId() |
||||
const { suffix } = useLexicsStore() |
||||
|
||||
const { |
||||
setSelectedSportTypeId, |
||||
setSelectedTournamentId, |
||||
} = useHeaderFiltersStore() |
||||
|
||||
const matchProfileNames = { |
||||
team1Name: matchProfile?.team1[`name_${suffix}` as Name], |
||||
team2Name: matchProfile?.team2[`name_${suffix}` as Name], |
||||
tournament: matchProfile?.tournament[`name_${suffix}` as Name], |
||||
} |
||||
|
||||
useEffect(() => { |
||||
setSelectedSportTypeId(sportType) |
||||
setSelectedTournamentId(pageId) |
||||
|
||||
getMatchInfo(sportType, pageId) |
||||
.then(setMatchProfile) |
||||
|
||||
return () => { |
||||
setSelectedSportTypeId(null) |
||||
setSelectedTournamentId(null) |
||||
} |
||||
}, |
||||
[ |
||||
sportType, |
||||
pageId, |
||||
setSelectedSportTypeId, |
||||
setSelectedTournamentId, |
||||
]) |
||||
|
||||
return { |
||||
matchProfile, |
||||
matchProfileNames, |
||||
} |
||||
} |
||||
@ -1,11 +1,17 @@ |
||||
import React from 'react' |
||||
import styled from 'styled-components' |
||||
|
||||
const TempPageTitle = styled.span` |
||||
padding: 20px; |
||||
font-size: 20px; |
||||
color: white; |
||||
` |
||||
import { UserFavoritesStore } from 'features/UserFavorites/store' |
||||
|
||||
import { MatchProfileCard } from './MatchProfileCard' |
||||
|
||||
import { |
||||
MainWrapper, |
||||
} from './styled' |
||||
|
||||
export const MatchPage = () => ( |
||||
<TempPageTitle>MATCH PAGE!</TempPageTitle> |
||||
<UserFavoritesStore> |
||||
<MainWrapper> |
||||
<MatchProfileCard /> |
||||
</MainWrapper> |
||||
</UserFavoritesStore> |
||||
) |
||||
|
||||
@ -0,0 +1,6 @@ |
||||
import styled from 'styled-components/macro' |
||||
|
||||
export const MainWrapper = styled.div` |
||||
margin-left: 18px; |
||||
margin-top: 63px; |
||||
` |
||||
@ -1,29 +1,56 @@ |
||||
import { useEffect } from 'react' |
||||
import { useEffect, useState } from 'react' |
||||
|
||||
import type { TeamInfo } from 'requests' |
||||
import { getTeamInfo } from 'requests' |
||||
|
||||
import { useHeaderFiltersStore } from 'features/HeaderFilters' |
||||
import { useLexicsStore } from 'features/LexicsStore' |
||||
|
||||
import { useSportNameParam, usePageId } from 'hooks' |
||||
|
||||
type Name = 'name_rus' | 'name_eng' |
||||
|
||||
export const useTeamPage = () => { |
||||
const [teamProfile, setTeamProfile] = useState<TeamInfo>(null) |
||||
const { sportType } = useSportNameParam() |
||||
const teamId = usePageId() |
||||
const { suffix } = useLexicsStore() |
||||
|
||||
const { |
||||
setSelectedSportTypeId, |
||||
setTeamId, |
||||
} = useHeaderFiltersStore() |
||||
|
||||
const { |
||||
[`name_${suffix}` as Name]: name = '', |
||||
} = teamProfile || {} |
||||
|
||||
const { |
||||
[`name_${suffix}` as Name]: country = '', |
||||
} = teamProfile?.country || {} |
||||
|
||||
useEffect(() => { |
||||
setSelectedSportTypeId(sportType) |
||||
setTeamId(teamId) |
||||
|
||||
getTeamInfo(sportType, teamId) |
||||
.then(setTeamProfile) |
||||
|
||||
return () => { |
||||
setSelectedSportTypeId(null) |
||||
setTeamId(null) |
||||
} |
||||
}, [ |
||||
setSelectedSportTypeId, |
||||
setTeamId, |
||||
}, |
||||
[ |
||||
sportType, |
||||
teamId, |
||||
setSelectedSportTypeId, |
||||
setTeamId, |
||||
]) |
||||
|
||||
return { |
||||
infoItems: [country], |
||||
name, |
||||
sportType, |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,47 @@ |
||||
import { |
||||
DATA_URL, |
||||
PROCEDURES, |
||||
} from 'config' |
||||
|
||||
import { callApi, getResponseData } from 'helpers' |
||||
|
||||
import { MatchStatuses } from 'features/HeaderFilters' |
||||
|
||||
const proc = PROCEDURES.get_match_info |
||||
|
||||
type Team = { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
score: number, |
||||
} |
||||
|
||||
export type MatchInfo = { |
||||
date: Date, |
||||
stream_status: MatchStatuses, |
||||
team1: Team, |
||||
team2: Team, |
||||
tournament: { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
}, |
||||
} | null |
||||
|
||||
export const getMatchInfo = (sportId: number, matchId: number) |
||||
: Promise<MatchInfo> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_match_id: matchId, |
||||
_p_sport: sportId, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: DATA_URL, |
||||
}).then(getResponseData(proc)) |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
import { |
||||
DATA_URL, |
||||
PROCEDURES, |
||||
} from 'config' |
||||
|
||||
import { callApi, getResponseData } from 'helpers' |
||||
|
||||
const proc = PROCEDURES.get_team_info |
||||
|
||||
export type TeamInfo = { |
||||
country: { |
||||
id: number, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
}, |
||||
id: number, |
||||
is_favorite: boolean, |
||||
name_eng: string, |
||||
name_rus: string, |
||||
short_name_eng: string, |
||||
short_name_rus: string, |
||||
} | null |
||||
|
||||
export const getTeamInfo = (sportId: number, teamId: number) |
||||
: Promise<TeamInfo> => { |
||||
const config = { |
||||
body: { |
||||
params: { |
||||
_p_sport: sportId, |
||||
_p_team_id: teamId, |
||||
}, |
||||
proc, |
||||
}, |
||||
} |
||||
|
||||
return callApi({ |
||||
config, |
||||
url: DATA_URL, |
||||
}).then(getResponseData(proc)) |
||||
} |
||||
Loading…
Reference in new issue