summaryrefslogtreecommitdiffstats
path: root/components/Header.js
blob: 60d06212a014c4fdedef4629c0646566c0304e4f (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
import { Component } from 'react'
import { graphql, compose } from 'react-apollo'
import { CURRENT_USER_QUERY } from '../queries';
import Cart from './Cart';
import Login from './LoginAuth0';
import Search from './Search';

class Header extends Component {

  componentDidMount() {
    // This fetches the new data, but doesn't populate the user via props
    // this.props.currentUserQuery.refetch();
    // This fetches the new data, and populates the user via props
    setTimeout(this.props.currentUserQuery.refetch, 1);
  }

  render() {
    const user = this.props.currentUserQuery.user || {};
    const { email = '' } = user;
    return (
      <div>
        <p>Signed in as <strong>{email}</strong></p>
        <Login></Login>
        <Cart></Cart>
        <Search></Search>
      </div>
    )
  }
}

const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUserQuery' });
export default compose(userEnhancer)(Header)