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,
|
isOutOfStock: productInfo.isOutOfStock,
|
||||||
incrementStep: productInfo.incrementStep,
|
incrementStep: productInfo.incrementStep,
|
||||||
unitShortNotation: units.shortNotation,
|
unitShortNotation: units.shortNotation,
|
||||||
|
unitNotation: units.shortNotation,
|
||||||
productQuantity: productInfo.productQuantity,
|
productQuantity: productInfo.productQuantity,
|
||||||
})
|
})
|
||||||
.from(productInfo)
|
.from(productInfo)
|
||||||
|
|
@ -122,6 +123,7 @@ export const storesRouter = router({
|
||||||
marketPrice: product.marketPrice,
|
marketPrice: product.marketPrice,
|
||||||
incrementStep: product.incrementStep,
|
incrementStep: product.incrementStep,
|
||||||
unit: product.unitShortNotation,
|
unit: product.unitShortNotation,
|
||||||
|
unitNotation: product.unitNotation,
|
||||||
images: await generateSignedUrlsFromS3Urls((product.images as string[]) || []),
|
images: await generateSignedUrlsFromS3Urls((product.images as string[]) || []),
|
||||||
isOutOfStock: product.isOutOfStock,
|
isOutOfStock: product.isOutOfStock,
|
||||||
productQuantity: product.productQuantity
|
productQuantity: product.productQuantity
|
||||||
|
|
|
||||||
|
|
@ -121,9 +121,6 @@ export default function Dashboard() {
|
||||||
const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
|
const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
|
||||||
|
|
||||||
const products = productsData?.products || [];
|
const products = productsData?.products || [];
|
||||||
const dashboardTags = tagsData?.tags || [];
|
|
||||||
const defaultAddress = defaultAddressResponse?.data;
|
|
||||||
const { getQuickestSlot } = useProductSlotIdentifier();
|
|
||||||
|
|
||||||
// Function to load more products
|
// Function to load more products
|
||||||
const loadMoreProducts = () => {
|
const loadMoreProducts = () => {
|
||||||
|
|
@ -133,7 +130,7 @@ export default function Dashboard() {
|
||||||
|
|
||||||
// Simulate loading more products by taking the next batch
|
// Simulate loading more products by taking the next batch
|
||||||
// In a real app, you would make an API call with pagination params
|
// In a real app, you would make an API call with pagination params
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
const batchSize = 10;
|
const batchSize = 10;
|
||||||
const startIndex = page * batchSize;
|
const startIndex = page * batchSize;
|
||||||
const endIndex = startIndex + batchSize;
|
const endIndex = startIndex + batchSize;
|
||||||
|
|
@ -141,6 +138,11 @@ export default function Dashboard() {
|
||||||
// Get the next batch of products
|
// Get the next batch of products
|
||||||
const nextBatch = products.slice(startIndex, endIndex);
|
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) {
|
if (nextBatch.length > 0) {
|
||||||
setDisplayedProducts(prev => [...prev, ...nextBatch]);
|
setDisplayedProducts(prev => [...prev, ...nextBatch]);
|
||||||
setPage(prev => prev + 1);
|
setPage(prev => prev + 1);
|
||||||
|
|
@ -150,21 +152,18 @@ export default function Dashboard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoadingMore(false);
|
setIsLoadingMore(false);
|
||||||
}, 500); // Simulate network delay
|
// }, 500); // Simulate network delay
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize with the first batch of products
|
// Initialize with the first batch of products
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (products.length > 0) {
|
if (products.length > 0 && displayedProducts.length === 0) {
|
||||||
const initialBatch = products.slice(0, 10); // First 10 products
|
const initialBatch = products.slice(0, 10); // First 10 products
|
||||||
setDisplayedProducts(initialBatch);
|
setDisplayedProducts(initialBatch);
|
||||||
setHasMore(products.length > 10);
|
setHasMore(products.length > 10);
|
||||||
setPage(1);
|
setPage(1);
|
||||||
} else {
|
|
||||||
setDisplayedProducts([]);
|
|
||||||
setHasMore(false);
|
|
||||||
}
|
}
|
||||||
}, [products]);
|
}, [productsData]);
|
||||||
|
|
||||||
// Extract popular items IDs as an array to preserve order
|
// Extract popular items IDs as an array to preserve order
|
||||||
const popularItemIds = (() => {
|
const popularItemIds = (() => {
|
||||||
|
|
@ -606,6 +605,7 @@ export default function Dashboard() {
|
||||||
miniView={false}
|
miniView={false}
|
||||||
nullIfNotAvailable={true}
|
nullIfNotAvailable={true}
|
||||||
containerComp={({children}) => <View key={item.id} style={tw`w-1/2 pr-2 pb-4`}>{children}</View>}
|
containerComp={({children}) => <View key={item.id} style={tw`w-1/2 pr-2 pb-4`}>{children}</View>}
|
||||||
|
key={item.id}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue