diff options
| author | Wes Bos <wesbos@gmail.com> | 2017-10-27 10:10:49 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2017-10-27 10:10:49 -0400 |
| commit | acdfa2840f867e686471a8e9ac3f29353fab7dd1 (patch) | |
| tree | 1a069ce11e145d9b286084221951272511debbdf /components/AddToCart.js | |
| parent | 6f44adb59d3542eb21e55e0aae789b1fcc7cf8f1 (diff) | |
hi
Diffstat (limited to 'components/AddToCart.js')
| -rw-r--r-- | components/AddToCart.js | 12 |
1 files changed, 8 insertions, 4 deletions
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 <p>Loading...</p>; + // TODO WTF + if (!user || this.props.singleItemQuery.loading || !this.props.singleItemQuery.Item) return <p>Loading...</p>; 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 ( <div> {isInCart ? ( |
