Ott 455 sport name refactor (#153)

* feat(ott-445): changed sportName component logic

* fix(ott-455): minor changes

* fix(ott-455): added sport types enum

Co-authored-by: Armen <armen9339@gmail.com>
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Armen9339 5 years ago committed by GitHub
parent 3b6d752486
commit 57dcf853c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      src/features/Common/SportName/index.tsx
  2. 16
      src/features/Common/SportName/styled.tsx
  3. 10
      src/features/HeaderFilters/components/TournamentFilter/helpers.tsx
  4. 1
      src/features/HeaderFilters/components/TournamentFilter/hooks.tsx
  5. 13
      src/features/HeaderFilters/components/TournamentList/index.tsx
  6. 12
      src/features/ItemsList/index.tsx
  7. 3
      src/features/MatchCard/CardFinished/index.tsx
  8. 3
      src/features/MatchCard/CardLive/index.tsx
  9. 4
      src/features/MatchCard/CardSoon/index.tsx
  10. 9
      src/features/MatchPage/MatchProfileCard/index.tsx
  11. 13
      src/features/Search/hooks/useNormalizedItems.tsx
  12. 6
      src/requests/getSportTournaments.tsx

@ -1,17 +1,21 @@
import styled from 'styled-components/macro' import React from 'react'
import { devices } from 'config/devices' import { SportTypes } from 'config'
import { T9n } from 'features/T9n'
export const SportName = styled(T9n)<{ color: string }>` import { getSportColor, getSportLexic } from 'helpers'
margin-right: 10px;
font-size: 11px;
color: ${({ color }) => color};
letter-spacing: 0.02em;
text-transform: uppercase;
@media ${devices.tablet} { import { useLexicsStore } from 'features/LexicsStore'
font-size: 10px;
margin-right: 5px; import { Text } from './styled'
}
` type SportNameProps = { sport: SportTypes }
export const SportName = ({ sport }: SportNameProps) => {
const { translate } = useLexicsStore()
return (
<Text color={getSportColor(sport)}>
{translate(getSportLexic(sport))}
</Text>
)
}

@ -0,0 +1,16 @@
import styled from 'styled-components/macro'
import { devices } from 'config/devices'
export const Text = styled.span<{ color: string }>`
margin-right: 10px;
font-size: 11px;
color: ${({ color }) => color};
letter-spacing: 0.02em;
text-transform: uppercase;
@media ${devices.tablet} {
font-size: 10px;
margin-right: 5px;
}
`

@ -5,8 +5,6 @@ import { Tournaments } from 'requests'
import { ProfileTypes } from 'config' import { ProfileTypes } from 'config'
import { import {
getProfileLogo, getProfileLogo,
getSportColor,
getSportLexic,
getProfileFallbackLogo, getProfileFallbackLogo,
} from 'helpers' } from 'helpers'
@ -16,9 +14,7 @@ type ShortName = 'short_name_rus' | 'short_name_eng'
export const normalizeTournaments = (tournaments: Tournaments, suffix: string) => ( export const normalizeTournaments = (tournaments: Tournaments, suffix: string) => (
map(tournaments, (tournament) => { map(tournaments, (tournament) => {
const profileType = ProfileTypes.TOURNAMENTS const profileType = ProfileTypes.TOURNAMENTS
const { c_sport: sportType, id } = tournament const { id, sport: sportType } = tournament
const color = getSportColor(sportType)
const sportLexic = getSportLexic(sportType)
const name = tournament[`name_${suffix}` as Name] const name = tournament[`name_${suffix}` as Name]
const shortName = tournament[`short_name_${suffix}` as ShortName] || name const shortName = tournament[`short_name_${suffix}` as ShortName] || name
const country = tournament.country?.[`name_${suffix}` as Name] const country = tournament.country?.[`name_${suffix}` as Name]
@ -32,16 +28,14 @@ export const normalizeTournaments = (tournaments: Tournaments, suffix: string) =
profileType, profileType,
sportType, sportType,
}) })
return { return {
color,
country, country,
fallbackImage, fallbackImage,
id, id,
logo, logo,
name, name,
shortName, shortName,
sportLexic, sportType,
} }
}) })
) )

