Skip to content

Commit 626590d

Browse files
committed
feat: optimize listings fetching logic based on selected restaurant
1 parent 6b4f967 commit 626590d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/redux/thunks/cartThunks.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ export const fetchCart = createAsyncThunk(
3030
dispatch(setSelectedRestaurant(restaurant));
3131
dispatch(getRestaurantThunk(restaurant.id));
3232

33-
// Also fetch the restaurant's listings/menu items
34-
dispatch(getListingsThunk({ restaurantId }));
33+
// Check if we already have listings for this restaurant in Redux state
34+
const currentListingsRestaurantId = state.listings?.currentRestaurantId;
35+
const hasListings = state.listings?.items?.length > 0;
36+
37+
// Only fetch listings if they don't already belong to the selected restaurant
38+
if (!hasListings || currentListingsRestaurantId !== restaurantId) {
39+
dispatch(getListingsThunk({ restaurantId }));
40+
}
3541
}
3642
}
3743

0 commit comments

Comments
 (0)