summaryrefslogtreecommitdiffstats
path: root/frontend/components/Count.js
blob: 7dfd33f862066a3b6c94d42488ee08106f229831 (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
// TODO THis is not needed
import React, { Component } from 'react'
import { graphql, gql } from 'react-apollo'

import { ALL_ITEMS_QUERY } from '../queries';

class Count extends Component {

  render() {

    // 1
    if (this.props.allLinksQuery && this.props.allLinksQuery.loading) {
      return <div>Loading</div>
    }

    // 2
    if (this.props.allLinksQuery && this.props.allLinksQuery.error) {
      return <div>Error</div>
    }

    // 3
    const itemsToRender = this.props.allLinksQuery.allItems

    return (
      <div>
        <h1>There are {itemsToRender.length} items for sale</h1>
      </div>
    )
  }

}

// 1

// We export the graphQL HOC - this will fetch the data and inject it into the Count compeont via props

export default graphql(ALL_ITEMS_QUERY, { name: 'allLinksQuery' })(Count)