Ott 283 matches list changes (#81)
parent
22d93b845c
commit
53cd031d5e
@ -1,45 +0,0 @@ |
||||
import size from 'lodash/size' |
||||
import slice from 'lodash/slice' |
||||
import chunk from 'lodash/chunk' |
||||
|
||||
import type { Match } from 'features/HeaderFilters' |
||||
import { useHeaderFiltersStore } from 'features/HeaderFilters' |
||||
|
||||
const MATCHES_PER_ROW = 6 |
||||
|
||||
const ROWS_COUNT = 3 |
||||
|
||||
export const useMatches = () => { |
||||
const { |
||||
matches: { |
||||
broadcast: matchesList, |
||||
}, |
||||
} = useHeaderFiltersStore() |
||||
const matchesCount = size(matchesList) |
||||
|
||||
let groupedMatches: Array<Array<Match>> = [] |
||||
|
||||
/** |
||||
* Распределяем матчи в ROWS_COUNT рядов |
||||
* Если общее количество матчей не больше количества |
||||
* ячеек в сетке размера ROWS_COUNT x MATCHES_PER_ROW, |
||||
* заполняем по максимуму каждый ряд с MATCHES_PER_ROW |
||||
* матчей в каждом, иначе распределяем поровну |
||||
*/ |
||||
if (matchesCount <= MATCHES_PER_ROW * ROWS_COUNT) { |
||||
for (let i = 0; i < ROWS_COUNT; i++) { |
||||
const matches = slice( |
||||
matchesList, |
||||
i * MATCHES_PER_ROW, |
||||
i * MATCHES_PER_ROW + MATCHES_PER_ROW, |
||||
) |
||||
groupedMatches.push(matches) |
||||
} |
||||
} else { |
||||
groupedMatches = chunk(matchesList, Math.ceil(matchesCount / ROWS_COUNT)) |
||||
} |
||||
|
||||
return { |
||||
groupedMatches, |
||||
} |
||||
} |
||||
@ -1,22 +0,0 @@ |
||||
import React, { Fragment } from 'react' |
||||
|
||||
import map from 'lodash/map' |
||||
|
||||
import { MatchesSlider } from 'features/MatchesSlider' |
||||
|
||||
import { useMatches } from './hooks' |
||||
|
||||
export const Matches = () => { |
||||
const { groupedMatches } = useMatches() |
||||
|
||||
return ( |
||||
<Fragment> |
||||
{map(groupedMatches, (matches, i) => ( |
||||
<MatchesSlider |
||||
key={i} |
||||
matches={matches} |
||||
/> |
||||
))} |
||||
</Fragment> |
||||
) |
||||
} |
||||
@ -0,0 +1,59 @@ |
||||
import React, { Fragment } from 'react' |
||||
|
||||
import isEmpty from 'lodash/isEmpty' |
||||
|
||||
import { useHeaderFiltersStore } from 'features/HeaderFilters' |
||||
import { MatchesSlider } from 'features/MatchesSlider' |
||||
import { MatchesGrid } from 'features/MatchesGrid' |
||||
import { T9n } from 'features/T9n' |
||||
|
||||
import { Title, Section } from './styled' |
||||
|
||||
export const Matches = () => { |
||||
const { |
||||
matches: { |
||||
broadcast, |
||||
features, |
||||
highlights, |
||||
isVideoSections, |
||||
}, |
||||
} = useHeaderFiltersStore() |
||||
|
||||
if (isVideoSections) { |
||||
return ( |
||||
<Fragment> |
||||
{!isEmpty(broadcast) && ( |
||||
<Section> |
||||
<Title><T9n t='broadcast' /></Title> |
||||
<MatchesSlider matches={broadcast} /> |
||||
</Section> |
||||
)} |
||||
|
||||
{!isEmpty(highlights) && ( |
||||
<Section> |
||||
<Title><T9n t='round_highilights' /></Title> |
||||
<MatchesSlider matches={highlights} /> |
||||
</Section> |
||||
)} |
||||
|
||||
{!isEmpty(features) && ( |
||||
<Section> |
||||
<Title><T9n t='features' /></Title> |
||||
<MatchesSlider matches={highlights} /> |
||||
</Section> |
||||
)} |
||||
</Fragment> |
||||
) |
||||
} |
||||
|
||||
return ( |
||||
<Fragment> |
||||
{!isEmpty(broadcast) && ( |
||||
<Section> |
||||
<Title><T9n t='broadcast' /></Title> |
||||
<MatchesGrid matches={broadcast} /> |
||||
</Section> |
||||
)} |
||||
</Fragment> |
||||
) |
||||
} |
||||
@ -0,0 +1,14 @@ |
||||
import styled from 'styled-components/macro' |
||||
|
||||
export const Section = styled.section` |
||||
margin-bottom: 30px; |
||||
` |
||||
|
||||
export const Title = styled.h2` |
||||
margin-bottom: 17px; |
||||
font-weight: bold; |
||||
font-size: 36px; |
||||
line-height: 24px; |
||||
letter-spacing: -0.02em; |
||||
color: #fff; |
||||
` |
||||
@ -0,0 +1,18 @@ |
||||
import React from 'react' |
||||
|
||||
import map from 'lodash/map' |
||||
|
||||
import type { Match } from 'features/HeaderFilters' |
||||
import { MatchCard } from 'features/MatchCard' |
||||
|
||||
import { Wrapper } from './styled' |
||||
|
||||
type MatchesGridProps = { |
||||
matches: Array<Match>, |
||||
} |
||||
|
||||
export const MatchesGrid = ({ matches }: MatchesGridProps) => ( |
||||
<Wrapper> |
||||
{map(matches, (match) => <MatchCard key={match.id} match={match} />)} |
||||
</Wrapper> |
||||
) |
||||
@ -0,0 +1,9 @@ |
||||
import styled from 'styled-components/macro' |
||||
|
||||
import { MATCH_CARD_WIDTH } from 'features/MatchCard/config' |
||||
|
||||
export const Wrapper = styled.ul` |
||||
display: grid; |
||||
grid-template-columns: repeat(6, ${MATCH_CARD_WIDTH}px); |
||||
grid-gap: 13px; |
||||
` |
||||
Loading…
Reference in new issue