diff options
Diffstat (limited to 'stepped-solutions/18/frontend/components/Items.js')
| -rwxr-xr-x | stepped-solutions/18/frontend/components/Items.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/stepped-solutions/18/frontend/components/Items.js b/stepped-solutions/18/frontend/components/Items.js new file mode 100755 index 0000000..5ff4055 --- /dev/null +++ b/stepped-solutions/18/frontend/components/Items.js @@ -0,0 +1,51 @@ +import React, { Component } from 'react'; +import { Query } from 'react-apollo'; +import gql from 'graphql-tag'; +import styled from 'styled-components'; +import Item from './Item'; + +const ALL_ITEMS_QUERY = gql` + query ALL_ITEMS_QUERY { + items { + id + title + price + description + image + largeImage + } + } +`; + +const Center = styled.div` + text-align: center; +`; + +const ItemsList = styled.div` + display: grid; + grid-template-columns: 1fr 1fr; + grid-gap: 60px; + max-width: ${props => props.theme.maxWidth}; + margin: 0 auto; +`; + +class Items extends Component { + render() { + return ( + <Center> + <Query query={ALL_ITEMS_QUERY}> + {({ data, error, loading }) => { + if (loading) return <p>Loading...</p>; + if (error) return <p>Error: {error.message}</p>; + return ( + <ItemsList>{data.items.map(item => <Item item={item} key={item.id} />)}</ItemsList> + ); + }} + </Query> + </Center> + ); + } +} + +export default Items; +export { ALL_ITEMS_QUERY }; |
