File tree Expand file tree Collapse file tree 4 files changed +37
-38
lines changed Expand file tree Collapse file tree 4 files changed +37
-38
lines changed Original file line number Diff line number Diff line change 11import { types as t , flow , getEnv } from 'mobx-state-tree'
2- import bookApi from './api'
2+ import bookApi from './mock-api/ api'
33
44let store = null
55
@@ -49,6 +49,7 @@ export const BookStore = t
4949 }
5050
5151 const loadBooks = flow ( function * loadBooks ( ) {
52+ if ( self . books . length > 0 ) return
5253 try {
5354 const books = yield self . api . fetchBooks ( )
5455 updateBooks ( books )
Original file line number Diff line number Diff line change 11import React , { Component } from 'react'
2- import BookStore from '../../../stores/book'
2+ import { View } from 'react-native'
3+ import { observer } from 'mobx-react'
4+
5+ import BkStore from '../../../stores/book'
36import BookList from './BookList'
7+ import Title from '../../../components/Title'
48
59class BookListView extends Component {
610 async componentWillMount ( ) {
7- this . store = BookStore ( )
11+ this . store = BkStore ( )
812 await this . store . loadBooks ( )
913 }
1014
1115 render ( ) {
12- return < BookList books = { this . store . books } />
16+ const { routeName } = this . props . navigation . state
17+ return (
18+ < View >
19+ < Title text = { `${ routeName } Books` } />
20+ < BookList books = { this . store . sortedBooks } />
21+ </ View >
22+ )
1323 }
1424}
1525
16- export default BookListView
26+ export default observer ( BookListView )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { createBottomTabNavigator } from 'react-navigation'
2+ import { observer } from 'mobx-react'
23
3- import {
4- AllBooksTab ,
5- FictionBooksTab ,
6- NonfictionBooksTab ,
7- } from './components/book-type-tabs'
4+ import BkStore from '../../stores/book'
5+ import BookListView from './components/BookListView'
86
9- export default createBottomTabNavigator ( {
10- 'All Books' : AllBooksTab ,
11- Fiction : FictionBooksTab ,
12- Nonfiction : NonfictionBooksTab ,
13- } )
7+ export default observer (
8+ createBottomTabNavigator (
9+ {
10+ All : BookListView ,
11+ Fiction : BookListView ,
12+ Nonfiction : BookListView ,
13+ } ,
14+ {
15+ navigationOptions : ( { navigation } ) => ( {
16+ tabBarOnPress : ( ) => {
17+ const { routeName } = navigation . state
18+ const store = BkStore ( )
19+ store . setGenre ( routeName )
20+ } ,
21+ } ) ,
22+ }
23+ )
24+ )
You can’t perform that action at this time.
0 commit comments