|
@@ -1,7 +1,20 @@
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
-import { getList } from '../../../../database/statisticsService';
|
|
|
+import {
|
|
|
+ getList,
|
|
|
+ getStatistic,
|
|
|
+ StatisticType,
|
|
|
+ Type2,
|
|
|
+ Type1,
|
|
|
+ Type3
|
|
|
+} from '../../../../database/statisticsService';
|
|
|
import { Header, HorizontalTabView, Loading, PageWrapper } from '../../../../components';
|
|
|
|
|
|
+import { FlatList, Text, View } from 'react-native';
|
|
|
+import { Colors } from '../../../../theme';
|
|
|
+import { getFontSize } from '../../../../utils';
|
|
|
+import { Image } from 'expo-image';
|
|
|
+import { API_HOST } from '../../../../constants';
|
|
|
+
|
|
|
const StatisticsScreen = () => {
|
|
|
const [index, setIndex] = useState(0);
|
|
|
const [routes, setRoutes] = useState<{ key: string; title: string }[]>([]);
|
|
@@ -32,11 +45,151 @@ const StatisticsScreen = () => {
|
|
|
setIndex={setIndex}
|
|
|
withMark={true}
|
|
|
routes={routes}
|
|
|
- renderScene={({ route }: { route: { key: string; title: string } }) => <></>}
|
|
|
+ renderScene={({ route }: Data) => <StatisticsList list={route.list} />}
|
|
|
+ onDoubleClick={() => console.log('double click')}
|
|
|
/>
|
|
|
</PageWrapper>
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+const StatisticsList = React.memo(({ list }: { list: { name: string; url1: string }[] }) => {
|
|
|
+ const [isLoading, setIsLoading] = useState(true);
|
|
|
+ const [statistic, setStatistic] = useState<StatisticType | null>(null);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const data = getStatistic(list ? list[0]?.url1 : '');
|
|
|
+
|
|
|
+ if (!data) return;
|
|
|
+
|
|
|
+ setStatistic(JSON.parse(data as unknown as string) as unknown as StatisticType);
|
|
|
+ setIsLoading(false);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ if (isLoading) return <Loading />;
|
|
|
+ if (!statistic) return null;
|
|
|
+
|
|
|
+ const renderItem = ({ item, index }: { index: number; item: Type1 | Type2 | Type3 }) => {
|
|
|
+ if ('region_id' in item) {
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ display: 'flex',
|
|
|
+ alignItems: 'center',
|
|
|
+ flexDirection: 'row',
|
|
|
+ flex: 1,
|
|
|
+ gap: 8
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text style={{ color: Colors.DARK_BLUE, fontSize: getFontSize(18), fontWeight: '700' }}>
|
|
|
+ {index + 1}
|
|
|
+ </Text>
|
|
|
+ <Image
|
|
|
+ style={{ width: 36, height: 36, borderRadius: 18 }}
|
|
|
+ source={{ uri: API_HOST + '/img/flags_new/' + item.flag }}
|
|
|
+ />
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ display: 'flex',
|
|
|
+ flexDirection: 'row',
|
|
|
+ justifyContent: 'space-between',
|
|
|
+ alignItems: 'center'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text style={{ width: '75%', color: Colors.DARK_BLUE, fontWeight: '700' }}>
|
|
|
+ {item.region_name}
|
|
|
+ </Text>
|
|
|
+ <Text style={{ color: Colors.DARK_BLUE, fontWeight: '700' }}>{item.cnt}</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ } else if ('mega_id' in item) {
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ display: 'flex',
|
|
|
+ alignItems: 'center',
|
|
|
+ flexDirection: 'row',
|
|
|
+ flex: 1,
|
|
|
+ gap: 8
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text style={{ color: Colors.DARK_BLUE, fontSize: getFontSize(18), fontWeight: '700' }}>
|
|
|
+ {index + 1}
|
|
|
+ </Text>
|
|
|
+ <Image
|
|
|
+ style={{ width: 36, height: 36, borderRadius: 18 }}
|
|
|
+ source={{ uri: API_HOST + '/img/flags_new/' + item.dare_flag }}
|
|
|
+ />
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flex: 1,
|
|
|
+ display: 'flex',
|
|
|
+ flexDirection: 'row',
|
|
|
+ justifyContent: 'space-between',
|
|
|
+ alignItems: 'center'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text style={{ width: '75%', color: Colors.DARK_BLUE, fontWeight: '700' }}>
|
|
|
+ {item.dare_name}
|
|
|
+ </Text>
|
|
|
+ <Text style={{ color: Colors.DARK_BLUE, fontWeight: '700' }}>{item.cnt}</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ } else if ('user' in item) {
|
|
|
+ return (
|
|
|
+ <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
|
|
|
+ <Text>
|
|
|
+ {item.first_name} {item.last_name}
|
|
|
+ </Text>
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ width: '100%',
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+ marginTop: 10,
|
|
|
+ marginBottom: 10
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(16),
|
|
|
+ fontWeight: '700',
|
|
|
+ textAlign: 'center'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {statistic?.name}
|
|
|
+ </Text>
|
|
|
+ </View>
|
|
|
+ <FlatList
|
|
|
+ contentContainerStyle={{ gap: 10 }}
|
|
|
+ horizontal={false}
|
|
|
+ data={statistic.ranking}
|
|
|
+ renderItem={renderItem}
|
|
|
+ showsVerticalScrollIndicator={false}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+});
|
|
|
+
|
|
|
+type Data = {
|
|
|
+ route: {
|
|
|
+ key: string;
|
|
|
+ title: string;
|
|
|
+ list: { name: string; url1: string }[];
|
|
|
+ sublist: [] | undefined;
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
export default StatisticsScreen;
|