diff options
| author | Peggy Rayzis <peggyrayzis@gmail.com> | 2018-05-23 17:51:50 -0400 |
|---|---|---|
| committer | Peggy Rayzis <peggyrayzis@gmail.com> | 2018-05-23 17:51:50 -0400 |
| commit | e040b70da6a48b1eb2f2b32132fa9b2244e92780 (patch) | |
| tree | f538c8b01f1ee41ea0c7cd0f58fcf7746b8accb8 /frontend/components/Cart.js | |
| parent | 444defc6e5709c46d935dbff8e90538156915457 (diff) | |
Refactor react-adopt to recommended API
Diffstat (limited to 'frontend/components/Cart.js')
| -rw-r--r-- | frontend/components/Cart.js | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/frontend/components/Cart.js b/frontend/components/Cart.js index 2230a0e..a815b78 100644 --- a/frontend/components/Cart.js +++ b/frontend/components/Cart.js @@ -17,19 +17,23 @@ import CloseButton from './styles/CloseButton'; import SickButton from './styles/SickButton'; const Composed = adopt({ - toggleCart: <Mutation mutation={TOGGLE_CART_MUTATION}>{() => {}}</Mutation>, - localState: <Query query={LOCAL_STATE_QUERY}>{() => {}}</Query>, - currentUser: ( - <Query query={CURRENT_USER_QUERY} data-test="cart"> - {() => {}} - </Query> + toggleCart: ({ render }) => ( + <Mutation mutation={TOGGLE_CART_MUTATION}> + {(mutate, result) => render({ mutate, result })} + </Mutation> ), + localState: <Query query={LOCAL_STATE_QUERY} />, + currentUser: <Query query={CURRENT_USER_QUERY} data-test="cart" />, }); const Cart = () => ( <Composed> {({ toggleCart, localState, currentUser }) => { - const { data: { me }, error, loading } = currentUser; + const { + data: { me }, + error, + loading, + } = currentUser; if (loading) return <p>Loading...</p>; if (error) return <Error error={error} />; if (!me) return null; @@ -42,11 +46,16 @@ const Cart = () => ( <Supreme>{me.name}'s Cart.</Supreme> <p> - You have {me.cart.length} item{me.cart.length === 1 ? '' : 's'} in your cart. + You have {me.cart.length} item{me.cart.length === 1 ? '' : 's'} in + your cart. </p> </header> - <ul>{me.cart.map(cartItem => <CartItem key={cartItem.id} cartItem={cartItem} />)}</ul> + <ul> + {me.cart.map(cartItem => ( + <CartItem key={cartItem.id} cartItem={cartItem} /> + ))} + </ul> <footer> <p>{formatMoney(calcTotalPrice(me.cart))}</p> <TakeMyMoney> |
