We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6b4f967 commit 626590dCopy full SHA for 626590d
src/redux/thunks/cartThunks.js
@@ -30,8 +30,14 @@ export const fetchCart = createAsyncThunk(
30
dispatch(setSelectedRestaurant(restaurant));
31
dispatch(getRestaurantThunk(restaurant.id));
32
33
- // Also fetch the restaurant's listings/menu items
34
- dispatch(getListingsThunk({ restaurantId }));
+ // Check if we already have listings for this restaurant in Redux state
+ 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
+ }
41
}
42
43
0 commit comments