|
| 1 | +import {ApolloProvider} from 'react-apollo'; |
| 2 | +import ApolloClient from 'apollo-boost'; |
| 3 | + |
| 4 | +import React, {Component} from 'react'; |
| 5 | +import PropTypes from 'prop-types'; |
| 6 | +import {ActivityPanels} from '@enact/moonstone/Panels'; |
| 7 | +import MoonstoneDecorator from '@enact/moonstone/MoonstoneDecorator'; |
| 8 | + |
| 9 | +import Detail from '../views/Detail'; |
| 10 | +import Search from '../views/Search'; |
| 11 | +import config from '../config.json'; |
| 12 | + |
| 13 | +const client = new ApolloClient({ |
| 14 | + uri: 'https://api.github.com/graphql', |
| 15 | + request: operation => { |
| 16 | + operation.setContext({ |
| 17 | + headers: { |
| 18 | + authorization: `Bearer ${config.token}` |
| 19 | + } |
| 20 | + }); |
| 21 | + } |
| 22 | +}); |
| 23 | + |
| 24 | +class AppBase extends Component { |
| 25 | + static propTypes = { |
| 26 | + index: PropTypes.number, |
| 27 | + onListSelectionChange: PropTypes.func, |
| 28 | + onSearch: PropTypes.func, |
| 29 | + onUserIdChange: PropTypes.func |
| 30 | + }; |
| 31 | + |
| 32 | + static defaultProps = { |
| 33 | + index: 0 |
| 34 | + }; |
| 35 | + |
| 36 | + |
| 37 | + constructor (props) { |
| 38 | + super(props); |
| 39 | + this.userId = 'haileyr'; |
| 40 | + this.lists = { |
| 41 | + repo: true, |
| 42 | + fol: true, |
| 43 | + org: true |
| 44 | + }; |
| 45 | + |
| 46 | + this.state = { |
| 47 | + userId: '', |
| 48 | + lists: {}, |
| 49 | + index: this.props.index |
| 50 | + }; |
| 51 | + } |
| 52 | + |
| 53 | + handleSelectBreadcrumb = ({index}) => { |
| 54 | + this.lists = { |
| 55 | + repo: false, |
| 56 | + fol: false, |
| 57 | + org: false |
| 58 | + }; |
| 59 | + this.setState({ |
| 60 | + index, |
| 61 | + userId: '', |
| 62 | + lists: this.lists |
| 63 | + }); |
| 64 | + }; |
| 65 | + |
| 66 | + onUserIdChange = (userId) => { |
| 67 | + this.userId = userId; |
| 68 | + }; |
| 69 | + |
| 70 | + onListSelectionChange = (target, value) => { |
| 71 | + this.lists[target] = value; |
| 72 | + }; |
| 73 | + |
| 74 | + onSearch = () => { |
| 75 | + this.setState({index: 1, userId: this.userId, lists: this.lists}); |
| 76 | + }; |
| 77 | + |
| 78 | + render () { |
| 79 | + const {index, userId, lists} = this.state; |
| 80 | + |
| 81 | + return ( |
| 82 | + <ApolloProvider client={client}> |
| 83 | + <ActivityPanels {...this.props} onSelectBreadcrumb={this.handleSelectBreadcrumb} index={index}> |
| 84 | + <Search |
| 85 | + onUserIdChange={this.onUserIdChange} |
| 86 | + onListSelectionChange={this.onListSelectionChange} |
| 87 | + onSearch={this.onSearch} |
| 88 | + /> |
| 89 | + <Detail userId={userId} lists={lists} /> |
| 90 | + </ActivityPanels> |
| 91 | + </ApolloProvider>); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +const App = MoonstoneDecorator(AppBase); |
| 96 | + |
| 97 | +export default App; |
| 98 | +export {App, AppBase}; |
0 commit comments