@ -50,6 +50,7 @@ export const useTournamentFilter = () => {
} }
const tournaments = normalizeTournaments(list, suffix) const tournaments = normalizeTournaments(list, suffix)
const selectedTournament = find( const selectedTournament = find(
tournaments, tournaments,
(tournament) => tournament.id === selectedTournamentId, (tournament) => tournament.id === selectedTournamentId,

@ -2,6 +2,8 @@ import React from 'react'
import map from 'lodash/map' import map from 'lodash/map'
import { SportTypes } from 'config'
import { useItemsList } from 'features/ItemsList/hooks' import { useItemsList } from 'features/ItemsList/hooks'
import { import {
Logo, Logo,
@ -16,13 +18,12 @@ import { SportName } from 'features/Common'
import { ListItem } from './styled' import { ListItem } from './styled'
type Tournament = { type Tournament = {
color: string,
country?: string, country?: string,
fallbackImage: string, fallbackImage: string,
id: number, id: number,
logo: string, logo: string,
name: string, name: string,
sportLexic: string, sportType: SportTypes,
} }
type TournamentListProps = { type TournamentListProps = {
@ -39,13 +40,12 @@ export const TournamentList = ({ onSelect, tournaments }: TournamentListProps) =
return ( return (
<Wrapper ref={ref} role='listbox'> <Wrapper ref={ref} role='listbox'>
{map(tournaments, ({ {map(tournaments, ({
color,
country, country,
fallbackImage, fallbackImage,
id, id,
logo, logo,
name, name,
sportLexic, sportType,
}) => ( }) => (
<ListItem <ListItem
key={`${id}_${name}`} key={`${id}_${name}`}
@ -61,10 +61,7 @@ export const TournamentList = ({ onSelect, tournaments }: TournamentListProps) =
</LogoWrapper> </LogoWrapper>
<ItemInfo> <ItemInfo>
<Name>{name}</Name> <Name>{name}</Name>
<SportName <SportName sport={sportType} />
color={color}
t={sportLexic}
/>
<TeamOrCountry>{country}</TeamOrCountry> <TeamOrCountry>{country}</TeamOrCountry>
</ItemInfo> </ItemInfo>
</ListItem> </ListItem>

@ -2,6 +2,8 @@ import React from 'react'
import map from 'lodash/map' import map from 'lodash/map'
import { SportTypes } from 'config'
import { SportName } from 'features/Common' import { SportName } from 'features/Common'
import { useItemsList } from './hooks' import { useItemsList } from './hooks'
@ -25,7 +27,7 @@ type SearchItemsListProps = {
logo: string, logo: string,
name: string, name: string,
profileUrl: string, profileUrl: string,
sportLexic: string, sportType: SportTypes,
teamOrCountry?: string, teamOrCountry?: string,
}>, }>,
} }
@ -39,13 +41,12 @@ export const ItemsList = ({ close, list }: SearchItemsListProps) => {
return ( return (
<Wrapper ref={ref}> <Wrapper ref={ref}>
{map(list, ({ {map(list, ({
color,
fallbackImage, fallbackImage,
id, id,
logo, logo,
name, name,
profileUrl, profileUrl,
sportLexic, sportType,
teamOrCountry, teamOrCountry,
}) => ( }) => (
<Item key={id}> <Item key={id}>
@ -58,10 +59,7 @@ export const ItemsList = ({ close, list }: SearchItemsListProps) => {
</LogoWrapper> </LogoWrapper>
<ItemInfo> <ItemInfo>
<Name>{name}</Name> <Name>{name}</Name>
<SportName <SportName sport={sportType} />
color={color}
t={sportLexic}
/>
<TeamOrCountry>{teamOrCountry}</TeamOrCountry> <TeamOrCountry>{teamOrCountry}</TeamOrCountry>
</ItemInfo> </ItemInfo>
</StyledLink> </StyledLink>

@ -1,7 +1,6 @@
import React from 'react' import React from 'react'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
import { getSportColor } from 'helpers'
import { SportName } from 'features/Common' import { SportName } from 'features/Common'
import { useCard } from '../hooks' import { useCard } from '../hooks'
@ -76,7 +75,7 @@ export const CardFinished = ({
/> />
</PreviewWrapper> </PreviewWrapper>
<Info> <Info>
<SportName t={sportName} color={getSportColor(sportType)} /> <SportName sport={sportType} />
<TournamentName title={tournamentName}>{tournamentName}</TournamentName> <TournamentName title={tournamentName}>{tournamentName}</TournamentName>
<Teams> <Teams>
<Team> <Team>

@ -1,7 +1,6 @@
import React from 'react' import React from 'react'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
import { getSportColor } from 'helpers'
import { SportName } from 'features/Common' import { SportName } from 'features/Common'
import { useCard } from '../hooks' import { useCard } from '../hooks'
@ -76,7 +75,7 @@ export const CardLive = ({
/> />
</PreviewWrapper> </PreviewWrapper>
<Info> <Info>
<SportName t={sportName} color={getSportColor(sportType)} /> <SportName sport={sportType} />
<TournamentName title={tournamentName}>{tournamentName}</TournamentName> <TournamentName title={tournamentName}>{tournamentName}</TournamentName>
<Teams> <Teams>
<Team> <Team>

@ -5,7 +5,7 @@ import styled from 'styled-components/macro'
import { devices } from 'config/devices' import { devices } from 'config/devices'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
import { getSportColor, handleImageError } from 'helpers' import { handleImageError } from 'helpers'
import { SportName } from 'features/Common' import { SportName } from 'features/Common'
import { import {
@ -99,7 +99,7 @@ export const CardSoon = ({
</TeamLogos> </TeamLogos>
</PreviewWrapper> </PreviewWrapper>
<Info> <Info>
<SportName t={sportName} color={getSportColor(sportType)} /> <SportName sport={sportType} />
<TournamentName title={tournamentName}>{tournamentName}</TournamentName> <TournamentName title={tournamentName}>{tournamentName}</TournamentName>
<Teams> <Teams>
<Team> <Team>

@ -3,7 +3,6 @@ import React, { Fragment } from 'react'
import isNull from 'lodash/isNull' import isNull from 'lodash/isNull'
import { getProfileUrl } from 'helpers' import { getProfileUrl } from 'helpers'
import { getSportColor } from 'helpers/getSportColor'
import { ProfileTypes } from 'config' import { ProfileTypes } from 'config'
@ -27,12 +26,11 @@ type Props = {
} }
export const MatchProfileCard = ({ profile }: Props) => { export const MatchProfileCard = ({ profile }: Props) => {
const { sportName, sportType } = useSportNameParam() const { sportType } = useSportNameParam()
const { isHidden } = useScoreStore() const { isHidden } = useScoreStore()
if (!profile) return <Wrapper /> if (!profile) return <Wrapper />
const color = getSportColor(sportType)
const { const {
team1, team1,
team2, team2,
@ -74,10 +72,7 @@ export const MatchProfileCard = ({ profile }: Props) => {
</Teams> </Teams>
<Tournament> <Tournament>
<SportName <SportName sport={sportType} />
color={color}
t={sportName}
/>
<StyledLink to={getProfileUrl({ <StyledLink to={getProfileUrl({
id: tournament.id, id: tournament.id,
profileType: ProfileTypes.TOURNAMENTS, profileType: ProfileTypes.TOURNAMENTS,

@ -5,7 +5,6 @@ import { ProfileTypes } from 'config'
import { import {
getProfileLogo, getProfileLogo,
getSportColor, getSportColor,
getSportLexic,
getProfileFallbackLogo, getProfileFallbackLogo,
getProfileUrl, getProfileUrl,
} from 'helpers' } from 'helpers'
@ -28,8 +27,6 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
const lastName = player[`lastname_${suffix}` as Lastname] const lastName = player[`lastname_${suffix}` as Lastname]
const teamName = player.team?.[`name_${suffix}` as Name] const teamName = player.team?.[`name_${suffix}` as Name]
const sportLexic = getSportLexic(sportType)
const logo = getProfileLogo({ const logo = getProfileLogo({
id, id,
profileType, profileType,
@ -51,7 +48,7 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
profileType: ProfileTypes.PLAYERS, profileType: ProfileTypes.PLAYERS,
sportType, sportType,
}), }),
sportLexic, sportType,
teamOrCountry: teamName, teamOrCountry: teamName,
} }
}) })
@ -61,8 +58,6 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
const profileType = ProfileTypes.TEAMS const profileType = ProfileTypes.TEAMS
const name = team[`name_${suffix}` as Name] const name = team[`name_${suffix}` as Name]
const sportLexic = getSportLexic(sportType)
const logo = getProfileLogo({ const logo = getProfileLogo({
id, id,
profileType, profileType,
@ -86,7 +81,7 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
profileType: ProfileTypes.TEAMS, profileType: ProfileTypes.TEAMS,
sportType, sportType,
}), }),
sportLexic, sportType,
teamOrCountry: country, teamOrCountry: country,
} }
}) })
@ -96,8 +91,6 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
const { id, sport: sportType } = tournament const { id, sport: sportType } = tournament
const name = tournament[`name_${suffix}` as Name] const name = tournament[`name_${suffix}` as Name]
const sportLexic = getSportLexic(sportType)
const logo = getProfileLogo({ const logo = getProfileLogo({
id, id,
profileType, profileType,
@ -121,7 +114,7 @@ export const useNormalizedItems = (searchItems: SearchItems) => {
profileType: ProfileTypes.TOURNAMENTS, profileType: ProfileTypes.TOURNAMENTS,
sportType, sportType,
}), }),
sportLexic, sportType,
teamOrCountry: country, teamOrCountry: country,
} }
}) })

@ -14,15 +14,15 @@ type Country = {
} }
export type Tournament = { export type Tournament = {
c_gender: number | null,
c_sport: SportTypes,
c_tournament_type: number,
country: Country, country: Country,
gender: number | null,
id: number, id: number,
name_eng: string, name_eng: string,
name_rus: string, name_rus: string,
short_name_eng: string | null, short_name_eng: string | null,
short_name_rus: string | null, short_name_rus: string | null,
sport: SportTypes,
tournament_type: number,
} }
export type Tournaments = Array<Tournament> export type Tournaments = Array<Tournament>

Loading…
Cancel
Save