You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
import map from 'lodash/map'
|
|
import some from 'lodash/some'
|
|
import filter from 'lodash/filter'
|
|
import uniq from 'lodash/uniq'
|
|
import uniqBy from 'lodash/uniqBy'
|
|
import flatten from 'lodash/flatten'
|
|
import compact from 'lodash/compact'
|
|
import startsWith from 'lodash/startsWith'
|
|
import toLower from 'lodash/toLower'
|
|
|
|
import { Match } from 'requests'
|
|
|
|
const checkStartString = (text: string, searchString: string) => startsWith(
|
|
toLower(text), toLower(searchString),
|
|
)
|
|
|
|
export const getAge = (filterList: Array<Match>) => compact(
|
|
uniq(
|
|
flatten(
|
|
map(
|
|
filterList, (item) => [item.team1.youth_age, item.team2.youth_age],
|
|
),
|
|
),
|
|
),
|
|
)
|
|
|
|
export const getDivision = (filterList: Array<Match>) => filter(
|
|
flatten(
|
|
map(
|
|
filterList, (item) => [item.team1.division, item.team2.division],
|
|
),
|
|
), (item) => item?.id,
|
|
)
|
|
|
|
export const getMainTeam = (filterList: Array<Match>) => filter(
|
|
flatten(
|
|
map(
|
|
filterList, (item) => [item.team1.main_team, item.team2.main_team],
|
|
),
|
|
), (item) => item?.id,
|
|
)
|
|
|
|
export const getArena = (filterList: Array<Match>, inputValue: string) => filter(
|
|
map(
|
|
filterList, (item) => item.arena,
|
|
), (item) => item?.id
|
|
&& (checkStartString(item.name_eng, inputValue)
|
|
|| checkStartString(item.name_rus, inputValue)),
|
|
)
|
|
|
|
export const getSport = (filterList: Array<Match>) => uniqBy(
|
|
filter(
|
|
map(
|
|
filterList, (item) => item.sport_info,
|
|
), (item) => item?.id,
|
|
), 'id',
|
|
)
|
|
|
|
export const getRound = (filterList: Array<Match>) => uniqBy(
|
|
filter(
|
|
map(
|
|
filterList, (item) => item.round,
|
|
), (item) => item?.id,
|
|
), 'id',
|
|
)
|
|
|
|
export const getGender = (filterList: Array<Match>) => {
|
|
const list = []
|
|
|
|
if (some(filterList, (item) => item.team1.gender === 1 || item.team2.gender === 1)) list.push({ id: 1, lexic: 'gender_male_long' })
|
|
if (some(filterList, (item) => item.team1.gender === 2 || item.team2.gender === 2)) list.push({ id: 2, lexic: 'gender_female_long' })
|
|
|
|
return list
|
|
}
|
|
|