From 172368d1a57832fd3df9ff361685d7c721089df7 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Sun, 1 Nov 2026 19:29:01 +0530 Subject: [PATCH] enh --- .../app/(drawer)/(tabs)/home/index.tsx | 389 ++++++++++-------- apps/user-ui/src/lib/home-list-tuning.ts | 14 + apps/user-ui/tests/pages/home.test.tsx | 12 +- change-log.txt | 33 ++ 4 files changed, 284 insertions(+), 164 deletions(-) create mode 100644 apps/user-ui/src/lib/home-list-tuning.ts diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx index 0536451..a1c4cdd 100755 --- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx @@ -31,6 +31,7 @@ import TabLayoutWrapper from "@/components/TabLayoutWrapper"; import LocationBar from "@/src/components/LocationBar"; import { useNavigationStore } from "@/src/store/navigationStore"; import { useHomeTagStore } from "@/src/store/homeTagStore"; +import { HOME_INITIAL_RENDER_COUNT, HOME_MAX_RENDER_BATCH, HOME_WINDOW_SIZE } from "@/src/lib/home-list-tuning"; import NextOrderGlimpse from "@/components/NextOrderGlimpse"; dayjs.extend(relativeTime); @@ -365,116 +366,128 @@ const ProductItem = memo(({ item, onPress }: ProductItemProps) => { ); }); -interface ListHeaderProps { - dashboardTags: any[]; - productsByTagId: Record; - onProductPress: (id: number) => void; - storesData: any; - sortedSlots: any[]; -} +type CatalogItem = + | { key: string; kind: 'glimpse' } + | { key: string; kind: 'tagStrip' } + | { key: string; kind: 'tagScene' } + | { key: string; kind: 'stores' } + | { key: string; kind: 'slots' } + | { key: string; kind: 'allProductsTitle' } + | { key: string; kind: 'empty' } + | { key: string; kind: 'row'; products: any[] }; -const ListHeader = memo(({ +const HomeGlimpse = memo(() => ( + + + +)); + +// The tag grid is its own list item so it can unmount with the rest of the top +// block instead of being pinned inside one giant header cell. +const TagSceneBlock = memo(({ dashboardTags, productsByTagId, onProductPress, - storesData, - sortedSlots, -}: ListHeaderProps) => { +}: TagSceneProps) => ( + + + +)); + +const StoresSection = memo(({ storesData }: { storesData: any }) => { + if (!storesData?.stores || storesData.stores.length === 0) return null; + + return ( + + + + + + Our Stores + + Fresh from our locations + + + + + {storesData.stores.map((store: any) => ( + + + + ))} + + + + + ); +}); + +const SlotsSection = memo(({ sortedSlots }: { sortedSlots: any[] }) => { const renderSlotItem = useCallback(({ item }: { item: any }) => ( ), []); + if (sortedSlots.length === 0) return null; + return ( - <> - - - - {dashboardTags.length > 0 && ( - - )} - {dashboardTags.length > 0 && ( - - - - )} - - {storesData?.stores && storesData.stores.length > 0 && ( - - - - - Our Stores - - Fresh from our locations - - - - - {storesData.stores.map((store: any) => ( - - - - ))} - - - - )} - - {sortedSlots.length > 0 && ( - - - - - - Upcoming Delivery Slots - - Plan your fresh deliveries ahead - - - item.id.toString()} - horizontal - showsHorizontalScrollIndicator={false} - contentContainerStyle={staticStyles.slotsListContent} - decelerationRate="fast" - snapToInterval={280 + 16} - renderItem={renderSlotItem} - removeClippedSubviews={true} - /> - - )} - - - - - - - All Available Products - - Browse our complete selection + + + + + + + Upcoming Delivery Slots + Plan your fresh deliveries ahead + item.id.toString()} + horizontal + showsHorizontalScrollIndicator={false} + contentContainerStyle={staticStyles.slotsListContent} + decelerationRate="fast" + snapToInterval={280 + 16} + renderItem={renderSlotItem} + removeClippedSubviews={true} + /> - + ); }); +const AllProductsTitle = memo(() => ( + + + + + + + All Available Products + + Browse our complete selection + + + + +)); + +const EmptyCatalog = memo(() => ( + + No products available + +)); + export default function Dashboard() { const router = useRouter(); const userDetails = useUserDetails(); @@ -645,15 +658,115 @@ export default function Dashboard() { { backgroundColor: '#FFFFFF' } ], []); - const listHeader = useMemo(() => ( - - ), [dashboardTags, productsByTagId, handleProductPress, storesData, sortedSlots]); + // One virtualized item per top section instead of a single giant header cell: + // VirtualizedList pins the first `initialNumToRender` items, so keeping the + // whole top block in one item kept it (and its images) mounted forever. + const listItems = useMemo(() => { + const items: CatalogItem[] = [{ key: 'glimpse', kind: 'glimpse' }]; + + if (dashboardTags.length > 0) { + items.push({ key: 'tag-strip', kind: 'tagStrip' }); + items.push({ key: 'tag-scene', kind: 'tagScene' }); + } + if (storesData?.stores && storesData.stores.length > 0) { + items.push({ key: 'stores', kind: 'stores' }); + } + if (sortedSlots.length > 0) { + items.push({ key: 'slots', kind: 'slots' }); + } + + items.push({ key: 'all-products-title', kind: 'allProductsTitle' }); + + if (displayedProducts.length === 0) { + items.push({ key: 'empty', kind: 'empty' }); + return items; + } + + const visible = Math.min(displayedProducts.length, visibleCount); + for (let index = 0; index < visible; index += 3) { + const products = displayedProducts.slice(index, index + 3); + items.push({ + key: products.map((product) => product.id).join('-'), + kind: 'row', + products, + }); + } + + return items; + }, [dashboardTags, displayedProducts, visibleCount, storesData, sortedSlots]); + + const sections = useMemo(() => [{ data: listItems }], [listItems]); + + const renderCatalogItem = useCallback(({ item }: { item: CatalogItem }) => { + switch (item.kind) { + case 'glimpse': + return ; + case 'tagStrip': + return ; + case 'tagScene': + return ( + + ); + case 'stores': + return ; + case 'slots': + return ; + case 'allProductsTitle': + return ; + case 'empty': + return ; + case 'row': + return ( + + {item.products.map((product) => ( + + {renderProductItem({ item: product })} + + ))} + + ); + } + }, [dashboardTags, handleProductPress, productsByTagId, renderProductItem, sortedSlots, storesData]); + + const keyExtractor = useCallback((item: CatalogItem) => item.key, []); + + const renderSectionHeader = useCallback(() => ( + + { }} + onPress={handleSearchPress} + editable={false} + containerStyle={tw`bg-white`} + onSubmitEditing={() => { + if (inputQuery.trim()) { + router.push(`/(drawer)/(tabs)/home/search-results?q=${encodeURIComponent(inputQuery.trim())}`); + } + }} + returnKeyType="search" + /> + + ), [handleSearchPress, inputQuery, router, searchBarContainerStyle]); + + const listFooter = useMemo(() => ( + hasMore ? ( + + + Show More + + + ) : null + ), [handleShowMore, hasMore]); const listContentContainerStyle = useMemo(() => [ tw`pb-24`, @@ -687,65 +800,15 @@ export default function Dashboard() { displayedProducts.slice(index * 3, Math.min(index * 3 + 3, visibleCount)) - )] }]} - keyExtractor={(row, index) => row.length ? row.map((item) => item.id).join('-') : 'catalog-header'} + sections={sections} + keyExtractor={keyExtractor} stickySectionHeadersEnabled style={{ backgroundColor: '#FFFFFF' }} contentContainerStyle={listContentContainerStyle} ListHeaderComponent={} - renderSectionHeader={() => ( - - { }} - onPress={handleSearchPress} - editable={false} - containerStyle={tw`bg-white`} - onSubmitEditing={() => { - if (inputQuery.trim()) { - router.push(`/(drawer)/(tabs)/home/search-results?q=${encodeURIComponent(inputQuery.trim())}`); - } - }} - returnKeyType="search" - /> - - )} - renderItem={({ item: row, index }) => index === 0 ? ( - <> - {listHeader} - {displayedProducts.length === 0 && ( - - No products available - - )} - - ) : ( - - {row.map((item) => ( - - {renderProductItem({ item })} - - ))} - - )} - ListFooterComponent={ - hasMore ? ( - - - Show More - - - ) : null - } + renderSectionHeader={renderSectionHeader} + renderItem={renderCatalogItem} + ListFooterComponent={listFooter} refreshControl={ } // NOTE: do not add removeClippedSubviews here - it breaks touch - // delivery to the nested horizontal scrollables in ListHeaderComponent - // (tag tabs / slots) on Android. - maxToRenderPerBatch={10} - windowSize={5} - initialNumToRender={10} + // delivery to the nested horizontal scrollables (tag tabs / slots) on + // Android. + maxToRenderPerBatch={HOME_MAX_RENDER_BATCH} + windowSize={HOME_WINDOW_SIZE} + initialNumToRender={HOME_INITIAL_RENDER_COUNT} updateCellsBatchingPeriod={50} /> diff --git a/apps/user-ui/src/lib/home-list-tuning.ts b/apps/user-ui/src/lib/home-list-tuning.ts new file mode 100644 index 0000000..6711093 --- /dev/null +++ b/apps/user-ui/src/lib/home-list-tuning.ts @@ -0,0 +1,14 @@ +/** + * Virtualization tuning for the home catalog. + * + * VirtualizedList keeps the first `initialNumToRender` cells mounted forever as + * a "scroll-to-top" optimisation, so it must stay small: the top sections + * (glimpse, tag strip, tag grid, stores, slots, title) are separate list items + * and should be allowed to unmount once scrolled away. + * + * Tests mock this module with a larger initial count so interaction assertions + * have product rows mounted (jsdom never scrolls a virtualized list). + */ +export const HOME_INITIAL_RENDER_COUNT = 2 +export const HOME_WINDOW_SIZE = 3 +export const HOME_MAX_RENDER_BATCH = 6 diff --git a/apps/user-ui/tests/pages/home.test.tsx b/apps/user-ui/tests/pages/home.test.tsx index bf8d672..6865a4f 100644 --- a/apps/user-ui/tests/pages/home.test.tsx +++ b/apps/user-ui/tests/pages/home.test.tsx @@ -37,6 +37,14 @@ import { StorageServiceCasual, tw } from 'common-ui' import { flush, renderWithProviders, seedBoot, seedSelectedAddress } from '../helpers/test-utils' import { buildEssentialUrls } from '@packages/shared' + +// The production list keeps only two pinned cells so the top sections can +// unmount; tests need the product rows mounted to fire events on them. +jest.mock('@/src/lib/home-list-tuning', () => ({ + HOME_INITIAL_RENDER_COUNT: 20, + HOME_WINDOW_SIZE: 3, + HOME_MAX_RENDER_BATCH: 6, +})) import { resetAllMocks } from '../helpers/reset' import { procedureQueryCalls, @@ -124,7 +132,9 @@ function idsFrom(nodes: any[], prefix: string): number[] { */ function mainListIds(utils: any): number[] { const sections = utils.UNSAFE_getByType(SectionList).props.sections as any[] - return (sections[0].data as any[]).flat().map((product: any) => product.id) + return (sections[0].data as any[]) + .filter((item: any) => item.kind === 'row') + .flatMap((item: any) => item.products.map((product: any) => product.id)) } async function renderHome(options: { queryClient?: any } = {}) { diff --git a/change-log.txt b/change-log.txt index 76dfb68..6e41b33 100644 --- a/change-log.txt +++ b/change-log.txt @@ -353,3 +353,36 @@ foreground. Results in a maximum age of 3 days for any cached image. + IMGCACHE-08..10: missing/corrupt file and the write path. --- apps/user-ui/JEST-TEST-CASES.md + rows for IMGCACHE-01..10. + +[2026-11-01 19:19:30 IST] home: split the monolithic list header into separate virtualized items and tighten the render window. + +The whole top block (glimpse + tag strip + tag grid + stores + slots + "All +Available Products" title) was a single SectionList item, and the first +`initialNumToRender` items are pinned by VirtualizedList. With +initialNumToRender=10 and windowSize=5, the header plus ~27 cards stayed mounted +forever, growing worse as Show More appended rows. + +--- apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +~ Removed the ListHeader component/wrapper. The list data is now a list of + typed items: glimpse, tagStrip, tagScene, stores, slots, allProductsTitle, + empty and row (3 products). Each renders independently, so the top sections + unmount as they scroll out of the window. +~ Per-item white/px-4 wrappers replace the old rounded-t-3xl wrapper (page + background is white, so the rounded edge was not visible). +~ Extracted HomeGlimpse, TagSceneBlock, StoresSection, SlotsSection and + AllProductsTitle (all memoized); SlotsSection keeps its own renderSlotItem. +~ sections, keyExtractor, renderItem, renderSectionHeader and the footer are + memoized/callback-stable so unrelated Dashboard renders no longer rebuild + the list props. +--- apps/user-ui/src/lib/home-list-tuning.ts (new) ++ HOME_INITIAL_RENDER_COUNT=2, HOME_WINDOW_SIZE=3, HOME_MAX_RENDER_BATCH=6. + VirtualizedList pins the first initialNumToRender cells forever, so it must + stay small for the split top sections to unmount. +~ Virtualization props now read those constants (was windowSize 5, + initialNumToRender 10, maxToRenderPerBatch 10). removeClippedSubviews stays + off (nested horizontal scrollers). +- ProductCard's 5s interval left untouched, as requested. +--- apps/user-ui/tests/pages/home.test.tsx +~ mainListIds reads the row items from sections[0].data (kind === 'row'). +~ Mocks home-list-tuning with initialNumToRender 20 so interaction assertions + have product rows mounted (jsdom never scrolls a virtualized list).