|
@@ -1,30 +1,31 @@
|
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
-import { Header, PageWrapper } from '../../../../components';
|
|
|
+import React, { useCallback, useState } from 'react';
|
|
|
+import { FlatList } from 'react-native';
|
|
|
+import { useFocusEffect } from '@react-navigation/native';
|
|
|
+
|
|
|
+import { Header, Loading, PageWrapper } from '../../../../components';
|
|
|
import { storage, StoreType } from '../../../../storage';
|
|
|
|
|
|
import { Profile } from '../Components/Profile';
|
|
|
|
|
|
-import { Ranking } from '../Ranking';
|
|
|
-import { FlatList } from 'react-native';
|
|
|
-import { fetchFullRanking } from '@api/ranking';
|
|
|
+import type { Ranking } from '..';
|
|
|
|
|
|
const LPIRankingScreen = () => {
|
|
|
const [LPIRanking, setLPIRanking] = useState<Ranking[]>([]);
|
|
|
- const { mutateAsync } = fetchFullRanking();
|
|
|
+ const [isLoading, setIsLoading] = useState(true);
|
|
|
|
|
|
- const lpi: string = storage.get('lpiRanking', StoreType.STRING) as string;
|
|
|
+ useFocusEffect(
|
|
|
+ useCallback(() => {
|
|
|
+ const fetchRanking = async () => {
|
|
|
+ const lpi: string = storage.get('lpiRanking', StoreType.STRING) as string;
|
|
|
+ setLPIRanking(JSON.parse(lpi).sort((a: Ranking, b: Ranking) => b.score_nm - a.score_nm));
|
|
|
+ setIsLoading(false);
|
|
|
+ };
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- setLPIRanking(JSON.parse(lpi).sort((a: Ranking, b: Ranking) => b.score_nm - a.score_nm));
|
|
|
- }, []);
|
|
|
+ fetchRanking();
|
|
|
+ }, [])
|
|
|
+ );
|
|
|
|
|
|
- const getFullRanking = async () => {
|
|
|
- await mutateAsync(undefined, {
|
|
|
- onSuccess: (data) => {
|
|
|
- setLPIRanking(data.data);
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
+ if (isLoading) return <Loading />;
|
|
|
|
|
|
return (
|
|
|
<PageWrapper>
|
|
@@ -33,6 +34,7 @@ const LPIRankingScreen = () => {
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
ListHeaderComponent={<Header label="LPI Ranking" />}
|
|
|
keyExtractor={(item) => item.user_id.toString()}
|
|
|
+ onEndReachedThreshold={0.1}
|
|
|
renderItem={({ item, index }) => (
|
|
|
<Profile
|
|
|
key={index}
|
|
@@ -62,8 +64,6 @@ const LPIRankingScreen = () => {
|
|
|
auth={item.auth}
|
|
|
/>
|
|
|
)}
|
|
|
- onEndReached={() => getFullRanking()}
|
|
|
- onEndReachedThreshold={0.1}
|
|
|
/>
|
|
|
</PageWrapper>
|
|
|
);
|