index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { useCallback, useState } from 'react';
  2. import { FlatList } from 'react-native';
  3. import { useFocusEffect } from '@react-navigation/native';
  4. import { Header, Loading, PageWrapper } from '../../../../components';
  5. import { storage, StoreType } from '../../../../storage';
  6. import { Profile } from '../Components/Profile';
  7. import type { Ranking } from '..';
  8. const LPIRankingScreen = () => {
  9. const [LPIRanking, setLPIRanking] = useState<Ranking[]>([]);
  10. const [isLoading, setIsLoading] = useState(true);
  11. useFocusEffect(
  12. useCallback(() => {
  13. const fetchRanking = async () => {
  14. const lpi: string = storage.get('lpiRanking', StoreType.STRING) as string;
  15. setLPIRanking(JSON.parse(lpi).sort((a: Ranking, b: Ranking) => b.score_nm - a.score_nm));
  16. setIsLoading(false);
  17. };
  18. fetchRanking();
  19. }, [])
  20. );
  21. if (isLoading) return <Loading />;
  22. return (
  23. <PageWrapper>
  24. <FlatList
  25. data={LPIRanking}
  26. showsVerticalScrollIndicator={false}
  27. ListHeaderComponent={<Header label="LPI Ranking" />}
  28. keyExtractor={(item) => item.user_id.toString()}
  29. onEndReachedThreshold={0.1}
  30. renderItem={({ item, index }) => (
  31. <Profile
  32. key={index}
  33. index={index}
  34. first_name={item.first_name}
  35. last_name={item.last_name}
  36. avatar={item.avatar}
  37. date_of_birth={item.age}
  38. homebase_flag={item.flag1}
  39. homebase2_flag={item.flag2}
  40. score={[
  41. item.score_nm,
  42. item.score_dare,
  43. item.score_un,
  44. item.score_unp,
  45. item.score_tcc,
  46. item.score_yes,
  47. item.score_slow,
  48. item.score_whs,
  49. item.score_kye
  50. ]}
  51. tbt_score={item.score_tbt}
  52. tbt_rank={item.rank_tbt}
  53. badge_tbt={item.badge_tbt}
  54. badge_1281={item.badge_1281}
  55. badge_un={item.badge_un}
  56. auth={item.auth}
  57. />
  58. )}
  59. />
  60. </PageWrapper>
  61. );
  62. };
  63. export default LPIRankingScreen;