This commit is contained in:
shafi54 2026-10-16 20:46:28 +05:30
parent 64ef5d8ea6
commit 60952bfefb
5 changed files with 175 additions and 42 deletions

View file

@ -148,6 +148,9 @@ const LocationTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
<View style={tw`flex-1 bg-white`}>
<LocationFallbackFlow
notice={locationNotice}
// Startup gate: no region yet, so nothing is chosen — don't mark a card as
// selected, or it reads as "already done" instead of "tap to continue".
highlightActiveAddress={false}
onOpenSettings={
locationStatus === 'services-off' || locationStatus === 'denied'
? openLocationSettings

View file

@ -29,6 +29,12 @@ import { LinearGradient } from "expo-linear-gradient";
const { height: screenHeight } = Dimensions.get("window");
// Height of the expanded "Your Cart" sheet: the full 80% of the screen the dialog
// allows. Deliberate (not a max) so the items list below can be `flex-1`: it takes
// exactly the leftover space and scrolls while the Subtotal / "Go to cart" footer
// stays pinned at the bottom of the sheet.
const CART_SHEET_HEIGHT = screenHeight * 0.8;
const formatQuantity = (quantity: number, unit: string): { value: string; display: string } => {
if (unit?.toLowerCase() === 'kg' && quantity < 1) {
return { value: `${Math.round(quantity * 1000)} g`, display: `${Math.round(quantity * 1000)}g` };
@ -225,7 +231,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
)}
</View>
<BottomDialog open={isExpanded} onClose={() => setIsExpanded(false)} enableDismiss={true}>
<ScrollView style={{ maxHeight: Dimensions.get('window').height * 0.8 }}>
<View style={{ height: CART_SHEET_HEIGHT }}>
{/* Header */}
<View style={tw`px-6 py-5 border-b border-slate-100 flex-row items-center justify-between`}>
<View>
@ -365,7 +371,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
</ScrollView>
{/* Fancy Footer */}
<View style={tw`p-6 bg-white border-t border-slate-100`}>
<View style={tw`px-6 pt-6 pb-2 bg-white border-t border-slate-100`}>
<View style={tw`flex-row justify-between items-center mb-5`}>
<View>
<MyText style={tw`text-slate-400 text-[10px] font-black uppercase tracking-widest`}>Subtotal</MyText>
@ -400,7 +406,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
</LinearGradient>
</MyTouchableOpacity>
</View>
</ScrollView>
</View>
</BottomDialog>
</>
);

View file

