-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.js
70 lines (65 loc) · 1.51 KB
/
app.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import ReactDOM from 'react-dom';
import Relay from 'react-relay';
import { debounce } from 'lodash';
import SearchForm from './search-form';
import Quote from './quote';
class QuotesLibrary extends React.Component {
constructor(props) {
super(props);
this.search = debounce(this.search.bind(this), 300);
}
search(searchTerm) {
this.props.relay.setVariables({searchTerm});
}
render() {
return (
<div className="quotes-library">
<SearchForm searchAction={this.search} />
<div className="quotes-list">
{this.props.library.quotesConnection.edges.map(edge =>
<Quote key={edge.node.id} quote={edge.node} />
)}
</div>
</div>
)
}
}
QuotesLibrary = Relay.createContainer(QuotesLibrary, {
initialVariables: {
searchTerm: ''
},
fragments: {
library: () => Relay.QL `
fragment on QuotesLibrary {
quotesConnection(first: 100, searchTerm: $searchTerm) {
edges {
node {
id
${Quote.getFragment('quote')}
}
}
}
}
`
}
});
class AppRoute extends Relay.Route {
static routeName = 'App';
static queries = {
library: (Component) => Relay.QL `
query QuotesLibrary {
quotesLibrary {
${Component.getFragment('library')}
}
}
`
}
}
ReactDOM.render(
<Relay.RootContainer
Component={QuotesLibrary}
route={new AppRoute()}
/>,
document.getElementById('react')
);