diff --git a/package.json b/package.json index 31a4b28..a928a68 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,13 @@ "version": "0.1.0", "private": true, "dependencies": { + "apollo-client-preset": "^1.0.8", "axios": "^0.18.0", + "graphql": "^0.13.2", + "graphql-tag": "^2.9.2", "lodash": "^4.17.10", "react": "^16.4.1", + "react-apollo": "^2.1.5", "react-dom": "^16.4.1", "react-redux": "^5.0.7", "react-router-dom": "^4.3.1", diff --git a/src/components/Link.js b/src/components/Link.js new file mode 100644 index 0000000..5874dc3 --- /dev/null +++ b/src/components/Link.js @@ -0,0 +1,22 @@ + + +import React, { Component } from 'react' + +class Link extends Component { + render() { + const { id, properties: { english, thai } } = this.props.node + return ( +
+
+ {id} ({english} - {thai}) +
+
+ ) + } + + _voteForLink = async () => { + // ... you'll implement this in chapter 6 + } +} + +export default Link diff --git a/src/components/LinkList.js b/src/components/LinkList.js new file mode 100644 index 0000000..1443237 --- /dev/null +++ b/src/components/LinkList.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react' +import Link from './Link' +import { graphql } from 'react-apollo' +import gql from 'graphql-tag' + +class LinkList extends Component { + render() { + const { loading, theaters } = this.props.theaterQuery + console.log('theaters ---> ', theaters && theaters.edges.length) + console.log('theaters ---> ', theaters && theaters.edges.map(t => t.node.id )) + return ( +
+ { loading && 'loading' } + { theaters &&

{theaters.edges.length}

} + { theaters && theaters.edges.map(t => ) } +
+ ) + } +} + +const THEATER_QUERY = gql` + query { + theaters(english_Icontains: "terminal") { + edges { + node { + id + geometry { + type + coordinates + } + properties { + english + thai + code + } + } + } + } + } +` + +export default graphql(THEATER_QUERY, { name: 'theaterQuery' }) (LinkList) +// export default LinkList diff --git a/src/constants/Api.js b/src/constants/Api.js index f4fd5fd..7ac1379 100644 --- a/src/constants/Api.js +++ b/src/constants/Api.js @@ -1,3 +1,5 @@ export const URL = process.env.API_URL || '//localhost:8000' export const LOGIN = '/api-token-auth/' + +export const GRAPHQL_URI = process.env.GRAPHQL_URI || '//localhost:8000/graphql' \ No newline at end of file diff --git a/src/container/Gone.js b/src/container/Gone.js index 600a010..f08d61d 100644 --- a/src/container/Gone.js +++ b/src/container/Gone.js @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom' import { connect } from 'react-redux' import { getToken, loggedIn } from '../reducers/auth' import { fetchAuth } from '../actions' +import LinkList from '../components/LinkList' const Gone = (props) => (
@@ -11,6 +12,9 @@ const Gone = (props) => (
Main +

LinkList

+ +
{props.loggedIn ? 'Logged in': 'Nah anonymous'}
diff --git a/src/index.js b/src/index.js index e634e72..a870798 100644 --- a/src/index.js +++ b/src/index.js @@ -10,15 +10,30 @@ import { persistStore } from 'redux-persist' import { PersistGate } from 'redux-persist/integration/react' import store from './store' +import { ApolloProvider } from 'react-apollo' +import { ApolloClient } from 'apollo-client' +import { HttpLink } from 'apollo-link-http' +import { InMemoryCache } from 'apollo-cache-inmemory' + +import { GRAPHQL_URI } from './constants/Api' + +const httpLink = new HttpLink({ uri: GRAPHQL_URI }) + +const client = new ApolloClient({ + link: httpLink, + cache: new InMemoryCache() +}) const persistor = persistStore(store) ReactDOM.render(( - - - + + + + + ), document.getElementById('root'))