From b1600adec47a04f60e1da07d94a3ed3906ff5aee Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 14 Jun 2018 16:44:21 -0400 Subject: starter files --- finished-application/frontend/components/Cart.js | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 finished-application/frontend/components/Cart.js (limited to 'finished-application/frontend/components/Cart.js') diff --git a/finished-application/frontend/components/Cart.js b/finished-application/frontend/components/Cart.js new file mode 100644 index 0000000..7e8a9c5 --- /dev/null +++ b/finished-application/frontend/components/Cart.js @@ -0,0 +1,74 @@ +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 }) => ( + + {(mutate, result) => render({ mutate, result })} + + ), + localState: ({ render }) => , + currentUser: ({ render }) => ( + + ), +}); + +const Cart = () => ( + + {({ toggleCart, localState, currentUser }) => { + const { data: { me }, error, loading } = currentUser; + if (loading) return

Loading...

; + if (error) return ; + if (!me) return null; + return ( + +
+ + × + + + {me.name}'s Cart. +

+ You have {me.cart.length} item{me.cart.length === 1 ? '' : 's'} in your cart. +

+
+ +
    {me.cart.map(cartItem => )}
+ +
+ ); + }} +
+); + +export default Cart; +export { LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION }; -- cgit v1.3