diff --git a/apps/backend/src/trpc/user-apis/stores.ts b/apps/backend/src/trpc/user-apis/stores.ts index 4a25a0c..71c900d 100644 --- a/apps/backend/src/trpc/user-apis/stores.ts +++ b/apps/backend/src/trpc/user-apis/stores.ts @@ -105,6 +105,7 @@ export const storesRouter = router({ isOutOfStock: productInfo.isOutOfStock, incrementStep: productInfo.incrementStep, unitShortNotation: units.shortNotation, + unitNotation: units.shortNotation, productQuantity: productInfo.productQuantity, }) .from(productInfo) @@ -122,6 +123,7 @@ export const storesRouter = router({ marketPrice: product.marketPrice, incrementStep: product.incrementStep, unit: product.unitShortNotation, + unitNotation: product.unitNotation, images: await generateSignedUrlsFromS3Urls((product.images as string[]) || []), isOutOfStock: product.isOutOfStock, productQuantity: product.productQuantity diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx index 9d28137..834e02a 100755 --- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx @@ -121,10 +121,7 @@ export default function Dashboard() { const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery(); const products = productsData?.products || []; - const dashboardTags = tagsData?.tags || []; - const defaultAddress = defaultAddressResponse?.data; - const { getQuickestSlot } = useProductSlotIdentifier(); - + // Function to load more products const loadMoreProducts = () => { if (!hasMore || isLoadingMore) return; @@ -133,7 +130,7 @@ export default function Dashboard() { // Simulate loading more products by taking the next batch // In a real app, you would make an API call with pagination params - setTimeout(() => { + // setTimeout(() => { const batchSize = 10; const startIndex = page * batchSize; const endIndex = startIndex + batchSize; @@ -141,6 +138,11 @@ export default function Dashboard() { // Get the next batch of products const nextBatch = products.slice(startIndex, endIndex); + const oldBatchIds = displayedProducts.map(p => p.id) + const nextBatchIds = nextBatch.map(p => p.id) + const productIds = products.map(p => p.id); + + if (nextBatch.length > 0) { setDisplayedProducts(prev => [...prev, ...nextBatch]); setPage(prev => prev + 1); @@ -150,21 +152,18 @@ export default function Dashboard() { } setIsLoadingMore(false); - }, 500); // Simulate network delay + // }, 500); // Simulate network delay }; // Initialize with the first batch of products React.useEffect(() => { - if (products.length > 0) { + if (products.length > 0 && displayedProducts.length === 0) { const initialBatch = products.slice(0, 10); // First 10 products setDisplayedProducts(initialBatch); setHasMore(products.length > 10); setPage(1); - } else { - setDisplayedProducts([]); - setHasMore(false); - } - }, [products]); + } + }, [productsData]); // Extract popular items IDs as an array to preserve order const popularItemIds = (() => { @@ -606,6 +605,7 @@ export default function Dashboard() { miniView={false} nullIfNotAvailable={true} containerComp={({children}) => {children}} + key={item.id} /> ))}