From acdfa2840f867e686471a8e9ac3f29353fab7dd1 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 27 Oct 2017 10:10:49 -0400 Subject: hi --- components/AddToCart.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'components/AddToCart.js') diff --git a/components/AddToCart.js b/components/AddToCart.js index ae5b87f..e46a1f5 100644 --- a/components/AddToCart.js +++ b/components/AddToCart.js @@ -5,6 +5,7 @@ import { graphql, compose } from 'react-apollo'; import Transition from 'react-transition-group/Transition'; import makeImage from '../lib/image'; import styled from 'styled-components'; +import PropTypes from 'prop-types'; const JumpImg = styled.img` border: 0 solid black; @@ -34,6 +35,10 @@ const JumpImg = styled.img` `; class AddToCart extends Component { + static propTypes = { + currentUserQuery: PropTypes.object, + }; + componentDidMount() { this.props.currentUserQuery.refetch(); } @@ -62,13 +67,12 @@ class AddToCart extends Component { render() { const user = this.props.currentUserQuery.user; - if (!user || this.props.singleItemQuery.loading) return

Loading...

; + // TODO WTF + if (!user || this.props.singleItemQuery.loading || !this.props.singleItemQuery.Item) return

Loading...

; const cartIds = user.cart.map(item => item.id); - const image = this.props.singleItemQuery.Item.image; + const image = this.props.singleItemQuery.Item.image || {}; const isInCart = cartIds.includes(this.props.id); const { x, y } = document.querySelector('.cart').getBoundingClientRect(); - console.log({ x, y }); - return (
{isInCart ? ( -- cgit v1.3