-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10: Implement the third page, Select Menu Items
- Cart ('Your tray') has its own actions column with ability to add/remove items and update subtotal
- Loading branch information
1 parent
7a259ad
commit 2351850
Showing
11 changed files
with
296 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { debugged } from '../../../shared/diagnostics'; | ||
import { useDispatch } from 'react-redux'; | ||
import { useMemo } from 'react'; | ||
import curry from 'lodash-es/curry'; | ||
import { updateCartWithItemAsyncThunk } from '../../../features/cart/cartSlice'; | ||
|
||
/** | ||
* | ||
* @param cartId | ||
* @param cartItemsMap | ||
* @param selectedRestaurantId | ||
* @return {*|(function(*, *): function(*): (function(...[*]): (*|undefined))|*)} | ||
*/ | ||
export function useUpdateCartHandler(cartId, cartItemsMap, selectedRestaurantId) { | ||
const dummyHandler = (a, b) => (c) => debugged([ a, b, c ]); | ||
|
||
const dispatch = useDispatch(); | ||
return useMemo(() => cartId ? curry((itemId, menuItem, cartItem, diff, _) => { | ||
const item = cartItem || { count: 0, name: menuItem?.name, price: menuItem?.price }; | ||
const restaurantId = selectedRestaurantId ?? (item.meta?.restaurantId ?? null); | ||
if (typeof item.oldCount !== 'undefined') { | ||
return; | ||
} | ||
dispatch(updateCartWithItemAsyncThunk({ | ||
cartId, | ||
restaurantId, | ||
itemId, | ||
qty: Math.max(0, item.count + diff), | ||
item | ||
})); | ||
debugger; | ||
}) : dummyHandler, [ cartId, selectedRestaurantId, dispatch ]); | ||
} | ||
|
||
export function createMap(arr, idGetter) { | ||
return new Map(arr.map(i => [ idGetter(i), i ])); | ||
} |
Oops, something went wrong.