import { NavigationProp, useFocusEffect, useNavigation, } from '@react-navigation/native'; import {useCallback, useState} from 'react'; import {FlatList, Image} from 'react-native'; import {List} from 'react-native-paper'; import {getBestReps, getBestWeights} from './best.service'; import {BestPageParams} from './BestPage'; import DrawerHeader from './DrawerHeader'; import Page from './Page'; import Set from './set'; import {useSettings} from './use-settings'; export default function BestList() { const [bests, setBests] = useState(); const [term, setTerm] = useState(''); const navigation = useNavigation>(); const {settings} = useSettings(); const refresh = useCallback(async (value: string) => { const weights = await getBestWeights(value); console.log(`${BestList.name}.refresh:`, {length: weights.length}); let newBest: Set[] = []; for (const set of weights) { const reps = await getBestReps(set.name, set.weight); newBest.push(...reps); } setBests(newBest); }, []); useFocusEffect( useCallback(() => { refresh(term); }, [refresh, term]), ); const search = useCallback( (value: string) => { setTerm(value); refresh(value); }, [refresh], ); const renderItem = ({item}: {item: Set}) => ( navigation.navigate('ViewBest', {best: item})} left={() => (settings.images && item.image && ( )) || null } /> ); return ( <> {bests?.length === 0 ? ( ) : ( )} ); }