summaryrefslogtreecommitdiffstats
path: root/frontend/components/Items.js
blob: 01d9786e4bc7b36b4f0dfc9d68f98be419ca5edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import { compose } from 'react-apollo';
import styled from 'styled-components';
import Pagination from './Pagination';
import Item from './Item';
import { itemEnhancer } from '../enhancers/enhancers';

const Items = styled.div`
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-gap: 60px;
  max-width: ${props => props.theme.maxWidth};
  margin: 0 auto;
`;

const Center = styled.div`
  text-align: center;
`;

class ItemList extends React.Component {
  something() { }
  render() {
    const { loading, error } = this.props.itemsQuery;
    // 1
    if (loading) {
      return <div>Loading</div>;
    }

    // 2
    if (error) {
      console.log(this.props.itemsQuery.error);
      return <div>Error</div>;
    }
    console.log(this.props);
    // 3
    const itemsToRender = this.props.itemsQuery.items;

    return (
      <Center>
        <Pagination page={this.props.page} />
        <Items key={this.props.page}>{itemsToRender.map((item, i) => <Item key={item.id} item={item} />)}</Items>
        <Pagination page={this.props.page} />
      </Center>
    );
  }
}

export default compose(itemEnhancer)(ItemList);