File tree 7 files changed +116
-14
lines changed
7 files changed +116
-14
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "extends": "airbnb",
3
+ "rules": {
4
+ comma-dangle: [2, "never"]
5
+ }
6
+ }
Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="UTF-8 " />
5
5
< title > React Seed</ title >
6
+
7
+ < style media ="screen ">
8
+
9
+ </ style >
6
10
</ head >
7
11
< body >
8
12
< main class ="application-container "> </ main >
Original file line number Diff line number Diff line change 16
16
"license" : " MIT" ,
17
17
"dependencies" : {
18
18
"react" : " ^0.14.7" ,
19
- "react-dom" : " ^0.14.7"
19
+ "react-dom" : " ^0.14.7" ,
20
+ "superagent" : " ^1.8.2"
20
21
},
21
22
"devDependencies" : {
22
23
"babel-cli" : " ^6.6.5" ,
23
24
"babel-core" : " ^6.7.2" ,
25
+ "babel-eslint" : " ^5.0.0" ,
24
26
"babel-loader" : " ^6.2.4" ,
25
27
"babel-preset-es2015" : " ^6.6.0" ,
26
28
"babel-preset-react" : " ^6.5.0" ,
29
+ "eslint" : " ^2.4.0" ,
30
+ "eslint-config-airbnb" : " ^6.2.0" ,
31
+ "eslint-loader" : " ^1.3.0" ,
32
+ "eslint-plugin-react" : " ^4.2.3" ,
27
33
"webpack" : " ^1.12.14"
28
34
}
29
35
}
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import request from 'superagent' ;
3
+ import RepositorySearchResult from './RepositorySearchResult.jsx' ;
4
+
5
+ export default class RepositorySearch extends React . Component {
6
+
7
+ constructor ( ) {
8
+ super ( ) ;
9
+ this . state = {
10
+ searchQuery : '' ,
11
+ repositories : [ ]
12
+ } ;
13
+ this . handleSearch = this . handleSearch . bind ( this ) ;
14
+ this . handleQueryChange = this . handleQueryChange . bind ( this ) ;
15
+ }
16
+
17
+ handleQueryChange ( e ) {
18
+ this . setState ( {
19
+ searchQuery : e . target . value
20
+ } ) ;
21
+ if ( e . target . value === '' ) {
22
+ this . setState ( {
23
+ repositories : [ ]
24
+ } ) ;
25
+ }
26
+ }
27
+
28
+ handleSearch ( ) {
29
+ if ( this . state . searchQuery ) {
30
+ request
31
+ . get ( 'https://api.github.com/search/repositories' )
32
+ . query ( {
33
+ q : this . state . searchQuery
34
+ } )
35
+ . end ( ( err , res ) => {
36
+ this . setState ( {
37
+ repositories : res . body . items
38
+ } ) ;
39
+ } ) ;
40
+ }
41
+ this . setState ( {
42
+ repositories : [ ]
43
+ } ) ;
44
+ }
45
+
46
+ render ( ) {
47
+ return (
48
+ < section className = "repository-search" >
49
+ < article className = "repository-search__search-query" >
50
+ < input
51
+ type = "search"
52
+ placeholder = "Search GitHub repositories"
53
+ onChange = { this . handleQueryChange }
54
+ value = { this . state . searchQuery }
55
+ />
56
+ < button onClick = { this . handleSearch } >
57
+ Search
58
+ </ button >
59
+ </ article >
60
+ < RepositorySearchResult repositories = { this . state . repositories } />
61
+ </ section >
62
+ ) ;
63
+ }
64
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export default function RepositorySearchResult ( { repositories } ) {
4
+ return (
5
+ < ul className = "repository-search__results" >
6
+ { repositories . map ( ( repository ) => (
7
+ < li key = { repository . id } >
8
+ { repository . full_name }
9
+ </ li >
10
+ ) ) }
11
+ </ ul >
12
+ ) ;
13
+ }
14
+
15
+ RepositorySearchResult . propTypes = {
16
+ repositories : React . PropTypes . nod
17
+ } ;
Original file line number Diff line number Diff line change 1
- 'use strict' ;
1
+ import React from 'react' ;
2
+ import ReactDOM from 'react-dom' ;
3
+ import RepositorySearch from './RepositorySearch/RepositorySearch.jsx' ;
2
4
3
- const React = require ( 'react' ) ;
4
- const ReactDOM = require ( 'react-dom' ) ;
5
-
6
- class Application extends React . Component {
7
- render ( ) {
8
- return (
9
- < section className = "application" >
10
- React Seed
11
- </ section >
12
- ) ;
13
- }
14
- } ;
5
+ function Application ( ) {
6
+ return (
7
+ < section className = "application" >
8
+ < RepositorySearch />
9
+ </ section >
10
+ ) ;
11
+ }
15
12
16
13
ReactDOM . render (
17
14
< Application /> ,
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ var config = {
11
11
filename : 'bundle.js'
12
12
} ,
13
13
module : {
14
+ preLoaders : [
15
+ {
16
+ test : / \. j s x $ | \. j s $ / ,
17
+ loader : 'eslint-loader' ,
18
+ include : APP_DIR ,
19
+ exclude : BUILD_DIR
20
+ }
21
+ ] ,
14
22
loaders : [
15
23
{
16
24
test : / \. j s x ? / ,
You can’t perform that action at this time.
0 commit comments