enh
This commit is contained in:
parent
944ea5fa33
commit
a8b5ba26a9
2 changed files with 14 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -121,9 +121,6 @@ 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 = () => {
|
||||
|
|
@ -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}) => <View key={item.id} style={tw`w-1/2 pr-2 pb-4`}>{children}</View>}
|
||||
key={item.id}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue