diff options
| author | Wes Bos <wesbos@gmail.com> | 2017-09-21 15:39:12 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2017-09-21 15:39:12 -0400 |
| commit | 3b45dd7b593825721ec9ee9f6a49c732601b1ae0 (patch) | |
| tree | a2e8e73d6b6b6bc32eda2bb79af817397e4304f5 /components/Item.js | |
| parent | 1450e579c67e3d969cb099dfe6c1cefd1e313fb5 (diff) | |
Cha Ching
Diffstat (limited to 'components/Item.js')
| -rw-r--r-- | components/Item.js | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/components/Item.js b/components/Item.js index 66ca66f..1b47fcf 100644 --- a/components/Item.js +++ b/components/Item.js @@ -1,33 +1,61 @@ -import React, { Component } from 'react' -import { graphql, gql, compose } from 'react-apollo' -import { SINGLE_ITEM_QUERY } from '../queries'; -import withData from '../lib/withData'; +import styled from 'styled-components'; +import slugify from 'slugify'; +import { Link } from '../routes'; +import AddToCart from './AddToCart'; +import makeImage from '../lib/image'; +import TakeMyMoney from './TakeMyMoney'; +import formatMoney from '../lib/formatMoney'; -class Item extends Component { - render() { - if(!this.props.findItem.Item) return <p>Not ready</p> - console.log(this.props.findItem.Item); +const Item = styled.div` + background: #f3f3f3; + padding: 5px; + img { + width: 100%; + } +`; - if(this.props.loading) return <p>Loading...</p> - if(this.props.error) return <p>Error...</p> +const ItemComponent = ({ item }) => ( + <Item key={item.id}> + {item.image ? <img key={item.image.secret} src={makeImage(item.image)} alt={item.title} /> : null} + <h3> + <Link + route="item" + params={{ + slug: slugify(item.title), + itemId: item.id, + }} + > + <a>{item.title}</a> + </Link> + </h3> - const item = this.props.findItem.Item; - return ( - <div> - <h2>Viewing {item.title}</h2> - </div> - ) - } -} + <p>{item.description}</p> + {/* { + + <Link + href={{ + pathname: '/admin/update', + query: { id: item.id }, + }} + > + <a>Edit ✏️</a> + </Link> + + } */} + + <TakeMyMoney + id={item.id} + amount={item.price} + name={item.title} // the pop-in header title + description={item.description} // the pop-in header subtitle + image={makeImage(item.image)} + > + <button>Buy for {formatMoney(item.price)}</button> + </TakeMyMoney> -const ComponentWithMutations = compose( - graphql(SINGLE_ITEM_QUERY, { - name: 'findItem', - // This comes from Props - options: ({ id }) => ({ - variables: { id } - }) - }) -)(Item); + <AddToCart id={item.id} /> + <button onClick={() => this.props.removeItemMutation({ variables: { id: item.id } })}>× Delete item</button> + </Item> +); -export default ComponentWithMutations; +export default ItemComponent; |
