Merge branch 'develop' into OTT-2362-create-lff-client

keep-around/8954335237167276f54602ac615497febf8ee3f0
Rakov Roman 4 years ago
commit 8954335237
  1. 17
      src/features/Matches/helpers/prepareMatches.tsx
  2. 14
      src/features/TournamentList/components/CollapseTournament/index.tsx
  3. 23
      src/features/TournamentList/components/TournamentMobile/index.tsx
  4. 40
      src/features/TournamentList/hooks.tsx
  5. 23
      src/features/TournamentList/index.tsx

@ -1,5 +1,5 @@
import map from 'lodash/map' import map from 'lodash/map'
import orderBy from 'lodash/orderBy'
import format from 'date-fns/format' import format from 'date-fns/format'
import type { Match } from 'requests' import type { Match } from 'requests'
@ -47,7 +47,14 @@ const prepareMatch = (match: Match) => {
} }
} }
export const prepareMatches = (matches: Array<Match>) => map( export const prepareMatches = (matches: Array<Match>) => {
matches, const preparedMatches = map(
prepareMatch, matches,
) prepareMatch,
)
return orderBy(
preparedMatches,
['live'],
['desc'],
)
}

@ -1,14 +1,11 @@
import { ProfileTypes } from 'config' import { ProfileTypes } from 'config'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { useUserFavoritesStore } from 'features/UserFavorites/store'
import { Icon } from 'features/Icon' import { Icon } from 'features/Icon'
import { useHeaderFiltersStore } from 'features/HeaderFilters' import { useHeaderFiltersStore } from 'features/HeaderFilters'
import { SportIcon } from 'components/SportIcon/SportIcon' import { SportIcon } from 'components/SportIcon/SportIcon'
import { TournamentProps } from '../TournamentMobile/index'
import { import {
CardWrapperOuter, CardWrapperOuter,
CardWrapper, CardWrapper,
@ -26,6 +23,8 @@ import {
HoverFrame, HoverFrame,
} from './styled' } from './styled'
import { TournamentProps } from '../..'
export const CollapseTournament = ({ export const CollapseTournament = ({
tournament, tournament,
tournamentMatches, tournamentMatches,
@ -35,18 +34,13 @@ export const CollapseTournament = ({
setSelectedLeague, setSelectedLeague,
setSelectTournament, setSelectTournament,
} = useHeaderFiltersStore() } = useHeaderFiltersStore()
const { isInFavorites } = useUserFavoritesStore()
const { const {
countryId, countryId,
isFavorite,
live, live,
sportType, sportType,
} = tournament } = tournament
const tournamentInFavorites = isInFavorites(
ProfileTypes.TOURNAMENTS,
tournament.id,
)
const handleClick = () => { const handleClick = () => {
setIsShowTournament(false) setIsShowTournament(false)
setSelectedLeague([tournament.id]) setSelectedLeague([tournament.id])
@ -83,7 +77,7 @@ export const CollapseTournament = ({
<SecondaryInfo> <SecondaryInfo>
<TournamentName nameObj={tournament} /> <TournamentName nameObj={tournament} />
{tournamentInFavorites && ( {isFavorite && (
<FavoriteSign marginLeft={12} color='rgba(255, 255, 255, 0.5)'> <FavoriteSign marginLeft={12} color='rgba(255, 255, 255, 0.5)'>
<Icon refIcon='Star' /> <Icon refIcon='Star' />
</FavoriteSign> </FavoriteSign>

@ -1,7 +1,5 @@
import { useState } from 'react' import { useState } from 'react'
import { ProfileTypes } from 'config'
import { SportIcon } from 'components/SportIcon/SportIcon' import { SportIcon } from 'components/SportIcon/SportIcon'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { Icon } from 'features/Icon' import { Icon } from 'features/Icon'
@ -12,9 +10,6 @@ import {
FavoriteSign, FavoriteSign,
LiveSign, LiveSign,
} from 'features/MatchCard/CardFrontside/MatchCardMobile/styled' } from 'features/MatchCard/CardFrontside/MatchCardMobile/styled'
import { useUserFavoritesStore } from 'features/UserFavorites/store'
import type { TournamentType } from 'requests/getMatches/types'
import { import {
CardWrapperOuter, CardWrapperOuter,
@ -26,14 +21,7 @@ import {
ScSecondInfo, ScSecondInfo,
} from './styled' } from './styled'
export type TournamentProps = { import { TournamentProps } from '../..'
tournament: TournamentType & {
countryId: number,
live: boolean,
sportType: number,
},
tournamentMatches: Array<Match>,
}
export const TournamentMobile = ({ export const TournamentMobile = ({
tournament, tournament,
@ -42,18 +30,13 @@ export const TournamentMobile = ({
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const { const {
countryId, countryId,
isFavorite,
live, live,
sportType, sportType,
} = tournament } = tournament
const { isInFavorites } = useUserFavoritesStore()
const currentColor = open ? '#ffffff' : 'rgba(255, 255, 255, 0.5)' const currentColor = open ? '#ffffff' : 'rgba(255, 255, 255, 0.5)'
const tournamentInFavorites = isInFavorites(
ProfileTypes.TOURNAMENTS,
tournament.id,
)
return ( return (
<CardWrapperOuter> <CardWrapperOuter>
<CardWrapper <CardWrapper
@ -66,7 +49,7 @@ export const TournamentMobile = ({
src={`https://instatscout.com/images/flags/48/${countryId}.png`} src={`https://instatscout.com/images/flags/48/${countryId}.png`}
/> />
<TournamentName nameObj={tournament} /> <TournamentName nameObj={tournament} />
{tournamentInFavorites && ( {isFavorite && (
<FavoriteSign marginLeft={12} color={currentColor}> <FavoriteSign marginLeft={12} color={currentColor}>
<Icon refIcon='Star' /> <Icon refIcon='Star' />
</FavoriteSign> </FavoriteSign>

@ -1,9 +1,20 @@
import { useEffect } from 'react' import { useEffect, useMemo } from 'react'
import orderBy from 'lodash/orderBy'
import { getSportLexic } from 'helpers/getSportLexic' import { getSportLexic } from 'helpers/getSportLexic'
import { ProfileTypes } from 'config'
import { TournamentListProps } from 'features/TournamentList' import { TournamentListProps } from 'features/TournamentList'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
import { useHeaderFiltersStore } from 'features/HeaderFilters' import { useHeaderFiltersStore } from 'features/HeaderFilters'
import { useUserFavoritesStore } from 'features/UserFavorites/store'
interface TournamentsSortProps {
id: number,
isFavorite: boolean,
isLive: boolean,
}
export const useTournaments = (matches: Array<Match>) => { export const useTournaments = (matches: Array<Match>) => {
const { const {
@ -12,6 +23,7 @@ export const useTournaments = (matches: Array<Match>) => {
selectedSport, selectedSport,
setSportIds, setSportIds,
} = useHeaderFiltersStore() } = useHeaderFiltersStore()
const { isInFavorites } = useUserFavoritesStore()
const compareSport = (match: Match, sportNames: Array<string>) => { const compareSport = (match: Match, sportNames: Array<string>) => {
if (sportNames[0] === 'all_sports') { if (sportNames[0] === 'all_sports') {
@ -28,16 +40,24 @@ export const useTournaments = (matches: Array<Match>) => {
return (selectedLeague.indexOf(id) >= 0) return (selectedLeague.indexOf(id) >= 0)
} }
const tournamentSort: Array<number> = [] // eslint-disable-next-line react-hooks/exhaustive-deps
const tournamentSort: Array<TournamentsSortProps> = []
const sportIds = new Set<number>([]) const sportIds = new Set<number>([])
const tournaments = matches.reduce((acc: TournamentListProps, match: Match) => { const tournaments = matches.reduce((acc: TournamentListProps, match: Match) => {
if (matches.length === 0) return {} if (matches.length === 0) return {}
const tournamentInFavorites = isInFavorites(
ProfileTypes.TOURNAMENTS,
match.tournament.id,
)
if (!acc[match.tournament.id] && compareSport(match, selectedSport) if (!acc[match.tournament.id] && compareSport(match, selectedSport)
&& compareLeague(match.tournament.id)) { && compareLeague(match.tournament.id)) {
const tournament = { const tournament = {
...match.tournament, ...match.tournament,
countryId: match.countryId, countryId: match.countryId,
isFavorite: tournamentInFavorites,
live: match.live, live: match.live,
matches: [match], matches: [match],
sportType: match.sportType, sportType: match.sportType,
@ -48,7 +68,11 @@ export const useTournaments = (matches: Array<Match>) => {
}, },
tournamentMatches: [match], tournamentMatches: [match],
} }
tournamentSort.push(match.tournament.id) tournamentSort.push({
id: match.tournament.id,
isFavorite: tournamentInFavorites,
isLive: match.live,
})
sportIds.add(match.sportType) sportIds.add(match.sportType)
} else if (compareSport(match, selectedSport) && compareLeague(match.tournament.id)) { } else if (compareSport(match, selectedSport) && compareLeague(match.tournament.id)) {
acc[match.tournament.id] = { acc[match.tournament.id] = {
@ -65,13 +89,19 @@ export const useTournaments = (matches: Array<Match>) => {
return acc return acc
}, {}) }, {})
const tournamentsSorted = useMemo(() => orderBy(
tournamentSort,
['isLive', 'isFavorite'],
['desc', 'desc'],
), [tournamentSort])
useEffect(() => { useEffect(() => {
sportIds && setSportIds(sportIds) sportIds && setSportIds(sportIds)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedDate, matches]) }, [selectedDate, matches])
return { return {
tournamentSort, tournamentSort: tournamentsSorted,
tournaments, tournaments,
} }
} }

@ -16,15 +16,18 @@ type TournamentTypeProps = {
matches: Array<Match>, matches: Array<Match>,
} }
export type TournamentListProps = { export type TournamentProps = {
[key: number]: { tournament: TournamentType & {
tournament: TournamentType & { countryId: number,
countryId: number, isFavorite: boolean,
live: boolean, live: boolean,
sportType: number, sportType: number,
},
tournamentMatches: Array<Match>,
}, },
tournamentMatches: Array<Match>,
}
export type TournamentListProps = {
[key: number]: TournamentProps,
} }
export const TournamentList = ({ matches }: TournamentTypeProps) => { export const TournamentList = ({ matches }: TournamentTypeProps) => {
@ -35,7 +38,7 @@ export const TournamentList = ({ matches }: TournamentTypeProps) => {
case isMobileDevice && isHomePage: case isMobileDevice && isHomePage:
return ( return (
<> <>
{tournamentSort?.map((id) => ( {tournamentSort?.map(({ id }) => (
<TournamentMobile <TournamentMobile
key={id} key={id}
tournament={tournaments[id].tournament} tournament={tournaments[id].tournament}
@ -47,7 +50,7 @@ export const TournamentList = ({ matches }: TournamentTypeProps) => {
case isHomePage && matches.length >= 12: case isHomePage && matches.length >= 12:
return ( return (
<> <>
{tournamentSort?.map((id) => ( {tournamentSort?.map(({ id }) => (
<CollapseTournament <CollapseTournament
key={id} key={id}
tournament={tournaments[id].tournament} tournament={tournaments[id].tournament}

Loading…
Cancel
Save