diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-09-13 14:18:56 -0400 |
| commit | 8a5825d52271d712ec7c8348447d433067e13ef2 (patch) | |
| tree | ba07c218c1b2d4e59c154f2059b69fd858ae65fe /finished-application/frontend/components/Cart.js | |
| parent | b0d25a9ad3cc1df2fcc11ddb84e4603b94520b09 (diff) | |
DONE
Diffstat (limited to 'finished-application/frontend/components/Cart.js')
| -rw-r--r-- | finished-application/frontend/components/Cart.js | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/finished-application/frontend/components/Cart.js b/finished-application/frontend/components/Cart.js deleted file mode 100644 index 7e8a9c5..0000000 --- a/finished-application/frontend/components/Cart.js +++ /dev/null @@ -1,74 +0,0 @@ -import React from 'react'; -import { Mutation, Query } from 'react-apollo'; -import { adopt } from 'react-adopt'; -import gql from 'graphql-tag'; -import TakeMyMoney from './TakeMyMoney'; -import formatMoney from '../lib/formatMoney'; -import CartItem from './CartItem'; -import { CURRENT_USER_QUERY } from './User'; -import calcTotalPrice from '../lib/calcTotalPrice'; -import Error from './ErrorMessage'; -import CartStyles from './styles/CartStyles'; -import Supreme from './styles/Supreme'; -import CloseButton from './styles/CloseButton'; -import SickButton from './styles/SickButton'; - -const LOCAL_STATE_QUERY = gql` - query { - cartOpen @client - } -`; - -const TOGGLE_CART_MUTATION = gql` - mutation { - toggleCart @client - } -`; - -const Composed = adopt({ - toggleCart: ({ render }) => ( - <Mutation mutation={TOGGLE_CART_MUTATION}> - {(mutate, result) => render({ mutate, result })} - </Mutation> - ), - localState: ({ render }) => <Query query={LOCAL_STATE_QUERY} children={render} />, - currentUser: ({ render }) => ( - <Query children={render} query={CURRENT_USER_QUERY} data-test="cart" /> - ), -}); - -const Cart = () => ( - <Composed> - {({ toggleCart, localState, currentUser }) => { - const { data: { me }, error, loading } = currentUser; - if (loading) return <p>Loading...</p>; - if (error) return <Error error={error} />; - if (!me) return null; - return ( - <CartStyles open={localState.data.cartOpen}> - <header> - <CloseButton title="close" onClick={toggleCart.mutate}> - × - </CloseButton> - - <Supreme>{me.name}'s Cart.</Supreme> - <p> - 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> - <footer> - <p>{formatMoney(calcTotalPrice(me.cart))}</p> - <TakeMyMoney> - <SickButton>Checkout</SickButton> - </TakeMyMoney> - </footer> - </CartStyles> - ); - }} - </Composed> -); - -export default Cart; -export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION }; |
