From b1600adec47a04f60e1da07d94a3ed3906ff5aee Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 14 Jun 2018 16:44:21 -0400 Subject: starter files --- .../frontend/components/SingleItem.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 finished-application/frontend/components/SingleItem.js (limited to 'finished-application/frontend/components/SingleItem.js') diff --git a/finished-application/frontend/components/SingleItem.js b/finished-application/frontend/components/SingleItem.js new file mode 100644 index 0000000..83ef8a0 --- /dev/null +++ b/finished-application/frontend/components/SingleItem.js @@ -0,0 +1,77 @@ +import { Query } from 'react-apollo'; +import PropTypes from 'prop-types'; +import styled from 'styled-components'; +import Head from 'next/head'; +import Link from 'next/link'; +import gql from 'graphql-tag'; +import Error from './ErrorMessage'; +import AddToCart from './AddToCart'; + +const SINGLE_ITEM_QUERY = gql` + query SINGLE_ITEM_QUERY($id: ID!) { + items(where: { id: $id }) { + id + title + description + largeImage + image + } + } +`; + +const SingleItemStyles = styled.div` + max-width: 1200px; + margin: 2rem auto; + box-shadow: ${props => props.theme.bs}; + display: grid; + grid-auto-columns: 1fr; + grid-auto-flow: column; + min-height: 800px; + img { + width: 100%; + height: 100%; + object-fit: contain; + } + .details { + margin: 3rem; + font-size: 2rem; + } +`; + +const SingleItem = props => ( + + {({ data, loading, error }) => { + if (loading) return

Loading...

; + if (error) return ; + const [item] = data.items; + return ( + + + {item.title} + + {item.title} +
+

Viewing {item.title}

+

{item.description}

+ + Edit ✏️ + + +
+
+ ); + }} +
+); + +SingleItem.propTypes = { + id: PropTypes.string.isRequired, +}; + +export default SingleItem; +export { SINGLE_ITEM_QUERY }; -- cgit v1.3