@ -1,5 +1,5 @@
import React, { useState, useMemo, useEffect } from 'react';
import { View, ScrollView } from 'react-native';
import { View, ScrollView, Dimensions } from 'react-native';
import { useRouter } from 'expo-router';
import { tw, BottomDialog, MyText, MyTouchableOpacity, Quantifier } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
@ -11,6 +11,12 @@ import { useGetEssentialConsts, useSlots } from '@/src/hooks/prominent-api-hooks
import dayjs from 'dayjs';
import { SafeAreaView } from 'react-native-safe-area-context';
// Height of the sheet's content box: the full 80% of the screen the dialog allows.
// Deliberate (not a max): the slot list is `flex-1`, so a definite height is what
// lets it take exactly the leftover space and scroll while the quantity row and the
// Cancel / Add to Cart row stay pinned at the bottom of the sheet.
const SHEET_HEIGHT = Dimensions.get('window').height * 0.8;
const formatTimeRange = (deliveryTime: string) => {
const time = dayjs(deliveryTime);
const endTime = time.add(1, 'hour');
@ -155,8 +161,10 @@ export default function AddToCartDialog() {
return (
<BottomDialog open={isOpen} onClose={clearAddedToCartProduct}>
<SafeAreaView>
<View style={tw`p-6 max-h-[650px]`}>
{/* Bottom sheet: only the bottom inset matters here — a top inset would just
add dead space between the handle and the header. */}
<SafeAreaView edges={['bottom']}>
<View style={[tw`p-6`, { height: SHEET_HEIGHT }]}>
<View style={tw`flex-row items-center mb-2`}>
<View style={tw`w-10 h-10 bg-blue-50 rounded-full items-center justify-center mr-3`}>
<MaterialIcons name="schedule" size={20} color="#3B82F6" />
@ -171,7 +179,10 @@ export default function AddToCartDialog() {
</View>
</View>
<ScrollView showsVerticalScrollIndicator={false}>
{/* The only scrolling region: this shrinks to whatever space is left in
the capped box above, so the quantity row and the Cancel / Add to
Cart row underneath it never move. */}
<ScrollView style={tw`flex-1`} showsVerticalScrollIndicator={false}>
{availableSlots.map((slot: any) => (
<MyTouchableOpacity
key={slot.id}
@ -197,38 +208,38 @@ export default function AddToCartDialog() {
)}
</MyTouchableOpacity>
))}
</ScrollView>
{!hasRegionSlots && !showFlashOption && (
<View style={tw`bg-red-50 p-4 rounded-xl border border-red-100`}>
<MyText style={tw`text-sm text-red-700 font-medium`}>
Not available in your region right now.
</MyText>
</View>
)}
{showFlashOption && (
<MyTouchableOpacity
key="flash-delivery"
style={tw`flex-row items-center mb-4 bg-pink-50 p-4 rounded-xl border ${selectedFlashDelivery ? 'border-pink-500' : 'border-pink-200'
}`}
onPress={() => {
setSelectedFlashDelivery(true);
setSelectedSlotId(null);
}}
activeOpacity={0.7}
>
<MaterialIcons name="bolt" size={20} color="#f81260" />
<View style={tw`ml-3 flex-1`}>
<MyText style={tw`text-gray-900 font-bold text-base`}>1 hr Delivery</MyText>
{!hasRegionSlots && !showFlashOption && (
<View style={tw`bg-red-50 p-4 rounded-xl border border-red-100`}>
<MyText style={tw`text-sm text-red-700 font-medium`}>
Not available in your region right now.
</MyText>
</View>
{selectedFlashDelivery ? (
<MaterialIcons name="check-circle" size={24} color="#f81260" />
) : (
<MaterialIcons name="check-box-outline-blank" size={24} color="#f81260" />
)}
</MyTouchableOpacity>
)}
)}
{showFlashOption && (
<MyTouchableOpacity
key="flash-delivery"
style={tw`flex-row items-center mb-4 bg-pink-50 p-4 rounded-xl border ${selectedFlashDelivery ? 'border-pink-500' : 'border-pink-200'
}`}
onPress={() => {
setSelectedFlashDelivery(true);
setSelectedSlotId(null);
}}
activeOpacity={0.7}
>
<MaterialIcons name="bolt" size={20} color="#f81260" />
<View style={tw`ml-3 flex-1`}>
<MyText style={tw`text-gray-900 font-bold text-base`}>1 hr Delivery</MyText>
</View>
{selectedFlashDelivery ? (
<MaterialIcons name="check-circle" size={24} color="#f81260" />
) : (
<MaterialIcons name="check-box-outline-blank" size={24} color="#f81260" />
)}
</MyTouchableOpacity>
)}
</ScrollView>
<View style={tw`mt-4`}>
<MyText style={tw`text-sm font-bold text-gray-900 mb-2`}>Quantity</MyText>
@ -262,7 +273,7 @@ export default function AddToCartDialog() {
</View>
</View>
<View style={tw`flex-row gap-3 mt-4 pb-12`}>
<View style={tw`flex-row gap-3 mt-4 pb-2`}>
<MyTouchableOpacity
testID="add-to-cart-confirm"
style={tw`flex-1 bg-brand500 py-3.5 rounded-xl items-center ${!canConfirm ? 'opacity-50' : ''}`}

View file

@ -41,6 +41,12 @@ interface LocationFallbackFlowProps {
* settings (used when the OS state can't be fixed from inside the app).
*/
onOpenSettings?: () => void
/**
* Whether to mark the address the app would fall back to (the user's default) as
* the active one. The startup gate passes false: no region exists yet, so nothing
* is chosen, and a pre-marked card reads as "already done" instead of "tap this".
*/
highlightActiveAddress?: boolean
}
/**
@ -48,7 +54,12 @@ interface LocationFallbackFlowProps {
* (which switches the browsing region + bound and clears the cart) or adds a
* new one (coordinates required, via attach-location or the map).
*/
const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, notice, onOpenSettings }) => {
const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({
onClose,
notice,
onOpenSettings,
highlightActiveAddress = true,
}) => {
const queryClient = useQueryClient()
const utils = trpc.useUtils()
const auth = useAuthOptional()
@ -78,9 +89,11 @@ const LocationFallbackFlow: React.FC<LocationFallbackFlowProps> = ({ onClose, no
// The address the app treats as active: an explicit pick (bar / cart / this
// sheet) wins, otherwise the default. Same precedence as LocationBar,
// CheckoutAddressSelector and CheckoutAddressDisplay, so the sheet cannot
// disagree with the bar it was opened from.
const activeAddressId =
selectedAddressId ?? addresses.find((address) => address.isDefault)?.id ?? null
// disagree with the bar it was opened from. Null in the startup gate, where
// nothing has been chosen yet — see highlightActiveAddress.
const activeAddressId = highlightActiveAddress
? selectedAddressId ?? addresses.find((address) => address.isDefault)?.id ?? null
: null
const activate = useCallback(
async (regionId: number, boundId: number | null): Promise<boolean> => {

View file

@ -5021,3 +5021,103 @@ user-ui
CheckoutAddressSelector). The green "Default" badge and the "Set as default" link are
unchanged - a default is not necessarily the active address.
No store/API/backend changes; the sheet still selects via handleSelect.
2026-10-16 20:48:35 user-ui: AddToCartDialog - slot list scrolls, Add to Cart row stays put.
apps/user-ui/src/components/AddToCartDialog.tsx
~ import Dimensions; new SHEET_MAX_HEIGHT = window height * 0.7.
~ content box: `tw`p-6 max-h-[650px]`` -> `[tw`p-6`, { maxHeight: SHEET_MAX_HEIGHT }]`.
Why: BottomDialog wraps children in its OWN ScrollView and caps itself at 85% of the screen
(packages/ui/src/components/dialog.tsx:56-63,147). A fixed 650px box + its handle + safe-area
insets can exceed that cap on shorter devices, so the DIALOG scrolled and dragged the action
row off-screen. Capping at 0.7 * screen keeps the dialog's own scroll view inert on any
screen (0.7S + ~60 chrome <= 0.85S), so the footer cannot move.
~ the slots ScrollView gets `tw`shrink`` (flexShrink 1, flexBasis auto) and now also holds the
"Not available in your region" notice and the 1 hr Delivery row, which were previously
siblings BELOW it. It is the only scrolling region, so it shrinks to the leftover space and
scrolls internally; the quantity row and the Cancel / Add to Cart row below it stay static.
Deliberately NOT `flex-1`: that is flexBasis 0%, which collapses to zero height inside an
auto-height (maxHeight-only) parent. Verified with the repo's own tw config:
max-h-[650px] -> {maxHeight:650}; shrink -> {flexShrink:1}; flex-1 -> {flexBasis:"0%"}.
~ SafeAreaView edges={['bottom']}: a top inset inside a bottom sheet only added dead space
between the handle and the header (it also counted against the height budget above).
No other file changed. No store/API/backend changes.
2026-10-16 21:20:10 user-ui: pin the action button for real - "Your Cart" dialog + AddToCartDialog.
The "Go to cart" button is in the FLOATING CART dialog, not AddToCartDialog:
apps/user-ui/components/floating-cart-bar.tsx:227-404 wraps the whole sheet (header, free-delivery
progress, the items list AND the Subtotal / "Go to cart" footer) in ONE <ScrollView> at line 228,
so the button scrolls away with the list. That is the button the user means, and the items list is
the "products list". Fixing it here; the earlier AddToCartDialog edit (right file per the original
request, but a different dialog) is made deterministic at the same time.
apps/user-ui/components/floating-cart-bar.tsx
~ line 228: `<ScrollView style={{ maxHeight: height * 0.8 }}>` -> `<View style={{ height:
CART_SHEET_HEIGHT }}>`; new CART_SHEET_HEIGHT = screenHeight * 0.72 (screenHeight already
exists at line 30). Closing tag at line 403 `</ScrollView>` -> `</View>`.
- With a DEFINITE sheet height the items ScrollView (already `flex-1`, line 267) gets exactly the
leftover space and is the only scrolling region; the header, the progress bar and the
Subtotal / Go to cart footer are static siblings.
- 0.72 * screen keeps the sheet + the dialog's handle inside BottomDialog's own 85%-of-screen
cap, so the dialog itself never scrolls (this is why a plain maxHeight is not enough: if the
sheet can outgrow that cap, the DIALOG scrolls and drags the footer with it).
apps/user-ui/src/components/AddToCartDialog.tsx
~ SHEET_MAX_HEIGHT (0.7 * screen, used as maxHeight) -> SHEET_HEIGHT used as a definite `height`,
and the slots ScrollView `tw`shrink`` -> `tw`flex-1``.
- Rationale: with only a maxHeight the parent's height is content-driven, so `flex-1`
(flexBasis 0%) would collapse the list; and relying on shrink alone depends on measure
semantics. A definite height makes the pinning deterministic: list = leftover, footer static.
- Trade-off: the sheet is now that tall even with one slot (blank space under the last row),
which is the price of a guaranteed-fixed action row.
No store/API/backend change. No other file changed.
2026-10-16 21:42:15 user-ui: less dead space under the pinned action rows in both cart sheets.
Feedback: "a lot of space between the go to cart button and the buttons below". Under the action row
there were three stacked paddings: the row's own bottom padding, the sheet's padding, AND
BottomDialog's own scroll-content paddingBottom (packages/ui/src/components/dialog.tsx:168 -
40px iOS / 20px Android, inside the dialog, below our sheet). Only our own padding is ours to trim.
apps/user-ui/components/floating-cart-bar.tsx ("Your Cart" footer with the Go to cart button)
~ footer `p-6` -> `px-6 pt-6 pb-2` (24 -> 8 below the button).
apps/user-ui/src/components/AddToCartDialog.tsx (Add to Cart / Cancel row)
~ action row `mt-4 pb-12` -> `mt-4 pb-2` (48 -> 8 below the row).
Not changed: the shared BottomDialog padding (20/40) - it is common-ui and affects every dialog.
If that remaining band still looks too big, the next step is a negative bottom margin on the sheet
(platform-coupled: -40 iOS / -20 Android), which I have deliberately not done unasked.
2026-10-16 21:55:40 user-ui: both cart sheets take the full 80% of the screen height.
"bottom dialog can take up 80% of screen height" - the original cart-dialog wrapper was
`maxHeight: height * 0.8` (floating-cart-bar.tsx), so 80% is the intended budget; I had made the
sheets 0.7/0.72 to fit the dialog's own 85% cap plus its handle/padding. Raising both to 0.8:
apps/user-ui/components/floating-cart-bar.tsx
~ CART_SHEET_HEIGHT = screenHeight * 0.72 -> screenHeight * 0.8.
apps/user-ui/src/components/AddToCartDialog.tsx
~ SHEET_HEIGHT = Dimensions.get('window').height * 0.7 -> * 0.8.
Both comments updated: at 0.8 the sheet plus BottomDialog's handle (~25) and its own scroll-content
paddingBottom (dialog.tsx:168 - 40 iOS / 20 Android) can exceed the dialog's 85% cap by ~20px, which
lets the dialog scroll by that much (the pinned action row stays fully visible; the sheet simply
fills more of the screen as requested). More list room: ~660px vs ~580px on a 932pt screen.
No other file changed.
2026-10-17 09:12:05 user-ui: the startup address chooser no longer pre-highlights the default.
Feedback: on startup the chooser marks an address as the selected option, which is misleading -
nothing is chosen yet (no region), the user still has to tap one, so the brand card + check circle
reads as "already done".
apps/user-ui/src/components/location/LocationFallbackFlow.tsx
+ prop `highlightActiveAddress` (default true). When false, activeAddressId is null and no card
gets the brand tint / check circle; the green "Default" badge is untouched (it only says which
address is the default, not that it is chosen).
- the default fallback was the cause: activeAddressId = selectedAddressId ?? isDefault. In the
gate selectedAddressId is always null, so the default was highlighted.
apps/user-ui/components/LocationTestWrapper.tsx
~ passes highlightActiveAddress={false} (the gate = no region resolved = nothing chosen).
- The sheet opened from the top region bar (AddressSwitcherSheet) keeps the default true, so it
still marks the address the app is actually using (and agrees with the bar).
No store/API changes. No test asserts the highlight (checked tests/).