Browse Source

fix flatlist

Viktoriia 1 year ago
parent
commit
8147846041

+ 17 - 5
src/screens/InAppScreens/TravellersScreen/MasterRankingScreen/index.tsx

@@ -1,4 +1,5 @@
-import React, { useEffect, useState } from 'react';
+import React, { useCallback, useState } from 'react';
+import { useFocusEffect } from '@react-navigation/native';
 import { Header, PageWrapper } from '../../../../components';
 import { getOnlineStatus, storage, StoreType } from '../../../../storage';
 
@@ -11,12 +12,23 @@ import { fetchFullRanking } from '@api/ranking';
 const MasterRankingScreen = () => {
   const [masterRanking, setMasterRanking] = useState<Ranking[]>([]);
   const { mutateAsync } = fetchFullRanking();
+  const [isLoading, setIsLoading] = useState(true);
 
-  const ranking = storage.get('masterRanking', StoreType.STRING) as string;
+  useFocusEffect(
+    useCallback(() => {
+      const fetchRanking = async () => {
+        const ranking = storage.get('masterRanking', StoreType.STRING) as string;
+        setMasterRanking(JSON.parse(ranking).sort((a: Ranking, b: Ranking) => b.score_nm - a.score_nm));
+        setIsLoading(false);
+      };
 
-  useEffect(() => {
-    setMasterRanking(JSON.parse(ranking).sort((a: Ranking, b: Ranking) => b.score_nm - a.score_nm));
-  }, []);
+      fetchRanking();
+    }, [])
+  );
+
+  if (isLoading) {
+    return null;
+  }
 
   const getFullRanking = async () => {
     if (getOnlineStatus()) {

+ 17 - 2
src/screens/RegisterScreen/EditAccount/index.tsx

@@ -1,8 +1,8 @@
-import React from 'react';
+import React, { useCallback, useState } from 'react';
 import { View, ScrollView } from 'react-native';
 import { Formik } from 'formik';
 import * as yup from 'yup';
-import { CommonActions, useNavigation } from '@react-navigation/native';
+import { CommonActions, useFocusEffect, useNavigation } from '@react-navigation/native';
 import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
 
 import { AvatarPicker, BigText, Button, Header, Input, PageWrapper } from '../../../components';
@@ -30,6 +30,21 @@ const EditAccount = () => {
   const [user] = store((state) => [state.registration.user]);
 
   const { data, error, mutate: userRegister } = useRegisterMutation();
+  const [isLoading, setIsLoading] = useState(true);
+
+  useFocusEffect(
+    useCallback(() => {
+      const fetchData = async () => {
+        setIsLoading(false);
+      };
+
+      fetchData();
+    }, [])
+  );
+
+  if (isLoading) {
+    return null;
+  }
 
   if (data) {
     if (data.token) {