import React, { useCallback, useState, useEffect, useRef } from 'react'; import { View, FlatList, ActivityIndicator, RefreshControl, Text } from 'react-native'; import Animated, { FadeInDown, FadeOutUp } from 'react-native-reanimated'; import LiveAuctionTile from './LiveAuctionTile'; import { useFetchLiveAuction } from '../../Services/BBPS/Hooks'; import { SearchInput } from '../../Component/Serach/SeacrhInput'; import { Skelton } from '../../Component/Index'; import colors from '../../Constant/Color'; import { useDispatch, useSelector } from 'react-redux'; import { togglePurchaseAuction } from '../../Redux/Slices/selectPurchaseAuction'; import { apiCall } from '../../Axios/Axios'; import { GET_MY_AUCTION } from '../../Services/BBPS/ApiUrls'; import SkeltonList from '../../Component/Skelton/SkeltonList'; import Skeleton from '../../Component/Skelton/Skelton'; const LiveAuction = () => { const Dispatch = useDispatch() const onEndReachedCalledDuringMomentum = useRef(true); const SelectedPurchaseList = useSelector((state: any) => state.selectPurchaseAuction); const [showRefreshBanner, setShowRefreshBanner] = useState(false); const [allBoolean, setAllBoolean] = useState({ liveAuctionData: [], isLoading: false }) const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isRefetching, refetch, isPending }: any = useFetchLiveAuction(); // My Methods const getMyAuction = async () => { try { setAllBoolean(prev => ({ ...prev, isLoading: true })) const res = await apiCall('get', `${GET_MY_AUCTION}`,); if (res?.statusCode === 200) { const purchasedIds = new Set(res.data.map((item: any) => item.auctionId)); const filteredLive = data?.result.map((item: any) => ({ ...item, active: !purchasedIds.has(item.auctionId) })); setAllBoolean(prev => ({ ...prev, liveAuctionData: filteredLive })); } } catch (error) { console.error('getMyAuction error', error); } finally { setAllBoolean(prev => ({ ...prev, isLoading: false })); } }; const renderItem = useCallback( ({ item, index }: any) => { const isPurchase = SelectedPurchaseList.findIndex((prev: any) => prev.auctionNumber === item.auctionNumber) return { Dispatch(togglePurchaseAuction(item)) }} onDetailsPress={() => { }} /> }, [SelectedPurchaseList] ); const loadMore = useCallback(() => { if (onEndReachedCalledDuringMomentum.current) return; if (!hasNextPage || isFetchingNextPage) return; fetchNextPage(); onEndReachedCalledDuringMomentum.current = true; }, [hasNextPage, isFetchingNextPage, fetchNextPage]); const renderFooter = useCallback(() => { if (!isFetchingNextPage) return null; return ( ); }, [isFetchingNextPage]); useEffect(() => { if (isRefetching) { setShowRefreshBanner(true); } else { const timer = setTimeout(() => { setShowRefreshBanner(false); }, 1000); return () => clearTimeout(timer); } }, [isRefetching]); useEffect(() => { if (data?.result?.length > 0) { getMyAuction() } }, [data]) if (isLoading) { return ; } return ( { }} placeholder="Search...." filter={false} /> {showRefreshBanner && ( Refreshing auctions )} { isPending || allBoolean.isLoading ? : { onEndReachedCalledDuringMomentum.current = false; }} ListFooterComponent={renderFooter} refreshControl={ } initialNumToRender={6} maxToRenderPerBatch={6} windowSize={7} removeClippedSubviews /> } ); }; export default LiveAuction;