Browse Source

feat: v1 series statistics

Oleksandr Honcharov 1 year ago
parent
commit
47a827ec69

+ 7 - 4
Route.tsx

@@ -26,6 +26,8 @@ import LPIRanking from './src/screens/InAppScreens/TravellersScreen/LPIRankingSc
 import InMemoriamScreen from './src/screens/InAppScreens/TravellersScreen/InMemoriamScreen';
 import InHistoryScreen from './src/screens/InAppScreens/TravellersScreen/InHistoryScreen';
 import UNMastersScreen from './src/screens/InAppScreens/TravellersScreen/UNMasters';
+import StatisticsScreen from './src/screens/InAppScreens/TravellersScreen/StatisticsScreen';
+
 import SeriesScreen from 'src/screens/InAppScreens/TravelsScreen/Series';
 
 import { NAVIGATION_PAGES } from './src/types';
@@ -137,6 +139,10 @@ const Route = () => {
                     name={NAVIGATION_PAGES.UN_MASTERS}
                     component={UNMastersScreen}
                   />
+                  <ScreenStack.Screen
+                    name={NAVIGATION_PAGES.STATISTICS}
+                    component={StatisticsScreen}
+                  />
                   <ScreenStack.Screen
                     name={NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW}
                     component={ProfileScreen}
@@ -151,10 +157,7 @@ const Route = () => {
                     name={NAVIGATION_PAGES.TRAVELS_TAB}
                     component={TravelsScreen}
                   />
-                  <ScreenStack.Screen
-                    name={NAVIGATION_PAGES.SERIES}
-                    component={SeriesScreen}
-                  />
+                  <ScreenStack.Screen name={NAVIGATION_PAGES.SERIES} component={SeriesScreen} />
                   <ScreenStack.Screen
                     name={NAVIGATION_PAGES.SERIES_ITEM}
                     component={SeriesItemScreen}

+ 3 - 5
src/database/statisticsService/index.ts

@@ -67,9 +67,7 @@ export async function fetchAndSaveStatistics(token: string) {
         const statsData = await fetchStatistic(token, item.url1, item.url2 ?? 'null');
 
         if (statsData && statsData.result === 'OK') {
-          const statsKey = item.url2
-            ? `stats_${item.url1}_${item.url2}`
-            : `stats_${item.url1}`;
+          const statsKey = item.url2 ? `stats_${item.url1}_${item.url2}` : `stats_${item.url1}`;
 
           saveData(statsKey, JSON.stringify(statsData.data));
         }
@@ -83,8 +81,8 @@ export function getStatistic(url1: string, url2?: string | null): Statistic | nu
   return loadData<Statistic>(statsKey);
 }
 
-export function getList(): List | null {
-  return loadData<List>('list');
+export function getList(): List[] | null {
+  return loadData<List[]>('list');
 }
 
 interface ListData {

+ 42 - 0
src/screens/InAppScreens/TravellersScreen/StatisticsScreen/index.tsx

@@ -0,0 +1,42 @@
+import React, { useEffect, useState } from 'react';
+import { getList } from '../../../../database/statisticsService';
+import { Header, HorizontalTabView, Loading, PageWrapper } from '../../../../components';
+
+const StatisticsScreen = () => {
+  const [index, setIndex] = useState(0);
+  const [routes, setRoutes] = useState<{ key: string; title: string }[]>([]);
+  const [loading, setLoading] = useState(true);
+
+  useEffect(() => {
+    const types = getList();
+
+    const parseRoutes = types?.map((item) => ({
+      key: item.name,
+      list: item.list,
+      sublist: item.sublists,
+      title: item.name
+    }));
+
+    setRoutes(parseRoutes || []);
+    setLoading(false);
+  }, []);
+
+  if (loading) return <Loading />;
+
+  return (
+    <>
+      <PageWrapper>
+        <Header label={'Statistics'} />
+        <HorizontalTabView
+          index={index}
+          setIndex={setIndex}
+          withMark={true}
+          routes={routes}
+          renderScene={({ route }: { route: { key: string; title: string } }) => <></>}
+        />
+      </PageWrapper>
+    </>
+  );
+};
+
+export default StatisticsScreen;

+ 4 - 1
src/screens/InAppScreens/TravellersScreen/index.tsx

@@ -44,7 +44,10 @@ const buttons: MenuButtonType[] = [
   },
   {
     label: 'Statistics',
-    icon: <ChartPieIcon fill={Colors.DARK_BLUE} width={20} height={20} />
+    icon: <ChartPieIcon fill={Colors.DARK_BLUE} width={20} height={20} />,
+    buttonFn: (navigation) => {
+      navigation.navigate(NAVIGATION_PAGES.STATISTICS);
+    }
   },
   {
     label: 'In Memoriam',

+ 1 - 0
src/types/navigation.ts

@@ -14,6 +14,7 @@ export enum NAVIGATION_PAGES {
   IN_MEMORIAM = 'inAppInMemoriam',
   IN_HISTORY = 'inAppInHistory',
   UN_MASTERS = 'inAppUNMaster',
+  STATISTICS = 'inAppStatistics',
   IN_APP_PROFILE = 'Profile',
   PROFILE_TAB = 'inAppProfile',
   PUBLIC_PROFILE_VIEW = 'publicProfileView',