File tree 9 files changed +111
-12
lines changed
9 files changed +111
-12
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ module.exports = {
11
11
{
12
12
singleQuote : true ,
13
13
bracketSpacing : true ,
14
- trailingComma : 'all ' ,
14
+ trailingComma : 'es5 ' ,
15
15
semi : false ,
16
16
} ,
17
17
] ,
@@ -21,6 +21,7 @@ module.exports = {
21
21
'react/jsx-closing-tag-location' : 'off' ,
22
22
'react/no-multi-comp' : 'off' ,
23
23
'no-use-before-define' : 'off' ,
24
+ 'no-param-reassign' : 'off' ,
24
25
'react/jsx-closing-bracket-location' : 'off' ,
25
26
'react/jsx-curly-spacing' : 'off' ,
26
27
'react/jsx-equals-spacing' : 'off' ,
Original file line number Diff line number Diff line change
1
+ {
2
+ "GBOOKS_KEY" : " YOUR_GOOGLE_BOOKS_API_KEY"
3
+ }
Original file line number Diff line number Diff line change 30
30
"jest" : {
31
31
"preset" : " jest-expo" ,
32
32
"setupTestFrameworkScriptFile" : " <rootDir>/jestSetup.js" ,
33
- "snapshotSerializers" : [" enzyme-to-json/serializer" ]
33
+ "snapshotSerializers" : [
34
+ " enzyme-to-json/serializer"
35
+ ]
34
36
},
35
37
"dependencies" : {
38
+ "axios" : " ^0.18.0" ,
36
39
"enzyme" : " ^3.3.0" ,
37
40
"enzyme-adapter-react-16" : " ^1.1.1" ,
38
41
"expo" : " ^27.0.1" ,
42
+ "mobx" : " ^4.2.1" ,
43
+ "mobx-react" : " ^5.1.2" ,
44
+ "mobx-state-tree" : " ^2.0.5" ,
39
45
"prop-types" : " ^15.6.1" ,
40
46
"react" : " 16.3.1" ,
41
47
"react-dom" : " 16" ,
Original file line number Diff line number Diff line change
1
+ import axios from 'axios'
2
+
3
+ const baseUrl = `https://www.googleapis.com/books/v1/volumes`
4
+ const { GBOOKS_KEY } = require ( '../../../keys' )
5
+
6
+ const fetchBooks = ( ) =>
7
+ axios . get ( `${ baseUrl } ?q=books&printType=books&key=${ GBOOKS_KEY } ` )
8
+
9
+ export default {
10
+ fetchBooks,
11
+ }
Original file line number Diff line number Diff line change
1
+ import { types as t , flow } from 'mobx-state-tree'
2
+ import api from './api'
3
+
4
+ let store = null
5
+
6
+ const Book = t . model ( 'Book' , {
7
+ id : t . identifier ( ) ,
8
+ title : t . string ,
9
+ pageCount : t . number ,
10
+ authors : t . array ( t . string ) ,
11
+ image : t . maybe ( t . string ) ,
12
+ inStock : t . optional ( t . boolean , true ) ,
13
+ } )
14
+
15
+ const BookStore = t
16
+ . model ( 'BookStore' , {
17
+ books : t . array ( Book ) ,
18
+ } )
19
+ . actions ( self => {
20
+ function updateBooks ( books ) {
21
+ books . items . forEach ( book => {
22
+ self . books . push ( {
23
+ id : book . id ,
24
+ title : book . volumeInfo . title ,
25
+ pageCount : book . volumeInfo . pageCount ,
26
+ authors : book . volumeInfo . authors ,
27
+ publisher : book . volumeInfo . publisher ,
28
+ image : book . volumeInfo . imageLinks . smallThumbnail ,
29
+ } )
30
+ } )
31
+ }
32
+
33
+ const loadBooks = flow ( function * loadBooks ( ) {
34
+ try {
35
+ const books = yield api . fetchBooks ( )
36
+ updateBooks ( books )
37
+ } catch ( err ) {
38
+ console . error ( 'Failed to load books ' , err )
39
+ }
40
+ } )
41
+
42
+ return {
43
+ loadBooks,
44
+ }
45
+ } )
46
+
47
+ export default ( ) => {
48
+ if ( store ) return store
49
+
50
+ store = BookStore . create ( { books : [ ] } )
51
+ return store
52
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { Text } from 'react-native'
3
+ import { observer } from 'mobx-react'
4
+
5
+ export default observer ( ( { book } ) => (
6
+ < Text >
7
+ { book . title } by { book . authors [ 0 ] }
8
+ </ Text >
9
+ ) )
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { View } from 'react-native'
3
+ import { observer } from 'mobx-react'
4
+ import Book from './Book'
5
+
6
+ export default observer ( ( { books } ) => (
7
+ < View > { books . map ( book => < Book key = { book . id } book = { book } /> ) } </ View >
8
+ ) )
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react'
2
+ import BookStore from '../../../stores/book'
3
+ import BookList from './BookList'
4
+
5
+ class BookListView extends Component {
6
+ async componentWillMount ( ) {
7
+ this . store = BookStore ( )
8
+ await this . store . loadBooks ( )
9
+ }
10
+
11
+ render ( ) {
12
+ return < BookList books = { this . store . books } />
13
+ }
14
+ }
15
+
16
+ export default BookListView
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
- import { View , Button } from 'react-native'
2
+ import { View } from 'react-native'
3
3
import Title from '../../../components/Title'
4
+ import BookListView from './BookListView'
4
5
5
6
export const AllBooksTab = ( { navigation } ) => (
6
7
< View >
7
8
< Title text = "All Books" />
8
- < Button
9
- onPress = { ( ) => navigation . navigate ( 'Authors' ) }
10
- title = "Go to Authors"
11
- />
12
- < Button
13
- onPress = { ( ) => navigation . navigate ( 'NonfictionBooksTab' ) }
14
- title = "Go to NonfictionBooksTab"
15
- />
16
- < Button onPress = { ( ) => navigation . openDrawer ( ) } title = "Open Drawer" />
9
+ < BookListView />
17
10
</ View >
18
11
)
19
12
You can’t perform that action at this time.
0 commit comments