index.tsx 2.17 KB
import { get } from 'lodash/fp';
import React from 'react';
import { StyleSheet } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import abbreviatePlayerPositon from '../../../../helpers/abbreviatePlayerPositon';
import {
  Column,
  ItemRow,
  PlayerColumn,
  PriceWithTrendColumn
} from '../../../ListGrid';
import { CardHeight } from '../../../player-card/constants';
import { BorderRadius } from '../../constants';

interface Props {
  data: PlayerEdge;
  isOwned: boolean;
  activeSort: string;
  onPress: () => any;
}

const styles = StyleSheet.create({
  itemWrapper: {
    height: CardHeight,
    borderRadius: BorderRadius
  },
  player: {
    justifyContent: 'center',
    width: '100%'
  },
  column: {
    justifyContent: 'center',
    alignItems: 'center'
  },
  priceTrend: {
    justifyContent: 'center',
    alignItems: 'center'
  }
});

const Item: React.FC<Props> = ({
  data: { node: playerNode },
  onPress,
  activeSort,
  isOwned
}: Props) => (
  <TouchableOpacity onPress={onPress}>
    <ItemRow style={styles.itemWrapper} key={playerNode?.id}>
      <PlayerColumn
        isOwned={isOwned}
        name={`${playerNode?.firstName} ${playerNode?.lastName}`}
        position={abbreviatePlayerPositon(playerNode?.playerPositions)}
        team={get('team.abbreviation', playerNode)}
        rating={4.3}
        size={4}
        style={styles.player}
      />
      <Column
        size={2}
        style={styles.column}
        color={activeSort === 'rank' && 'info'}
      >
        {playerNode?.rank}
      </Column>
      <Column
        size={2.5}
        style={styles.column}
        color={activeSort === 'fantasyPoints' && 'info'}
      >
        {playerNode?.fantasyPoints}
      </Column>
      <Column
        size={2.5}
        style={styles.column}
        color={activeSort === 'fantasyPointsPerGame' && 'info'}
      >
        {playerNode?.fantasyPointsPerGame}
      </Column>
      <PriceWithTrendColumn
        rise
        size={2.3}
        style={styles.priceTrend}
        height={45}
        current={playerNode?.value}
        color={activeSort === 'value' && 'info'}
      />
    </ItemRow>
  </TouchableOpacity>
);

export default Item;