Skip to content

Commit

Permalink
fixed: remove console log
Browse files Browse the repository at this point in the history
  • Loading branch information
zzggo committed Feb 18, 2025
1 parent 9615a50 commit d44b1a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
27 changes: 3 additions & 24 deletions src/ui/views/NFT/GridTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ const GridTab = forwardRef((props: GridTabProps, ref) => {

const handleScroll = useCallback(
(e: Event) => {
if (loading) return;
const target = e.target as HTMLElement;
const scrollTop = target.scrollTop;
const direction = scrollTop > lastScrollTop.current ? 'down' : 'up';

if (direction !== scrollDirection) {
console.log('🔄 NFT: Scroll direction changed:', direction);
setScrollDirection(direction);
}
lastScrollTop.current = scrollTop;
},
[scrollDirection]
[loading, scrollDirection]
);

useImperativeHandle(ref, () => ({
Expand All @@ -192,50 +192,29 @@ const GridTab = forwardRef((props: GridTabProps, ref) => {
}));

const nextPage = useCallback(async () => {
console.log('📥 NFT: Attempting to load next page', {
loadingMore,
hasMore,
currentCount: nfts.length,
total,
});

if (loadingMore || !hasMore) {
console.log('⏭️ NFT: Skipping next page - loading or no more items');
return;
}

setLoadingMore(true);
const offset = nfts.length;

try {
console.log('🔄 NFT: Fetching next page with offset:', offset);
const response = await usewallet.refreshNft(ownerAddress, offset);

if (!response || !response.nfts) {
console.log('⚠️ NFT: No response for next page');
return;
}
if (!response || !response.nfts) return;

const newList = response.nfts.filter(
(item) => !nfts.some((nft) => nft.unique_id === item.unique_id)
);

console.log('✨ NFT: New items found:', newList.length);

if (newList.length > 0) {
const mergedList = [...nfts, ...newList];
setNFTs(mergedList);
setHasMore(mergedList.length < total);
console.log('✅ NFT: Updated list', {
newTotal: mergedList.length,
hasMore: mergedList.length < total,
});
} else {
setHasMore(false);
console.log('⏹️ NFT: No new items, stopping infinite scroll');
}
} catch (e) {
console.error('❌ NFT: Next page fetch failed:', e);
setHasMore(false);
} finally {
setLoadingMore(false);
Expand Down
12 changes: 5 additions & 7 deletions src/ui/views/NftEvm/GridTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ const GridTab = forwardRef((props: GridTabProps, ref) => {
const direction = scrollTop > lastScrollTop.current ? 'down' : 'up';

if (direction !== scrollDirection) {
console.log('🔄 EVM: Scroll direction changed:', direction);
setScrollDirection(direction);
}
lastScrollTop.current = scrollTop;
Expand All @@ -191,14 +190,14 @@ const GridTab = forwardRef((props: GridTabProps, ref) => {
},
}));

const nextPage = async () => {
if (loadingMore) {
const nextPage = useCallback(async () => {
if (loadingMore || !hasMore) {
return;
}

setLoadingMore(true);
const offset = nfts.length;
// pageIndex * 24;

try {
const list = await usewallet.openapi.EvmNFTList(ownerAddress);
const newList: any[] = [];
Expand All @@ -210,12 +209,11 @@ const GridTab = forwardRef((props: GridTabProps, ref) => {
});
const mergedList = [...nfts, ...newList];
setNFTs(mergedList);
const hasMore = mergedList.length > 0 && mergedList.length < total;
setHasMore(hasMore);
setHasMore(mergedList.length < total);
} finally {
setLoadingMore(false);
}
};
}, [loadingMore, hasMore, nfts, ownerAddress, total, usewallet]);

const { setCount } = props;

Expand Down

0 comments on commit d44b1a9

Please sign in to comment.