All files / widgets/LeagueStatistics/mobile LeagueStatistics.native.tsx

100% Statements 35/35
95.23% Branches 20/21
100% Functions 10/10
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206                    1x       6x 6x 6x 6x   6x         10x 74x     10x 74x   10x   10x   8x   8x   2x   36x       10x 74x           198x                                       6x 6x 6x   6x                                       6x 1x   1x                                       6x 1x   1x                                         6x 2x 2x   2x                                       6x                                     6x                                      
import { cn } from '@sb/libs';
import { FC, ReactNode } from 'react';
import { Tab } from '../../../molecules/tabs';
import { Dimensions, Text, View } from 'react-native';
import { Tabs } from '../../../molecules/tabs/mobile/Tabs.native';
import { LeagueStatisticsProps } from '../LeagueStatistics.types';
import { useThemeColors } from '@sb/hooks/Utilities/useThemeColors';
import { Table } from '../../../organisms/Table/mobile/Table.native';
import { ColumnProps as TableColumn } from '../../../organisms/Table/mobile/Table.native.types';
 
export const LeagueStatistics: FC<LeagueStatisticsProps> = ({
  data,
  error = 'There was an unexpected error retrieving data for this table',
}) => {
  const colClassName = '!px-0 w-full';
  const { themedColors } = useThemeColors();
  const captionClassName = 'font-normal text-lg pl-2 py-1';
  const emptyMessageClassName = 'text-text-main font-normal';
 
  const getTableData = (
    columns: string[],
    isFormTable: boolean = false,
    isMiddleTable: boolean = false
  ): TableColumn[] => {
    const calculateWidth = (fraction: number) => {
      return Dimensions.get('window').width * fraction;
    };
 
    const getColumnWidth = (column: string): number => {
      switch (column) {
        case 'id':
          return calculateWidth(0.09);
        case 'Team':
          return calculateWidth(isMiddleTable ? 0.4 : 0.3);
        case 'Tore':
          return calculateWidth(0.13);
        case 'Pkt':
          return calculateWidth(0.1);
        case 'Form':
          return calculateWidth(0.2);
        default:
          return calculateWidth(isMiddleTable ? 0.2 : isFormTable ? 0.08 : 0.1);
      }
    };
 
    return columns.map((column) => {
      return {
        key: column,
        title:
          column === 'id' || column === 'Team' || (isFormTable && column === 'Form') ? '' : column,
        dataIndex: column,
        render: (value) => (
          <View>
            <Text
              className={cn('truncate text-left font-normal', {
                'w-[25px] pl-1 text-right': column === 'id',
                'pt-0.5': typeof value === 'string',
              })}
              numberOfLines={1}
              ellipsizeMode="tail"
              style={{ color: themedColors.colorText_Main }}
            >
              {value}
            </Text>
          </View>
        ),
        className: 'truncate line-clamp-1',
        width: getColumnWidth(column),
      } as TableColumn;
    });
  };
 
  const Ligatabelle = (): ReactNode => {
    const columns: string[] = ['id', 'Team', 'Sp', 'G', 'U', 'V', 'Tore', 'Pkt'];
    const columnData = getTableData(columns);
 
    return (
      <Table
        id="Ligatabelle"
        variant="striped"
        columns={columnData}
        data={data}
        pageSize={20}
        caption={
          <Text style={{ color: themedColors.colorText_Main }} className={captionClassName}>
            Bundesliga 21/22
          </Text>
        }
        emptyMessage={error}
        emptyMessageClassName={emptyMessageClassName}
        aria-label="League standings table"
        colClassName={colClassName}
      />
    );
  };
 
  const Heim = (): ReactNode => {
    const columnData = getTableData(['id', 'Team', 'G', 'U', 'V'], false, true);
 
    return (
      <Table
        id="heim"
        variant="striped"
        columns={columnData}
        data={data}
        pageSize={20}
        caption={
          <Text style={{ color: themedColors.colorText_Main }} className={captionClassName}>
            Heim
          </Text>
        }
        emptyMessage={error}
        emptyMessageClassName={emptyMessageClassName}
        aria-label="Home statistics table"
        colClassName={colClassName}
      />
    );
  };
 
  const Gast = (): ReactNode => {
    const columnData = getTableData(['id', 'Team', 'G', 'U', 'V'], false, true);
 
    return (
      <Table
        id="gast"
        variant="striped"
        columns={columnData}
        data={data}
        pageSize={20}
        caption={
          <Text style={{ color: themedColors.colorText_Main }} className={captionClassName}>
            Gast
          </Text>
        }
        emptyMessage={error}
        emptyMessageClassName={emptyMessageClassName}
        aria-label="Away statistics table"
        className="w-full"
        colClassName={colClassName}
      />
    );
  };
 
  const Formtabelle = (): ReactNode => {
    const columns: string[] = ['id', 'Team', 'Form', 'G', 'U', 'V', 'Tore', 'Pkt'];
    const columnData = getTableData(columns, true);
 
    return (
      <Table
        data={data}
        pageSize={20}
        id="Formtabelle"
        variant="striped"
        columns={columnData}
        caption={
          <Text style={{ color: themedColors.colorText_Main }} className={captionClassName}>
            Formtabelle
          </Text>
        }
        emptyMessage={error}
        colClassName={colClassName}
        aria-label="Team form statistics table"
        emptyMessageClassName={emptyMessageClassName}
      />
    );
  };
 
  const LeagueStatisticsTabs: Tab[] = [
    {
      label: 'Ligatabelle',
      body: <Ligatabelle />,
    },
    {
      label: 'Heim',
      body: <Heim />,
    },
    {
      label: 'Gast',
      body: <Gast />,
    },
    {
      label: 'Formtabelle',
      body: <Formtabelle />,
    },
  ];
 
  return (
    <View className="h-full w-full" style={{ backgroundColor: themedColors.colorPrimary }}>
      <Text
        className="font-Bold px-2 py-4 text-2xl uppercase"
        style={{ color: themedColors.colorText_Main, backgroundColor: themedColors.colorSecondary }}
      >
        Statistiken
      </Text>
      <View className="h-full w-full">
        <Tabs
          padding="none"
          id="league_statistics_tabs"
          tabs={LeagueStatisticsTabs}
          tabLabelStyle="text-center uppercase w-full"
        />
      </View>
    </View>
  );
};