|
|
|
|
@ -1,19 +1,25 @@ |
|
|
|
|
import { useRef, useEffect } from 'react' |
|
|
|
|
|
|
|
|
|
import styled from 'styled-components/macro' |
|
|
|
|
|
|
|
|
|
import map from 'lodash/map' |
|
|
|
|
import find from 'lodash/find' |
|
|
|
|
|
|
|
|
|
import type { Team } from 'requests' |
|
|
|
|
import type { PlaylistOption } from 'features/MatchPage/types' |
|
|
|
|
import type { |
|
|
|
|
PlayerPlaylistOptions, |
|
|
|
|
PlayerPlaylistOption, |
|
|
|
|
PlaylistOption, |
|
|
|
|
} from 'features/MatchPage/types' |
|
|
|
|
|
|
|
|
|
import { Name } from 'features/Name' |
|
|
|
|
import { isEqual } from 'features/MatchSidePlaylists' |
|
|
|
|
|
|
|
|
|
import { PlayButton } from '../PlayButton' |
|
|
|
|
import { Item } from '../DropdownSection/styled' |
|
|
|
|
|
|
|
|
|
type Props = { |
|
|
|
|
onSelect: (selectedMathPlaylist: PlaylistOption) => void, |
|
|
|
|
players: Array<PlaylistOption>, |
|
|
|
|
onSelect: (selectedMathPlaylist: PlayerPlaylistOption) => void, |
|
|
|
|
players: PlayerPlaylistOptions, |
|
|
|
|
selectedMathPlaylist?: PlaylistOption, |
|
|
|
|
teamName?: Team, |
|
|
|
|
} |
|
|
|
|
@ -24,9 +30,12 @@ const Wrapper = styled.div` |
|
|
|
|
|
|
|
|
|
const List = styled.ul`` |
|
|
|
|
|
|
|
|
|
const PlayersItem = styled(Item)` |
|
|
|
|
margin-top: 10px |
|
|
|
|
const PlayersItem = styled.li` |
|
|
|
|
width: 100%; |
|
|
|
|
height: 50px; |
|
|
|
|
margin-top: 10px; |
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
const Title = styled.span` |
|
|
|
|
font-weight: 300; |
|
|
|
|
font-size: 16px; |
|
|
|
|
@ -35,13 +44,28 @@ const Title = styled.span` |
|
|
|
|
color: #ffffff; |
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
export const PlayersPlaylists = (props: Props) => { |
|
|
|
|
const { |
|
|
|
|
onSelect, |
|
|
|
|
players, |
|
|
|
|
selectedMathPlaylist, |
|
|
|
|
teamName, |
|
|
|
|
} = props |
|
|
|
|
const ShirtNumber = styled.span` |
|
|
|
|
font-weight: bold; |
|
|
|
|
margin-right: 6px; |
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
export const PlayersPlaylists = ({ |
|
|
|
|
onSelect, |
|
|
|
|
players, |
|
|
|
|
selectedMathPlaylist, |
|
|
|
|
teamName, |
|
|
|
|
}: Props) => { |
|
|
|
|
const listRef = useRef<HTMLUListElement>(null) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const found = find( |
|
|
|
|
players, |
|
|
|
|
(player) => isEqual(player, selectedMathPlaylist), |
|
|
|
|
) |
|
|
|
|
if (found) { |
|
|
|
|
listRef.current?.scrollIntoView() |
|
|
|
|
} |
|
|
|
|
}, [players, selectedMathPlaylist]) |
|
|
|
|
|
|
|
|
|
if (!selectedMathPlaylist || !teamName) return null |
|
|
|
|
|
|
|
|
|
@ -50,7 +74,7 @@ export const PlayersPlaylists = (props: Props) => { |
|
|
|
|
<Title> |
|
|
|
|
<Name nameObj={teamName} /> |
|
|
|
|
</Title> |
|
|
|
|
<List> |
|
|
|
|
<List ref={listRef}> |
|
|
|
|
{ |
|
|
|
|
map(players, (player) => ( |
|
|
|
|
<PlayersItem key={player.id}> |
|
|
|
|
@ -58,6 +82,7 @@ export const PlayersPlaylists = (props: Props) => { |
|
|
|
|
onClick={() => onSelect(player)} |
|
|
|
|
active={isEqual(player, selectedMathPlaylist)} |
|
|
|
|
> |
|
|
|
|
<ShirtNumber>{player.num}</ShirtNumber> |
|
|
|
|
<Name nameObj={player} /> |
|
|
|
|
</PlayButton> |
|
|
|
|
</PlayersItem> |
|
|
|
|
|