|
@@ -1,26 +1,21 @@
|
|
|
-import React, { useCallback, useState } from 'react';
|
|
|
-import { FlatList, View, Text } from 'react-native';
|
|
|
-import { Image } from 'expo-image';
|
|
|
+import React, { FC, useCallback, useState } from 'react';
|
|
|
+import { FlatList, Text } from 'react-native';
|
|
|
import { useFocusEffect } from '@react-navigation/native';
|
|
|
|
|
|
+import { RenderItem } from '../Components/StatisticRouter';
|
|
|
+
|
|
|
import { Header, Loading, PageWrapper } from '../../../../components';
|
|
|
-import { getStatistic, StatisticType, ListType } from '../../../../database/statisticsService';
|
|
|
-import { API_HOST } from '../../../../constants';
|
|
|
-import { Colors } from '../../../../theme';
|
|
|
-import { getFontSize } from '../../../../utils';
|
|
|
-import {
|
|
|
- isType1,
|
|
|
- isType2,
|
|
|
- isType3,
|
|
|
- isType4,
|
|
|
- isType5,
|
|
|
- isType6,
|
|
|
- isType7,
|
|
|
- isType8,
|
|
|
- isType9
|
|
|
-} from './temp';
|
|
|
+import { getStatistic, StatisticType } from '../../../../database/statisticsService';
|
|
|
+
|
|
|
+import { ItemStyles } from '../Components/styles';
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ route: { params: { title: string; url1: string; url2: string | null } };
|
|
|
+};
|
|
|
+
|
|
|
+//TODO: For future fix types
|
|
|
|
|
|
-const StatisticsListScreen = ({ route }) => {
|
|
|
+const StatisticsListScreen: FC<Props> = ({ route }) => {
|
|
|
const title = route.params.title;
|
|
|
const url1 = route.params.url1;
|
|
|
const url2 = route.params.url2;
|
|
@@ -46,161 +41,17 @@ const StatisticsListScreen = ({ route }) => {
|
|
|
if (isLoading) return <Loading />;
|
|
|
if (!statistic) return null;
|
|
|
|
|
|
- const Item = (data: { name: string; flag: string; cnt: number | string; index: number }) => (
|
|
|
- <View
|
|
|
- style={{
|
|
|
- display: 'flex',
|
|
|
- alignItems: 'center',
|
|
|
- flexDirection: 'row',
|
|
|
- flex: 1,
|
|
|
- gap: 8
|
|
|
- }}
|
|
|
- >
|
|
|
- <Text style={{ color: Colors.DARK_BLUE, fontSize: getFontSize(18), fontWeight: '700' }}>
|
|
|
- {data.index + 1}
|
|
|
- </Text>
|
|
|
- <Image
|
|
|
- style={{ width: 36, height: 36, borderRadius: 18 }}
|
|
|
- source={{ uri: API_HOST + '/img/flags_new/' + data.flag }}
|
|
|
- />
|
|
|
- <View
|
|
|
- style={{
|
|
|
- flex: 1,
|
|
|
- display: 'flex',
|
|
|
- flexDirection: 'row',
|
|
|
- justifyContent: 'space-between',
|
|
|
- alignItems: 'center'
|
|
|
- }}
|
|
|
- >
|
|
|
- <Text style={{ width: '75%', color: Colors.DARK_BLUE, fontWeight: '700' }}>
|
|
|
- {data.name}
|
|
|
- </Text>
|
|
|
- <Text style={{ color: Colors.DARK_BLUE, fontWeight: '700' }}>{data.cnt}</Text>
|
|
|
- </View>
|
|
|
- </View>
|
|
|
- );
|
|
|
-
|
|
|
- const renderItem = ({ item, index }: { index: number; item: ListType }) => {
|
|
|
- if (isType1(item) || isType4(item) || isType5(item)) {
|
|
|
- return (
|
|
|
- <>
|
|
|
- {'megaregion' in item && (
|
|
|
- <View>
|
|
|
- {item.megaregion !== statistic.ranking[index - 1]?.megaregion ? (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
- fontSize: getFontSize(14),
|
|
|
- fontWeight: '700',
|
|
|
- textAlign: 'center',
|
|
|
- marginTop: 10,
|
|
|
- marginBottom: 15
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.megaregion as string}
|
|
|
- </Text>
|
|
|
- ) : null}
|
|
|
- </View>
|
|
|
- )}
|
|
|
- <Item cnt={item.cnt} flag={item.flag} index={index} name={item.region_name} />
|
|
|
- </>
|
|
|
- );
|
|
|
- } else if (isType6(item)) {
|
|
|
- return (
|
|
|
- <>
|
|
|
- <View>
|
|
|
- {item.country !== statistic.ranking[index - 1]?.country ? (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
- fontSize: getFontSize(14),
|
|
|
- fontWeight: '700',
|
|
|
- textAlign: 'center',
|
|
|
- marginTop: 10,
|
|
|
- marginBottom: 15
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.country}
|
|
|
- </Text>
|
|
|
- ) : null}
|
|
|
- </View>
|
|
|
- <Item cnt={item.cnt} flag={item.region_flag} index={index} name={item.region} />
|
|
|
- </>
|
|
|
- );
|
|
|
- } else if (isType2(item)) {
|
|
|
- return (
|
|
|
- <>
|
|
|
- <View>
|
|
|
- {item.mega_name !== statistic.ranking[index - 1]?.mega_name ? (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
- fontSize: getFontSize(14),
|
|
|
- fontWeight: '700',
|
|
|
- textAlign: 'center',
|
|
|
- marginTop: 10,
|
|
|
- marginBottom: 15
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.mega_name as string}
|
|
|
- </Text>
|
|
|
- ) : null}
|
|
|
- </View>
|
|
|
- <Item name={item.dare_name} flag={item.dare_flag} cnt={item.cnt} index={index} />
|
|
|
- </>
|
|
|
- );
|
|
|
- } else if (isType7(item)) {
|
|
|
- return <Item name={item.country_name} flag={item.flag} cnt={item.cnt} index={index} />;
|
|
|
- } else if (isType8(item)) {
|
|
|
- return (
|
|
|
- <>
|
|
|
- <View>
|
|
|
- {item.mega_name !== statistic.ranking[index - 1]?.mega_name ? (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
- fontSize: getFontSize(14),
|
|
|
- fontWeight: '700',
|
|
|
- textAlign: 'center',
|
|
|
- marginTop: 10,
|
|
|
- marginBottom: 15
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.mega_name as string}
|
|
|
- </Text>
|
|
|
- ) : null}
|
|
|
- <Item name={item.country} flag={item.flag} cnt={item.cnt} index={index} />
|
|
|
- </View>
|
|
|
- </>
|
|
|
- );
|
|
|
- } else if (isType9(item)) {
|
|
|
- return <Item name={item.nation} flag={item.flag} cnt={item.score} index={index} />;
|
|
|
- } else
|
|
|
- return (
|
|
|
- <>
|
|
|
- <Item
|
|
|
- name={item.nation ? item.nation : `${item.first_name} ${item.last_name}`}
|
|
|
- flag={item.flag}
|
|
|
- cnt={item.score ? item.score : item.cnt}
|
|
|
- index={index}
|
|
|
- />
|
|
|
- </>
|
|
|
- );
|
|
|
- };
|
|
|
-
|
|
|
return (
|
|
|
<PageWrapper>
|
|
|
<Header label={title} />
|
|
|
- {statistic.comment && (
|
|
|
- <Text style={{ color: Colors.DARK_BLUE, textAlign: 'center', marginBottom: 15 }}>
|
|
|
- {statistic.comment}
|
|
|
- </Text>
|
|
|
- )}
|
|
|
+ {statistic.comment && <Text style={ItemStyles.comment}>{statistic.comment}</Text>}
|
|
|
<FlatList
|
|
|
contentContainerStyle={{ gap: 10 }}
|
|
|
horizontal={false}
|
|
|
data={statistic.ranking}
|
|
|
- renderItem={renderItem}
|
|
|
+ renderItem={({ item, index }) => (
|
|
|
+ <RenderItem item={item} index={index} ranking={statistic?.ranking} />
|
|
|
+ )}
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
/>
|
|
|
</PageWrapper>
|