From d22616d5a675f5a381c741784333151255713b45 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 6 Apr 2018 16:44:50 -0400 Subject: local data with apollo --- frontend/components/Cart.js | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'frontend/components/Cart.js') diff --git a/frontend/components/Cart.js b/frontend/components/Cart.js index 0a77754..7dbea8f 100644 --- a/frontend/components/Cart.js +++ b/frontend/components/Cart.js @@ -1,11 +1,10 @@ import React from 'react'; -import { Query } from 'react-apollo'; +import { Mutation, Query } from 'react-apollo'; import styled from 'styled-components'; import TakeMyMoney from './TakeMyMoney'; import formatMoney from '../lib/formatMoney'; -import { UIContext } from './UIContext'; import CartItem from './CartItem'; -import { CURRENT_USER_QUERY } from '../queries/index'; +import { CURRENT_USER_QUERY, LOCAL_STATE_QUERY, TOGGLE_CART_MUTATION } from '../queries/index'; import calcTotalPrice from '../lib/calcTotalPrice'; const CartStyles = styled.div` @@ -74,37 +73,43 @@ const CloseButton = styled.button` `; const Cart = props => ( - - {context => ( - - {({ data: { me }, error, loading }) => { - if (loading || error || !me) return null; - return ( - -
- - × - + + {toggle => ( + + {({ data }) => ( + + {({ data: { me }, error, loading }) => { + if (loading || error || !me) return null; + return ( + +
+ + × + - {me.name}'s Cart. -

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

-
+ {me.name}'s Cart. +

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

+
- {me.cart.map(cartItem => )} -
-

{formatMoney(calcTotalPrice(me.cart))}

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